|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler net.sf.fikin.xml.sax.SAXSerializer net.sf.fikin.xml.TemplateEngine
public class TemplateEngine
Simple template engine.
It can read input XML document and for each tag from predefined namespace
it can execute a method of a POJO lookup object.
public class MyPOJO {
public String empty() { return ""; }
public String m1() { return "Hello world!"; }
public String m2() { return "Simple TE"; }
}
...
Input XML file:
<te:empty xmlns:te="http://sf.net/fikin-ant-tasks/xml/sax-template-engine">
This is "<te:m1/>" example, generated by <te:m2/> <today/>
</te:empty>
...
TemplateEngine te = new TemplateEngine();
te.transform( input, new MyPOJO(), outputStream );
...
TODO:
Field Summary | |
---|---|
static java.lang.String |
NAMESPACE
tags namespace of this template engine |
Fields inherited from class net.sf.fikin.xml.sax.SAXSerializer |
---|
doIndent, elementDepth, inCDATA, indent, isCanonical, isPreviousStartElement, isXML11, locator, namespaces, output |
Constructor Summary | |
---|---|
TemplateEngine()
instantiate new template engine with default xml reader |
|
TemplateEngine(org.xml.sax.XMLReader reader)
instantiate new template engine with given xml reader |
Method Summary | |
---|---|
protected java.lang.Object[] |
convertAtttibutes(java.lang.reflect.Method method,
org.xml.sax.Attributes attributes)
convert xml sax Attributes into an array of values sorts them first in alphabetical order |
java.lang.String |
empty()
lookup built-in method |
void |
endDocument()
flush the output writer and reset internal state |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
print clising tag is this is not a tag from NAMESPACE namespace |
java.lang.String |
forAll(java.util.Iterator iterator)
|
java.lang.Object |
getLookupObject()
get lookup object |
java.util.Hashtable |
getMethods()
get indexed methods of the lookup object |
org.xml.sax.XMLReader |
getReader()
get xml reader object |
protected void |
indexMethods(java.lang.Object lookupObject)
index lookup object's methods which the negine can work with public not void |
protected java.lang.String |
invokeMethod(java.lang.String methodName,
org.xml.sax.Attributes attributes)
invoke given method and using given sax-tag attributes as parameters |
static org.xml.sax.InputSource |
newInputSource(java.io.File in)
instaitate new input source |
static org.xml.sax.InputSource |
newInputSource(java.io.InputStream in)
instaitate new input source |
static org.xml.sax.InputSource |
newInputSource(java.io.Reader in)
instaitate new input source |
static org.xml.sax.InputSource |
newInputSource(java.lang.String file,
java.lang.Class callingCls)
instantiate new input source |
static org.xml.sax.InputSource |
newInputSource(java.lang.String fqnFile,
java.lang.ClassLoader cl)
instantiate new input source |
static org.xml.sax.InputSource |
newInputSource(java.lang.String file,
java.lang.Package pkg)
instantiate new input source |
static org.xml.sax.InputSource |
newInputSource(java.net.URL in)
instaitate new input source |
static org.xml.sax.InputSource |
newInputSourceFromCode(java.lang.String code)
instaitate new input source |
static org.xml.sax.InputSource |
newInputSourceFromFile(java.lang.String file)
instaitate new input source |
static org.xml.sax.InputSource |
newInputSourceFromSystemId(java.lang.String systemId)
instaitate new input source |
static java.io.CharArrayWriter |
newOutput()
instantiate new char array writer |
static java.io.BufferedWriter |
newOutput(java.io.File out)
instantiate new file writer |
static java.io.CharArrayWriter |
newOutput(int initialSize)
instantiate new char array writer |
static java.io.BufferedWriter |
newOutputFromFile(java.lang.String file)
instantiate new file writer |
static org.xml.sax.XMLReader |
newXMLReader()
instantiate new defualt xml reader |
static org.xml.sax.XMLReader |
newXMLReader(java.lang.String readerClassName)
instantiate new xml reader with given class name |
protected void |
reset()
reset internal state after transformation |
protected void |
setLookupObject(java.lang.Object lookupObject)
build methods index of the lookup object |
protected void |
setXMLReader(org.xml.sax.XMLReader r)
initialize xml reader with this object receiving the parsing notifications |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attributes)
process tag if this is a tag from NAMESPACE namespace it executes the
corrsponding to the tag name lookupObject method and prints
out the method invocation result.
is this is any other tag it copes it as occured in the input
stream |
void |
transform(org.xml.sax.InputSource input)
same as transform(InputSource, Object, BufferedWriter) but
using this as lookup object and a dummy output stream |
void |
transform(org.xml.sax.InputSource input,
java.io.BufferedWriter output)
same as transform(InputSource, Object, BufferedWriter) but
using this as lookup object |
void |
transform(org.xml.sax.InputSource input,
java.lang.Object lookupObject)
same as transform(InputSource, Object, BufferedWriter) but
using a dummy output stream |
void |
transform(org.xml.sax.InputSource input,
java.lang.Object lookupObject,
java.io.BufferedWriter output)
process input document and for each tag in NAMESPACE namespace
perform method invocation of the corresponding to the tag's name method
of lookupObject and print the result. |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
endPrefixMapping, notationDecl, resolveEntity, skippedEntity, unparsedEntityDecl |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.xml.sax.EntityResolver |
---|
resolveEntity |
Methods inherited from interface org.xml.sax.ContentHandler |
---|
endPrefixMapping, skippedEntity |
Methods inherited from interface org.xml.sax.DTDHandler |
---|
notationDecl, unparsedEntityDecl |
Field Detail |
---|
public static final java.lang.String NAMESPACE
Constructor Detail |
---|
public TemplateEngine() throws org.xml.sax.SAXException
org.xml.sax.SAXException
public TemplateEngine(org.xml.sax.XMLReader reader) throws org.xml.sax.SAXException
reader
-
org.xml.sax.SAXException
Method Detail |
---|
protected void setXMLReader(org.xml.sax.XMLReader r)
public org.xml.sax.XMLReader getReader()
public java.util.Hashtable getMethods()
protected void setLookupObject(java.lang.Object lookupObject)
lookupObject
-
java.lang.VerifyError
- in case there are dublicated method names and
total parameters countspublic java.lang.Object getLookupObject()
public void transform(org.xml.sax.InputSource input, java.lang.Object lookupObject, java.io.BufferedWriter output) throws org.xml.sax.SAXException, java.io.IOException
NAMESPACE
namespace
perform method invocation of the corresponding to the tag's name method
of lookupObject
and print the result.
all other data is coped as it is received via sax events.
input
- is the input xml document to be processedlookupObject
- is plain old java object having public methods and
returning strings or other toString()
capable objects. These
methods will be executed each time a tag with same name is encounted in
the input document.output
- is the output stream
org.xml.sax.SAXException
java.io.IOException
public void transform(org.xml.sax.InputSource input, java.io.BufferedWriter output) throws org.xml.sax.SAXException, java.io.IOException
transform(InputSource, Object, BufferedWriter)
but
using this as lookup object
input
- is the input xml document to be processedoutput
- is the output stream
org.xml.sax.SAXException
java.io.IOException
public void transform(org.xml.sax.InputSource input) throws org.xml.sax.SAXException, java.io.IOException
transform(InputSource, Object, BufferedWriter)
but
using this as lookup object and a dummy output stream
input
- is the input xml document to be processed
org.xml.sax.SAXException
java.io.IOException
public void transform(org.xml.sax.InputSource input, java.lang.Object lookupObject) throws org.xml.sax.SAXException, java.io.IOException
transform(InputSource, Object, BufferedWriter)
but
using a dummy output stream
input
- is the input xml document to be processed
org.xml.sax.SAXException
java.io.IOException
protected void indexMethods(java.lang.Object lookupObject)
lookupObject
-
java.lang.VerifyError
- in case there are methods with equal names and
total number of argumentsprotected java.lang.String invokeMethod(java.lang.String methodName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
methodName
- attributes
-
org.xml.sax.SAXException
protected java.lang.Object[] convertAtttibutes(java.lang.reflect.Method method, org.xml.sax.Attributes attributes)
method
- attributes
-
protected void reset()
public java.lang.String empty()
public java.lang.String forAll(java.util.Iterator iterator)
public static org.xml.sax.XMLReader newXMLReader() throws org.xml.sax.SAXException
org.xml.sax.SAXException
public static org.xml.sax.XMLReader newXMLReader(java.lang.String readerClassName) throws org.xml.sax.SAXException
readerClassName
- if fqn of the class
org.xml.sax.SAXException
public static org.xml.sax.InputSource newInputSource(java.io.InputStream in)
in
- is the input stream
public static org.xml.sax.InputSource newInputSource(java.io.Reader in)
in
- is the input reader
public static org.xml.sax.InputSource newInputSourceFromSystemId(java.lang.String systemId)
systemId
-
public static org.xml.sax.InputSource newInputSource(java.io.File in) throws java.io.FileNotFoundException
in
- is the file to be used as input
java.io.FileNotFoundException
public static org.xml.sax.InputSource newInputSourceFromFile(java.lang.String file) throws java.io.FileNotFoundException
file
- name to be used as input
java.io.FileNotFoundException
public static org.xml.sax.InputSource newInputSource(java.net.URL in) throws java.io.IOException
in
- is the url which stream is to be used
java.io.IOException
public static org.xml.sax.InputSource newInputSource(java.lang.String fqnFile, java.lang.ClassLoader cl)
fqnFile
- is the fully qualified name of the classloader resource
which input stream is to be used as inputcl
- is classloader to be used to resolve the resource. if null
it will use Thread context classloader.
public static org.xml.sax.InputSource newInputSource(java.lang.String file, java.lang.Package pkg)
file
- is file name (local) of the classloader reasource, which
input stream is to be used as input sourcepkg
- is the java package where this resource is located
public static org.xml.sax.InputSource newInputSource(java.lang.String file, java.lang.Class callingCls)
file
- is file name (local) of the classloader reasource, which
input stream is to be used as input sourcecallingCls
- is the java class under which package this resource is located
public static org.xml.sax.InputSource newInputSourceFromCode(java.lang.String code)
code
- is the actual input code
public static java.io.CharArrayWriter newOutput()
public static java.io.CharArrayWriter newOutput(int initialSize)
initialSize
- with initial capacity
public static java.io.BufferedWriter newOutput(java.io.File out) throws java.io.IOException
out
- is the output file to be used
java.io.IOException
public static java.io.BufferedWriter newOutputFromFile(java.lang.String file) throws java.io.IOException
file
- is the output file name to be used
java.io.IOException
public void endDocument() throws org.xml.sax.SAXException
endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class SAXSerializer
org.xml.sax.SAXException
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
NAMESPACE
namespace it executes the
corrsponding to the tag name lookupObject
method and prints
out the method invocation result.
startElement
in interface org.xml.sax.ContentHandler
startElement
in class SAXSerializer
org.xml.sax.SAXException
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
NAMESPACE
namespace
endElement
in interface org.xml.sax.ContentHandler
endElement
in class SAXSerializer
org.xml.sax.SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |