public class XMLParser extends org.xml.sax.helpers.DefaultHandler
XMLParser
parses the XML Jelly format.
The SAXParser and XMLReader portions of this code come from Digester.
Modifier and Type | Field and Description |
---|---|
protected ClassLoader |
classLoader
The class loader to use for instantiating application objects.
|
protected ErrorHandler |
errorHandler
The application-supplied error handler that is notified when parsing
warnings, errors, or fatal errors occur.
|
protected static SAXParserFactory |
factory
The SAXParserFactory that is created the first time we need it.
|
protected Locator |
locator
The Locator associated with our parser.
|
protected Map |
namespaces
Registered namespaces we are currently processing.
|
protected SAXParser |
parser
The SAXParser we will use to parse the input stream.
|
protected XMLReader |
reader
The XMLReader used to parse digester rules.
|
protected boolean |
useContextClassLoader
Do we want to use the Context ClassLoader when loading classes
for instantiating new objects? Default is
false . |
protected boolean |
validating
Do we want to use a validating parser?
|
Constructor and Description |
---|
XMLParser()
Construct a new XMLParser with default properties.
|
XMLParser(SAXParser parser)
Construct a new XMLParser, allowing a SAXParser to be passed in.
|
XMLParser(XMLReader reader)
Construct a new XMLParser, allowing an XMLReader to be passed in.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addExpressionScript(ScriptBlock script,
Expression expression)
Adds the given Expression object to the current Script.
|
protected void |
addTextScript(String text,
boolean start)
Adds the text to the current script block parsing any embedded
expressions into ExpressionScript objects.
|
void |
characters(char[] buffer,
int start,
int length)
Process notification of character data received from the body of
an XML element.
|
protected void |
configure()
This method is called only once before parsing occurs
which allows tag libraries to be registered and so forth
|
protected void |
configureStaticTagAttributes(TagScript script,
Attributes list) |
protected void |
configureTagScript(TagScript aTagScript)
Configure a newly created TagScript instance before any Expressions are created
|
protected Expression |
createConstantExpression(String tagName,
String attributeName,
String attributeValue) |
protected Expression |
createEscapingExpression(Expression expression) |
protected ExpressionFactory |
createExpressionFactory() |
protected SAXException |
createSAXException(Exception e)
Create a SAX exception which also understands about the location in
the digester file where the exception occurs
|
protected SAXException |
createSAXException(String message)
Create a SAX exception which also understands about the location in
the digester file where the exception occurs
|
protected SAXException |
createSAXException(String message,
Exception e)
Create a SAX exception which also understands about the location in
the file where the exception occurs
|
protected TagScript |
createStaticTag(String namespaceURI,
String localName,
String qName,
Attributes list)
Factory method to create a static Tag that represents some static content.
|
protected TagScript |
createTag(String namespaceURI,
String localName,
Attributes list)
Factory method to create new Tag script for the given namespaceURI and name or
return null if this is not a custom Tag.
|
void |
endDocument()
Process notification of the end of the document being reached.
|
void |
endElement(String namespaceURI,
String localName,
String qName)
Process notification of the end of an XML element being reached.
|
void |
endPrefixMapping(String prefix)
Process notification that a namespace prefix is going out of scope.
|
void |
error(SAXParseException exception)
Forward notification of a parsing error to the application supplied
error handler, if any, otherwise throw a SAXException with the error.
|
void |
fatalError(SAXParseException exception)
Forward notification of a fatal parsing error to the application
supplied error handler, if any, otherwise throw a SAXException with the error.
|
String |
findNamespaceURI(String prefix)
Return the currently mapped namespace URI for the specified prefix,
if any; otherwise return
null . |
ClassLoader |
getClassLoader()
Return the class loader to be used for instantiating application objects
when required.
|
JellyContext |
getContext() |
protected String |
getCurrentURI() |
ErrorHandler |
getErrorHandler()
Return the error handler for this XMLParser.
|
ExpressionFactory |
getExpressionFactory() |
protected Properties |
getJellyProperties()
A helper method which loads the static Jelly properties once on startup
|
org.apache.commons.logging.Log |
getLogger()
Return the current Logger associated with this instance of the XMLParser
|
SAXParser |
getParser()
Return the SAXParser we will use to parse the input stream.
|
XMLReader |
getReader()
Deprecated.
Use getXMLReader() instead, which can throw a
SAXException if the reader cannot be instantiated
|
ScriptBlock |
getScript()
Returns the script that has just been created if this class is used
as a SAX ContentHandler and passed into some XML processor or parser.
|
boolean |
getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.
|
boolean |
getValidating()
Return the validating parser flag.
|
XMLReader |
getXMLReader()
Return the XMLReader to be used for parsing the input document.
|
void |
ignorableWhitespace(char[] buffer,
int start,
int len)
Process notification of ignorable whitespace received from the body of
an XML element.
|
boolean |
isEscapeByDefault() |
void |
notationDecl(String name,
String publicId,
String systemId)
Receive notification of a notation declaration event.
|
Script |
parse(File file)
Parse the content of the specified file using this XMLParser.
|
Script |
parse(InputSource input)
Parse the content of the specified input source using this XMLParser.
|
Script |
parse(InputStream input)
Parse the content of the specified input stream using this XMLParser.
|
Script |
parse(Reader reader)
Parse the content of the specified reader using this XMLParser.
|
Script |
parse(String uri)
Parse the content of the specified URI using this XMLParser.
|
Script |
parse(URL url)
Parse the content of the specified file using this XMLParser.
|
void |
processingInstruction(String target,
String data)
Process notification of a processing instruction that was encountered.
|
void |
setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects
when required.
|
void |
setContext(JellyContext context) |
void |
setDefaultNamespaceURI(String namespace)
Set the jelly namespace to use for unprefixed elements.
|
void |
setDocumentLocator(Locator locator)
Set the document locator associated with our parser.
|
void |
setErrorHandler(ErrorHandler errorHandler)
Set the error handler for this XMLParser.
|
void |
setEscapeByDefault(boolean escapeByDefault) |
void |
setExpressionFactory(ExpressionFactory expressionFactory)
Sets the expression factory used to evaluate tag attributes
|
void |
setLogger(org.apache.commons.logging.Log log)
Set the current logger for this XMLParser.
|
void |
setUseContextClassLoader(boolean use)
Determine whether to use the Context ClassLoader (the one found by
calling
Thread.currentThread().getContextClassLoader() )
to resolve/load classes. |
void |
setValidating(boolean validating)
Set the validating parser flag.
|
void |
skippedEntity(String name)
Process notification of a skipped entity.
|
void |
startDocument()
Process notification of the beginning of the document being reached.
|
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes list)
Process notification of the start of an XML element being reached.
|
void |
startPrefixMapping(String prefix,
String namespaceURI)
Process notification that a namespace prefix is coming in to scope.
|
void |
unparsedEntityDecl(String name,
String publicId,
String systemId,
String notation)
Receive notification of an unparsed entity declaration event.
|
void |
warning(SAXParseException exception)
Forward notification of a parse warning to the application supplied
error handler (if any).
|
error, fatalError, resolveEntity, warning
protected ClassLoader classLoader
useContextClassLoader
variable.protected boolean useContextClassLoader
false
.protected ErrorHandler errorHandler
protected static SAXParserFactory factory
protected SAXParser parser
protected XMLReader reader
protected Locator locator
protected Map namespaces
protected boolean validating
public XMLParser()
public XMLParser(SAXParser parser)
public XMLParser(XMLReader reader)
public void setEscapeByDefault(boolean escapeByDefault)
public boolean isEscapeByDefault()
public Script parse(File file) throws IOException, SAXException
file
- File containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Script parse(URL url) throws IOException, SAXException
url
- URL containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Script parse(InputSource input) throws IOException, SAXException
input
- Input source containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Script parse(InputStream input) throws IOException, SAXException
input
- Input stream containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Script parse(Reader reader) throws IOException, SAXException
reader
- Reader containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic Script parse(String uri) throws IOException, SAXException
uri
- URI containing the XML data to be parsedIOException
- if an input/output error occursSAXException
- if a parsing exception occurspublic String findNamespaceURI(String prefix)
null
. These mappings come and
go dynamically as the document is parsed.prefix
- Prefix to look uppublic JellyContext getContext()
public void setContext(JellyContext context)
public void setDefaultNamespaceURI(String namespace)
namespace
- jelly namespace to use (e.g. 'jelly:core')public ClassLoader getClassLoader()
setClassLoader()
, if anyuseContextClassLoader
property is set to truepublic void setClassLoader(ClassLoader classLoader)
classLoader
- The new class loader to use, or null
to revert to the standard rulespublic boolean getUseContextClassLoader()
public void setUseContextClassLoader(boolean use)
Thread.currentThread().getContextClassLoader()
)
to resolve/load classes. If not
using Context ClassLoader, then the class-loading defaults to
using the calling-class' ClassLoader.use
- determines whether to use JellyContext ClassLoader.public ErrorHandler getErrorHandler()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- The new error handlerpublic org.apache.commons.logging.Log getLogger()
public void setLogger(org.apache.commons.logging.Log log)
public ExpressionFactory getExpressionFactory()
public void setExpressionFactory(ExpressionFactory expressionFactory)
public SAXParser getParser()
null
.public XMLReader getReader()
public XMLReader getXMLReader() throws SAXException
SAXException
- if no XMLReader can be instantiatedpublic boolean getValidating()
public void setValidating(boolean validating)
parse()
is called the first time.validating
- The new validating parser flag.public ScriptBlock getScript()
public void startDocument() throws SAXException
startDocument
in interface ContentHandler
startDocument
in class org.xml.sax.helpers.DefaultHandler
SAXException
- if a parsing error is to be reportedpublic void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class org.xml.sax.helpers.DefaultHandler
SAXException
- if a parsing error is to be reportedpublic void startElement(String namespaceURI, String localName, String qName, Attributes list) throws SAXException
startElement
in interface ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace processing is not
being performed.localName
- The local name (without prefix), or the empty
string if Namespace processing is not being performed.qName
- The qualified name (with prefix), or the empty
string if qualified names are not available.\list
- The attributes attached to the element. If there are
no attributes, it shall be an empty Attributes object.SAXException
- if a parsing error is to be reportedpublic void characters(char[] buffer, int start, int length) throws SAXException
characters
in interface ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlength
- Number of characters from the bufferSAXException
- if a parsing error is to be reportedpublic void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement
in interface ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
namespaceURI
- The Namespace URI, or the empty string if the
element has no Namespace URI or if Namespace processing is not
being performed.localName
- The local name (without prefix), or the empty
string if Namespace processing is not being performed.qName
- The qualified XML 1.0 name (with prefix), or the
empty string if qualified names are not available.SAXException
- if a parsing error is to be reportedpublic void startPrefixMapping(String prefix, String namespaceURI) throws SAXException
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class org.xml.sax.helpers.DefaultHandler
prefix
- Prefix that is being declarednamespaceURI
- Corresponding namespace URI being mapped toSAXException
- if a parsing error is to be reportedpublic void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class org.xml.sax.helpers.DefaultHandler
prefix
- Prefix that is going out of scopeSAXException
- if a parsing error is to be reportedpublic void ignorableWhitespace(char[] buffer, int start, int len) throws SAXException
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class org.xml.sax.helpers.DefaultHandler
buffer
- The characters from the XML documentstart
- Starting offset into the bufferlen
- Number of characters from the bufferSAXException
- if a parsing error is to be reportedpublic void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
processingInstruction
in class org.xml.sax.helpers.DefaultHandler
target
- The processing instruction targetdata
- The processing instruction data (if any)SAXException
- if a parsing error is to be reportedpublic void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class org.xml.sax.helpers.DefaultHandler
locator
- The new locatorpublic void skippedEntity(String name) throws SAXException
skippedEntity
in interface ContentHandler
skippedEntity
in class org.xml.sax.helpers.DefaultHandler
name
- Name of the skipped entitySAXException
- if a parsing error is to be reportedpublic void notationDecl(String name, String publicId, String systemId)
notationDecl
in interface DTDHandler
notationDecl
in class org.xml.sax.helpers.DefaultHandler
name
- The notation namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)public void unparsedEntityDecl(String name, String publicId, String systemId, String notation)
unparsedEntityDecl
in interface DTDHandler
unparsedEntityDecl
in class org.xml.sax.helpers.DefaultHandler
name
- The unparsed entity namepublicId
- The public identifier (if any)systemId
- The system identifier (if any)notation
- The name of the associated notationpublic void error(SAXParseException exception) throws SAXException
exception
- The error informationSAXException
- if a parsing exception occurspublic void fatalError(SAXParseException exception) throws SAXException
exception
- The fatal error informationSAXException
- if a parsing exception occurspublic void warning(SAXParseException exception) throws SAXException
exception
- The warning informationSAXException
- if a parsing exception occursprotected void configure()
protected Properties getJellyProperties()
protected TagScript createTag(String namespaceURI, String localName, Attributes list) throws SAXException
SAXException
protected TagScript createStaticTag(String namespaceURI, String localName, String qName, Attributes list) throws SAXException
Note that to if you use jelly:define taglib, these tags might turn out to be non-static during the runtime.
SAXException
protected void configureStaticTagAttributes(TagScript script, Attributes list) throws JellyException
JellyException
protected void configureTagScript(TagScript aTagScript)
aTagScript
- protected void addTextScript(String text, boolean start) throws JellyException
start
- If the text precedes a start element. Otherwise the text precedes an end element.JellyException
protected void addExpressionScript(ScriptBlock script, Expression expression)
protected Expression createEscapingExpression(Expression expression)
protected Expression createConstantExpression(String tagName, String attributeName, String attributeValue)
protected ExpressionFactory createExpressionFactory()
protected String getCurrentURI()
protected SAXException createSAXException(String message, Exception e)
protected SAXException createSAXException(Exception e)
protected SAXException createSAXException(String message)
Copyright © 2014 Apache Software Foundation. All rights reserved.