Developing
XML-enabled application requires XML transformation with some degree. The
simplest translating happens while an Entity is resolved during the
parsing of the XML document, in which the Entity is replaced by a string as
defined early in the document. However, most application requires more
transformation functionalities than Entity resolving alone.
Leaflet is a macro language translator, which is designed to help developer with XML transformation. It provides a simple and intuitive, yet powerful, way to do transformation.
Leaflet has two [mode]. In the first [mode], a transformation rule, called Shells and XML data are defined in the same document. The transformation will start in the Main Shell and result will be generated according all of the Shells and the XML data.
In the batch [mode], Shells are defined in advance and a translator with the Shells is created. The same set of Shells will be reused, instead of loading from disk and parsing every time. Result will be generated differently according to the XML data feed in. It works especially efficient in environment like Java Servlet. User data, likes cookies in user’s browser, user profile that is stored in the server and transaction result from database can be feed into the translator as XML Data. The resulting page will be generated differently to the transaction result and user’s preferences.
Also, with Slot and Selector, Shell architecture provides abstraction of to the rules. It functionalities are not available in any other XML solution in the market.
Beside abstraction, Leaflet also provides a rich set of functionalities, yet as intuitive, for Data extracting, Output encoding and Pattern matching (reg exp).
Despite Leaflet is rich in functionalities, its footprint is extremely small. The uncompressed jar file of the fully functional Leaflet is less than 100kB (the typical size of a jpeg photo you can find in the web). And, functions can be easily added to it extremely extensible architecture.
1/ Getting Started
Introduction
An Introductory
Example
Example List of
this book
Understands Leaflet
Architecture
Understanding Tree
structure
Passing Tree around
Understand
DataSource
Defining a Shell
Translator and
batch mode
2/ Using Leaflet
Marco
definition/abstraction
Shell/Slot/Choice/Pipe
DataSource
BasicDataSource
FileDataSource
TempFileDataSource
(create a temp file on behalf of servlet)
XMLFileDataSource
JDBCDataSource
Data selection
Identifing a branch
or a set of branch -- XdataPath
ForEach/Exist/Switch
Eval
Output encoding
HttpString
Replace Character
Pattern
matching/reg expression
Match/Split
Output Method
State (returned by
translate)
ResultHandler
(SAX-like interface)
TreeBuilder
3/ Advanced
features
Defining your own
predcate
adding new
predecate into translator
Dynamic Data source
creating custom
data source
CoureInfo example
Working with
Servlet thin layer
need JavaScript
which sent in XML data, instead of just key and
Forward
compatibility
Define alternative
for older translator
1/ Getting Started
Introduction
An Introductory
Example
Example List of
this book
Understands Leaflet
Architecture
Understanding Tree
structure
Passing Tree around
Defining a Shell
Translator and
batch mode
2/ Using Leaflet
Marco
definition/abstraction
Shell/Slot/Selector
Data extraction
Identifing a branch
or a set of branch -- XdataPath
ForEach/Exist/Switch
Eval
Output encoding
HttpString
Replace Character
Pattern
matching/reg expression
Match/Split
Output Method
State (returned by
translate)
ResultHandler
(SAX-like interface)
TreeBuilder
3/ Advanced
features
Defining your own
predcate
adding new
predecate into translator
Dynamic Data model
creating custom
data model
CoureInfo example
Working with
Servlet thin layer
need JavaScript
which sent in XML data, instead of just key and
Forward
compatibility
Define alternative
for older translator
Using
Leaflet in Multithread environment
4/ Appendixes
FAQ
Ok, transformation of XML, why not
XSLT
Table
of Examples
Introductory
Example
Abstraction
-- Company Title Bar
Abstraction–
Advanced use – Uvic timetable
Swtich
– Name Card vs. Table – that’s why you need switch and need it a lot
Extract
Data -- Display name card
Extract
Data – Advanced use -- CourseInfo Example
Split
and Match – Unix User File, Mulitple IP Address
Output
Encoding – SQL statement
Voting
Searching site – get user’s link information in XML (maybe from java)
Calendar
User
customize portral page
Part 1
Part
1 -- Using Leaflet
-1/ Working with
XML, a link to other tutorial
0/ Introducting
example of how to use
The most common use of Leaflet is use it as preprocessor for HTML.
Class ABC {
public void main(
String[] argv ) {
FileReader f = new FileReader( "example1.xml" );
Tree t =
Tree.createTree( f );
Translator t =
new Translator();
translateToXml(
System.out );
}
}
In
"example1.xml"
something
Output:
something
1/
Understanding and Working with Tree structure
Why
not DOM?
for
cross platform cumbersome to work in java
code
is very ugly
Data/Rule
Identifiy
a branch (support XPath later)
2/
Certaining Shell
Design yoru own tag.
New tag is often some old features plus something new.
More than Text representation
filling
complicated form
Two way to present data on the web.
1/ iterate data
into form
2/ rule for make tag, java object etc.
How this document
organize
Need it?
Leaflet support
the following type of operations
Shell
and slot concept (like parameter)
1/
don't use slot (two way to abstractize)
<html><body>
<CompanyLogo>
<p>News:
Nov 19, 1999 -- Vancouver ....</p>
<body><html>
2/
use slot
<CompanyPage>
<Content>
</Content>
<CompanyPage>
3/
selector, shell, and slot
<CompanyPage>
<Department>
<Hardware/>
</Department>
<Content>
</Content>
</CompanyPage>
3/
Working with data
Branch
and Bough
ForEach
different
style, different color for second line.
set
limit
Exist
Swtich
Swtich – Name Card vs. Table – that’s
why you need switch and need it a lot
<NameCard>
<Name><First>Thomas</First><Middle>Tat-Man</Middle><Last>Yip</Last></Name>
<Email><Primary>tyip@leafosft</Primary></Email>
<Phone>604-436-6185</Phone>
<PerferredContactMethod><Email/></PerferredContactMethod>
</NameCard>
<Record
type=”NameCard”>
<Param
name=”FirstName”>Thomas</Param>
<Param
name=”MiddleName”>Tat-Man</Param>
<Param
name=”LastName”>Yip</Param>
<Param
name=”Phone”>604-436-6185</Param>
<Param
name=”PerferredContactMethod><Email/></PerferredContactMethod>
</Record>
SortList
DelimitorList
Overall
example:
University
schedule
4/
Output predecate
HttpString,
Replace character
5/
External predecate (eval)
6/
Create Transtor
Cerating
translator
adding
shell into translator
Understand
ResultInfo
Note:
Thread safe
Setting
ResultHandler
Start
translating (into ResultHolder)
Result
in Tree structure
7/
option of Handling the result
sax-style
result handler
creating
Java GUI widget
Using
Reflection to create
Displaying
tag to browser
special
handling of <br><hr> etc
8/
Some possible use of Translator
[list
whetever in my idea book]
Part
2 -- Advanced topic
9/
Defining your own predcate
In
javascript
In
Java
adding
new predecate into translator
10/
Dynamic Data model
creating
custom data model
CoureInfo
example
11/
Working with servlet thin layer
need
javascript which sent in xml data, instead of just key and value pair
Index of examples
Create a new tag for the existing
application. For example, add an Tag to Html
Use a tag to represent another tag to
help separation different text logically for example, use Indent to replace
BackQuote
Use a tag to represent multiple tags,
like company
[do reflection]
While XSLT can do [something], it lack of the functionality of [some other things]. And, XSLT's pattern driven design make something impossible/hard to do. for example,
[complicate table].
[do site management]