|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.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 | |
|---|---|
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 Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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 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. |
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). |
| 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 |
|---|
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
| Constructor Detail |
|---|
public XMLParser()
public XMLParser(SAXParser parser)
public XMLParser(XMLReader reader)
| Method Detail |
|---|
public void setEscapeByDefault(boolean escapeByDefault)
public Script parse(File file)
throws IOException,
SAXException
file - File containing the XML data to be parsed
IOException - if an input/output error occurs
SAXException - if a parsing exception occurs
public Script parse(URL url)
throws IOException,
SAXException
url - URL containing the XML data to be parsed
IOException - if an input/output error occurs
SAXException - if a parsing exception occurs
public Script parse(InputSource input)
throws IOException,
SAXException
input - Input source containing the XML data to be parsed
IOException - if an input/output error occurs
SAXException - if a parsing exception occurs
public Script parse(InputStream input)
throws IOException,
SAXException
input - Input stream containing the XML data to be parsed
IOException - if an input/output error occurs
SAXException - if a parsing exception occurs
public Script parse(Reader reader)
throws IOException,
SAXException
reader - Reader containing the XML data to be parsed
IOException - if an input/output error occurs
SAXException - if a parsing exception occurs
public Script parse(String uri)
throws IOException,
SAXException
uri - URI containing the XML data to be parsed
IOException - if an input/output error occurs
SAXException - 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 true
public 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 ContentHandlerstartDocument in class org.xml.sax.helpers.DefaultHandlerSAXException - if a parsing error is to be reported
public void endDocument()
throws SAXException
endDocument in interface ContentHandlerendDocument in class org.xml.sax.helpers.DefaultHandlerSAXException - if a parsing error is to be reported
public void startElement(String namespaceURI,
String localName,
String qName,
Attributes list)
throws SAXException
startElement in interface ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlernamespaceURI - 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 reported
public void characters(char[] buffer,
int start,
int length)
throws SAXException
characters in interface ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerbuffer - The characters from the XML documentstart - Starting offset into the bufferlength - Number of characters from the buffer
SAXException - if a parsing error is to be reported
public void endElement(String namespaceURI,
String localName,
String qName)
throws SAXException
endElement in interface ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlernamespaceURI - 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 reported
public void startPrefixMapping(String prefix,
String namespaceURI)
throws SAXException
startPrefixMapping in interface ContentHandlerstartPrefixMapping in class org.xml.sax.helpers.DefaultHandlerprefix - Prefix that is being declarednamespaceURI - Corresponding namespace URI being mapped to
SAXException - if a parsing error is to be reported
public void endPrefixMapping(String prefix)
throws SAXException
endPrefixMapping in interface ContentHandlerendPrefixMapping in class org.xml.sax.helpers.DefaultHandlerprefix - Prefix that is going out of scope
SAXException - if a parsing error is to be reported
public void ignorableWhitespace(char[] buffer,
int start,
int len)
throws SAXException
ignorableWhitespace in interface ContentHandlerignorableWhitespace in class org.xml.sax.helpers.DefaultHandlerbuffer - The characters from the XML documentstart - Starting offset into the bufferlen - Number of characters from the buffer
SAXException - if a parsing error is to be reported
public void processingInstruction(String target,
String data)
throws SAXException
processingInstruction in interface ContentHandlerprocessingInstruction in class org.xml.sax.helpers.DefaultHandlertarget - 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 ContentHandlersetDocumentLocator in class org.xml.sax.helpers.DefaultHandlerlocator - The new locator
public void skippedEntity(String name)
throws SAXException
skippedEntity in interface ContentHandlerskippedEntity in class org.xml.sax.helpers.DefaultHandlername - Name of the skipped entity
SAXException - if a parsing error is to be reported
public void notationDecl(String name,
String publicId,
String systemId)
notationDecl in interface DTDHandlernotationDecl in class org.xml.sax.helpers.DefaultHandlername - 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 DTDHandlerunparsedEntityDecl in class org.xml.sax.helpers.DefaultHandlername - The unparsed entity namepublicId - The public identifier (if any)systemId - The system identifier (if any)notation - The name of the associated notation
public void error(SAXParseException exception)
throws SAXException
error in interface ErrorHandlererror in class org.xml.sax.helpers.DefaultHandlerexception - The error information
SAXException - if a parsing exception occurs
public void fatalError(SAXParseException exception)
throws SAXException
fatalError in interface ErrorHandlerfatalError in class org.xml.sax.helpers.DefaultHandlerexception - The fatal error information
SAXException - if a parsing exception occurs
public void warning(SAXParseException exception)
throws SAXException
warning in interface ErrorHandlerwarning in class org.xml.sax.helpers.DefaultHandlerexception - The warning information
SAXException - 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
JellyExceptionprotected 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 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)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||