|
|||||||||
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.tapestry.util.xml.RuleDirectedParser
public class RuleDirectedParser
A simplified version of Digester
.
This version is without as many bells and whistles but has some key features needed when parsing
a document (rather than a configuration file):
Like Digester, there's an object stack and a rule stack. The rules are much simpler (more coding), in that there's a one-to-one relationship between an element and a rule.
Based on SAX2.
Constructor Summary | |
---|---|
RuleDirectedParser()
|
Method Summary | |
---|---|
void |
addRule(String localElementName,
IRule rule)
|
void |
characters(char[] ch,
int start,
int length)
Accumulates the content in a buffer; the concatinated content is provided to the top rule just before any start or end tag. |
protected void |
configureParserFactory(javax.xml.parsers.SAXParserFactory factory)
Configures a SAXParserFactory before
SAXParserFactory.newSAXParser() is invoked. |
protected javax.xml.parsers.SAXParser |
constructParser()
Uses SAXParserFactory to create a instance
of a validation SAX2 parser. |
void |
endElement(String uri,
String localName,
String qName)
Pops the top rule off the stack and invokes IRule.endElement(RuleDirectedParser) . |
void |
error(org.xml.sax.SAXParseException ex)
Throws the exception. |
void |
fatalError(org.xml.sax.SAXParseException ex)
Throws the exception. |
IResourceLocation |
getDocumentLocation()
|
String |
getLocalName()
Returns the localName for the current element. |
ILocation |
getLocation()
Returns an ILocation representing the
current position within the document (depending
on the parser, this may be accurate to
column number level). |
String |
getQName()
Returns the qualified name for the current element. |
String |
getUri()
Returns the URI for the current element. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Ignorable content is ignored. |
Object |
parse(IResourceLocation documentLocation)
|
protected Object |
parse(URL url)
|
Object |
peek()
Returns the top object on the object stack. |
Object |
peek(int depth)
Returns an object within the object stack, at depth. |
protected IRule |
peekRule()
Returns the top rule on the stack. |
Object |
pop()
Removes and returns the top object on the object stack. |
protected IRule |
popRule()
|
void |
push(Object object)
Pushes an object onto the object stack. |
protected void |
pushRule(IRule rule)
Pushes a new rule onto the rule stack. |
void |
registerEntity(String publicId,
String entityPath)
Registers a public id and corresponding input source. |
org.xml.sax.InputSource |
resolveEntity(String publicId,
String systemId)
|
protected IRule |
selectRule(String localName,
org.xml.sax.Attributes attributes)
|
void |
setDocumentLocator(org.xml.sax.Locator locator)
Uses the Locator to track the position
in the document as a ILocation . |
void |
startElement(String uri,
String localName,
String qName,
org.xml.sax.Attributes attributes)
Invokes selectRule(String, Attributes) to choose a new rule,
which is pushed onto the rule stack, then invokes
IRule.startElement(RuleDirectedParser, Attributes) . |
void |
validate(String value,
String pattern,
String errorKey)
Validates that the input value matches against the specified Perl5 pattern. |
void |
warning(org.xml.sax.SAXParseException ex)
Throws the exception. |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
endDocument, endPrefixMapping, notationDecl, processingInstruction, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RuleDirectedParser()
Method Detail |
---|
public Object parse(IResourceLocation documentLocation)
protected Object parse(URL url)
public ILocation getLocation()
ILocation
representing the
current position within the document (depending
on the parser, this may be accurate to
column number level).
public void push(Object object)
public Object peek()
public Object peek(int depth)
public Object pop()
protected void pushRule(IRule rule)
protected IRule peekRule()
protected IRule popRule()
public void addRule(String localElementName, IRule rule)
public void registerEntity(String publicId, String entityPath)
publicId
- the public identifier to be registerred, generally
the publicId of a DTD related to the document being parsedentityPath
- the resource path of the entity, typically a DTD
file. Relative files names are expected to be stored in the same package
as the class file, otherwise a leading slash is an absolute pathname
within the classpath.protected IRule selectRule(String localName, org.xml.sax.Attributes attributes)
public void setDocumentLocator(org.xml.sax.Locator locator)
Locator
to track the position
in the document as a ILocation
. This is invoked
once (before the initial element is parsed) and
the Locator is retained and queried as to
the current file location.
setDocumentLocator
in interface org.xml.sax.ContentHandler
setDocumentLocator
in class org.xml.sax.helpers.DefaultHandler
getLocation()
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void endElement(String uri, String localName, String qName) throws org.xml.sax.SAXException
IRule.endElement(RuleDirectedParser)
.
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
ignorableWhitespace
in interface org.xml.sax.ContentHandler
ignorableWhitespace
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
selectRule(String, Attributes)
to choose a new rule,
which is pushed onto the rule stack, then invokes
IRule.startElement(RuleDirectedParser, Attributes)
.
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
protected javax.xml.parsers.SAXParser constructParser()
SAXParserFactory
to create a instance
of a validation SAX2 parser.
protected void configureParserFactory(javax.xml.parsers.SAXParserFactory factory)
SAXParserFactory
before
SAXParserFactory.newSAXParser()
is invoked.
The default implementation sets validating to true
and namespaceAware to false,
public void error(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
error
in interface org.xml.sax.ErrorHandler
error
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void fatalError(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
fatalError
in interface org.xml.sax.ErrorHandler
fatalError
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void warning(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
warning
in interface org.xml.sax.ErrorHandler
warning
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public org.xml.sax.InputSource resolveEntity(String publicId, String systemId) throws org.xml.sax.SAXException
resolveEntity
in interface org.xml.sax.EntityResolver
resolveEntity
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void validate(String value, String pattern, String errorKey) throws DocumentParseException
InvalidStringException
is thrown.
DocumentParseException
public IResourceLocation getDocumentLocation()
public String getLocalName()
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public String getQName()
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public String getUri()
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |