|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler org.apache.commons.jelly.parser.XMLParser
public class XMLParser
XMLParser
parses the XML Jelly format.
The SAXParser and XMLReader portions of this code come from Digester.
Field Summary | |
---|---|
private boolean |
allowDtdToCallExternalEntities
Do we allow our doctype definitions to call out to external entities? |
protected java.lang.ClassLoader |
classLoader
The class loader to use for instantiating application objects. |
private boolean |
configured
Flag to indicate if this object has been configured |
private JellyContext |
context
JellyContext which is used to locate tag libraries |
private java.lang.String |
defaultNamespaceURI
when not null, set the default namespace for unprefixed elements via the DefaultNamespaceFilter class |
private java.util.Map |
elementNamespaces
The Map of the namespace prefix -> URIs defined for the current element |
protected org.xml.sax.ErrorHandler |
errorHandler
The application-supplied error handler that is notified when parsing warnings, errors, or fatal errors occur. |
private ExpressionFactory |
expressionFactory
the expression factory used to evaluate tag attributes |
protected static javax.xml.parsers.SAXParserFactory |
factory
The SAXParserFactory that is created the first time we need it. |
private java.lang.String |
fileName
The name of the file being parsed that is passed to the TagScript objects for error reporting |
private static java.util.Properties |
jellyProperties
Share the Jelly properties across parsers |
protected org.xml.sax.Locator |
locator
The Locator associated with our parser. |
private org.apache.commons.logging.Log |
log
The Log to which logging calls will be made. |
protected java.util.Map |
namespaces
Registered namespaces we are currently processing. |
protected javax.xml.parsers.SAXParser |
parser
The SAXParser we will use to parse the input stream. |
protected org.xml.sax.XMLReader |
reader
The XMLReader used to parse digester rules. |
private ScriptBlock |
script
The current script block |
private org.apache.commons.collections.ArrayStack |
scriptStack
The stack of body scripts. |
private TagScript |
tagScript
The current, parent tagScript |
private java.util.ArrayList |
tagScriptStack
The stack of tagScripts - use ArrayList as it allows null. |
private java.lang.StringBuffer |
textBuffer
The current text buffer where non-custom tags get written |
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 Summary | |
---|---|
XMLParser()
Construct a new XMLParser with default properties. |
|
XMLParser(boolean allowDtdToCallExternalEntities)
Construct a new XMLParser, with the boolean allowDtdToCallExternalEntities being passed in. |
|
XMLParser(javax.xml.parsers.SAXParser parser)
Construct a new XMLParser, allowing a SAXParser to be passed in. |
|
XMLParser(org.xml.sax.XMLReader reader)
Construct a new XMLParser, allowing an XMLReader to be passed in. |
Method Summary | |
---|---|
protected void |
addExpressionScript(ScriptBlock script,
Expression expression)
Adds the given Expression object to the current Script. |
protected void |
addTextScript(java.lang.String text)
Adds the text to the current script block parsing any embedded expressions inot 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 |
configureTagScript(TagScript aTagScript)
Configure a newly created TagScript instance before any Expressions are created |
protected Expression |
createConstantExpression(java.lang.String tagName,
java.lang.String attributeName,
java.lang.String attributeValue)
|
protected ExpressionFactory |
createExpressionFactory()
|
protected org.xml.sax.SAXException |
createSAXException(java.lang.Exception e)
Create a SAX exception which also understands about the location in the digester file where the exception occurs |
protected org.xml.sax.SAXException |
createSAXException(java.lang.String message)
Create a SAX exception which also understands about the location in the digester file where the exception occurs |
protected org.xml.sax.SAXException |
createSAXException(java.lang.String message,
java.lang.Exception e)
Create a SAX exception which also understands about the location in the file where the exception occurs |
protected TagScript |
createStaticTag(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes list)
Factory method to create a static Tag that represents some static content. |
protected TagScript |
createTag(java.lang.String namespaceURI,
java.lang.String localName,
org.xml.sax.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(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
Process notification of the end of an XML element being reached. |
void |
endPrefixMapping(java.lang.String prefix)
Process notification that a namespace prefix is going out of scope. |
private void |
ensureConfigured()
If this object has not been configured then register the default namespaces |
void |
error(org.xml.sax.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(org.xml.sax.SAXParseException exception)
Forward notification of a fatal parsing error to the application supplied error handler, if any, otherwise throw a SAXException with the error. |
java.lang.String |
findNamespaceURI(java.lang.String prefix)
Return the currently mapped namespace URI for the specified prefix, if any; otherwise return null . |
java.lang.ClassLoader |
getClassLoader()
Return the class loader to be used for instantiating application objects when required. |
JellyContext |
getContext()
|
protected java.lang.String |
getCurrentURI()
|
org.xml.sax.ErrorHandler |
getErrorHandler()
Return the error handler for this XMLParser. |
ExpressionFactory |
getExpressionFactory()
|
protected java.util.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 |
javax.xml.parsers.SAXParser |
getParser()
Return the SAXParser we will use to parse the input stream. |
org.xml.sax.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. |
org.xml.sax.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. |
void |
notationDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Receive notification of a notation declaration event. |
Script |
parse(java.io.File file)
Parse the content of the specified file using this XMLParser. |
Script |
parse(org.xml.sax.InputSource input)
Parse the content of the specified input source using this XMLParser. |
Script |
parse(java.io.InputStream input)
Parse the content of the specified input stream using this XMLParser. |
Script |
parse(java.io.Reader reader)
Parse the content of the specified reader using this XMLParser. |
Script |
parse(java.lang.String uri)
Parse the content of the specified URI using this XMLParser. |
Script |
parse(java.net.URL url)
Parse the content of the specified file using this XMLParser. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Process notification of a processing instruction that was encountered. |
void |
setClassLoader(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required. |
void |
setContext(JellyContext context)
|
void |
setDefaultNamespaceURI(java.lang.String namespace)
Set the jelly namespace to use for unprefixed elements. |
void |
setDocumentLocator(org.xml.sax.Locator locator)
Set the document locator associated with our parser. |
void |
setErrorHandler(org.xml.sax.ErrorHandler errorHandler)
Set the error handler for this XMLParser. |
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(java.lang.String name)
Process notification of a skipped entity. |
void |
startDocument()
Process notification of the beginning of the document being reached. |
void |
startElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes list)
Process notification of the start of an XML element being reached. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String namespaceURI)
Process notification that a namespace prefix is coming in to scope. |
void |
unparsedEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId,
java.lang.String notation)
Receive notification of an unparsed entity declaration event. |
void |
warning(org.xml.sax.SAXParseException exception)
Forward notification of a parse warning to the application supplied error handler (if any). |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
resolveEntity |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static java.util.Properties jellyProperties
private JellyContext context
private ExpressionFactory expressionFactory
private ScriptBlock script
private TagScript tagScript
private org.apache.commons.collections.ArrayStack scriptStack
private java.util.ArrayList tagScriptStack
private java.lang.StringBuffer textBuffer
private boolean allowDtdToCallExternalEntities
protected java.lang.ClassLoader classLoader
useContextClassLoader
variable.
protected boolean useContextClassLoader
false
.
protected org.xml.sax.ErrorHandler errorHandler
protected static javax.xml.parsers.SAXParserFactory factory
protected javax.xml.parsers.SAXParser parser
protected org.xml.sax.XMLReader reader
protected org.xml.sax.Locator locator
protected java.util.Map namespaces
private java.util.Map elementNamespaces
private java.lang.String fileName
protected boolean validating
private boolean configured
private java.lang.String defaultNamespaceURI
private org.apache.commons.logging.Log log
Constructor Detail |
---|
public XMLParser()
public XMLParser(boolean allowDtdToCallExternalEntities)
public XMLParser(javax.xml.parsers.SAXParser parser)
public XMLParser(org.xml.sax.XMLReader reader)
Method Detail |
---|
public Script parse(java.io.File file) throws java.io.IOException, org.xml.sax.SAXException
file
- File containing the XML data to be parsed
java.io.IOException
- if an input/output error occurs
org.xml.sax.SAXException
- if a parsing exception occurspublic Script parse(java.net.URL url) throws java.io.IOException, org.xml.sax.SAXException
url
- URL containing the XML data to be parsed
java.io.IOException
- if an input/output error occurs
org.xml.sax.SAXException
- if a parsing exception occurspublic Script parse(org.xml.sax.InputSource input) throws java.io.IOException, org.xml.sax.SAXException
input
- Input source containing the XML data to be parsed
java.io.IOException
- if an input/output error occurs
org.xml.sax.SAXException
- if a parsing exception occurspublic Script parse(java.io.InputStream input) throws java.io.IOException, org.xml.sax.SAXException
input
- Input stream containing the XML data to be parsed
java.io.IOException
- if an input/output error occurs
org.xml.sax.SAXException
- if a parsing exception occurspublic Script parse(java.io.Reader reader) throws java.io.IOException, org.xml.sax.SAXException
reader
- Reader containing the XML data to be parsed
java.io.IOException
- if an input/output error occurs
org.xml.sax.SAXException
- if a parsing exception occurspublic Script parse(java.lang.String uri) throws java.io.IOException, org.xml.sax.SAXException
uri
- URI containing the XML data to be parsed
java.io.IOException
- if an input/output error occurs
org.xml.sax.SAXException
- if a parsing exception occurspublic java.lang.String findNamespaceURI(java.lang.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(java.lang.String namespace)
namespace
- jelly namespace to use (e.g. 'jelly:core')public java.lang.ClassLoader getClassLoader()
setClassLoader()
, if anyuseContextClassLoader
property is set to true
public void setClassLoader(java.lang.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 org.xml.sax.ErrorHandler getErrorHandler()
public void setErrorHandler(org.xml.sax.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 javax.xml.parsers.SAXParser getParser()
null
.
public org.xml.sax.XMLReader getReader()
public org.xml.sax.XMLReader getXMLReader() throws org.xml.sax.SAXException
org.xml.sax.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 org.xml.sax.SAXException
startDocument
in interface org.xml.sax.ContentHandler
startDocument
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void endDocument() throws org.xml.sax.SAXException
endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list) throws org.xml.sax.SAXException
startElement
in interface org.xml.sax.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.
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void characters(char[] buffer, int start, int length) throws org.xml.sax.SAXException
characters
in interface org.xml.sax.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 buffer
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement
in interface org.xml.sax.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.
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void startPrefixMapping(java.lang.String prefix, java.lang.String namespaceURI) throws org.xml.sax.SAXException
startPrefixMapping
in interface org.xml.sax.ContentHandler
startPrefixMapping
in class org.xml.sax.helpers.DefaultHandler
prefix
- Prefix that is being declarednamespaceURI
- Corresponding namespace URI being mapped to
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
endPrefixMapping
in interface org.xml.sax.ContentHandler
endPrefixMapping
in class org.xml.sax.helpers.DefaultHandler
prefix
- Prefix that is going out of scope
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void ignorableWhitespace(char[] buffer, int start, int len) throws org.xml.sax.SAXException
ignorableWhitespace
in interface org.xml.sax.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 buffer
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
processingInstruction
in interface org.xml.sax.ContentHandler
processingInstruction
in class org.xml.sax.helpers.DefaultHandler
target
- The processing instruction targetdata
- The processing instruction data (if any)
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in interface org.xml.sax.ContentHandler
setDocumentLocator
in class org.xml.sax.helpers.DefaultHandler
locator
- The new locatorpublic void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
skippedEntity
in interface org.xml.sax.ContentHandler
skippedEntity
in class org.xml.sax.helpers.DefaultHandler
name
- Name of the skipped entity
org.xml.sax.SAXException
- if a parsing error is to be reportedpublic void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
notationDecl
in interface org.xml.sax.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(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notation)
unparsedEntityDecl
in interface org.xml.sax.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(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
error
in interface org.xml.sax.ErrorHandler
error
in class org.xml.sax.helpers.DefaultHandler
exception
- The error information
org.xml.sax.SAXException
- if a parsing exception occurspublic void fatalError(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
fatalError
in interface org.xml.sax.ErrorHandler
fatalError
in class org.xml.sax.helpers.DefaultHandler
exception
- The fatal error information
org.xml.sax.SAXException
- if a parsing exception occurspublic void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXException
warning
in interface org.xml.sax.ErrorHandler
warning
in class org.xml.sax.helpers.DefaultHandler
exception
- The warning information
org.xml.sax.SAXException
- if a parsing exception occursprivate void ensureConfigured()
protected void configure()
protected java.util.Properties getJellyProperties()
protected TagScript createTag(java.lang.String namespaceURI, java.lang.String localName, org.xml.sax.Attributes list) throws org.xml.sax.SAXException
org.xml.sax.SAXException
protected TagScript createStaticTag(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes list) throws org.xml.sax.SAXException
org.xml.sax.SAXException
protected void configureTagScript(TagScript aTagScript)
aTagScript
- protected void addTextScript(java.lang.String text) throws JellyException
JellyException
protected void addExpressionScript(ScriptBlock script, Expression expression)
protected Expression createConstantExpression(java.lang.String tagName, java.lang.String attributeName, java.lang.String attributeValue)
protected ExpressionFactory createExpressionFactory()
protected java.lang.String getCurrentURI()
protected org.xml.sax.SAXException createSAXException(java.lang.String message, java.lang.Exception e)
protected org.xml.sax.SAXException createSAXException(java.lang.Exception e)
protected org.xml.sax.SAXException createSAXException(java.lang.String message)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |