|
|||||||||
| Home >> All >> org >> apache >> tapestry >> util >> [ xml overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.tapestry.util.xml
Class RuleDirectedParser

java.lang.Objectorg.xml.sax.helpers.DefaultHandler
org.apache.tapestry.util.xml.RuleDirectedParser
- All Implemented Interfaces:
- org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
- public class RuleDirectedParser
- extends org.xml.sax.helpers.DefaultHandler
A simplified version of org.apache.commons.digester.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):
- Notifications for each bit of text
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.
- Since:
- 3.0
| Constructor Summary | |
RuleDirectedParser()
|
|
| Method Summary | |
void |
addRule(java.lang.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 javax.xml.parsers.SAXParserFactory before SAXParserFactory.newSAXParser()> SAXParserFactory.newSAXParser() 55 is invoked. |
protected javax.xml.parsers.SAXParser |
constructParser()
Uses javax.xml.parsers.SAXParserFactory to create a instance of a validation SAX2 parser. |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Pops the top rule off the stack and invokes IRule#endElementt(RuleDirectedParser). |
void |
error(org.xml.sax.SAXParseException ex)
Throws the exception. |
private java.lang.String |
extractName(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
|
void |
fatalError(org.xml.sax.SAXParseException ex)
Throws the exception. |
private void |
fireContentRule()
|
org.apache.hivemind.Resource |
getDocumentLocation()
|
java.lang.String |
getLocalName()
Returns the localName for the current element. |
org.apache.hivemind.Location |
getLocation()
Returns an ILocation representing the
current position within the document (depending
on the parser, this may be accurate to
column number level). |
java.lang.String |
getQName()
Returns the qualified name for the current element. |
java.lang.String |
getUri()
Returns the URI for the current element. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Ignorable content is ignored. |
java.lang.Object |
parse(org.apache.hivemind.Resource documentLocation)
|
protected java.lang.Object |
parse(java.net.URL url)
|
java.lang.Object |
peek()
Returns the top object on the object stack. |
java.lang.Object |
peek(int depth)
Returns an object within the object stack, at depth. |
private java.lang.Object |
peek(java.util.List list,
int depth)
|
protected IRule |
peekRule()
Returns the top rule on the stack. |
java.lang.Object |
pop()
Removes and returns the top object on the object stack. |
private java.lang.Object |
pop(java.util.List list,
java.lang.String name)
|
protected IRule |
popRule()
|
private void |
push(java.util.List list,
java.lang.Object object,
java.lang.String name)
|
void |
push(java.lang.Object object)
Pushes an object onto the object stack. |
protected void |
pushRule(IRule rule)
Pushes a new rule onto the rule stack. |
void |
registerEntity(java.lang.String publicId,
java.lang.String entityPath)
Registers a public id and corresponding input source. |
org.xml.sax.InputSource |
resolveEntity(java.lang.String publicId,
java.lang.String systemId)
Resolve an external entity. |
protected IRule |
selectRule(java.lang.String localName,
org.xml.sax.Attributes attributes)
|
void |
setDocumentLocator(org.xml.sax.Locator locator)
Uses the org.xml.sax.Locator to track the position in the document as a ILocation. |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attributes)
Invokes selectRule(String, Attributes) 55 to choose a new rule,
which is pushed onto the rule stack, then invokes
IRule.startElement(RuleDirectedParser, Attributes) 55 . |
void |
validate(java.lang.String value,
java.lang.String pattern,
java.lang.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 |
| Field Detail |
__CLOVER_444_0
public static com.cortexeb.tools.clover.d __CLOVER_444_0
LOG
private static final org.apache.commons.logging.Log LOG
_documentLocation
private org.apache.hivemind.Resource _documentLocation
_ruleStack
private java.util.List _ruleStack
_objectStack
private java.util.List _objectStack
_documentObject
private java.lang.Object _documentObject
_locator
private org.xml.sax.Locator _locator
_line
private int _line
_column
private int _column
_location
private org.apache.hivemind.Location _location
_parserFactory
private static javax.xml.parsers.SAXParserFactory _parserFactory
_parser
private javax.xml.parsers.SAXParser _parser
_matcher
private org.apache.tapestry.util.RegexpMatcher _matcher
_uri
private java.lang.String _uri
_localName
private java.lang.String _localName
_qName
private java.lang.String _qName
_ruleMap
private java.util.Map _ruleMap
- Map of IRule keyed on the local name
of the element.
_contentBuffer
private java.lang.StringBuffer _contentBuffer
- Used to accumlate content provided by
ContentHandler.characters(char[], int, int)>
ContentHandler.characters(char[], int, int)55 .
_entities
private java.util.Map _entities
- Map of paths to external entities (such as the DTD) keyed on public id.
| Constructor Detail |
RuleDirectedParser
public RuleDirectedParser()
| Method Detail |
parse
public java.lang.Object parse(org.apache.hivemind.Resource documentLocation)
parse
protected java.lang.Object parse(java.net.URL url)
getLocation
public org.apache.hivemind.Location getLocation()
- Returns an
ILocationrepresenting the current position within the document (depending on the parser, this may be accurate to column number level).
push
public void push(java.lang.Object object)
- Pushes an object onto the object stack. The first object
pushed is the "document object", the root object returned
by the parse.
peek
public java.lang.Object peek()
- Returns the top object on the object stack.
peek
public java.lang.Object peek(int depth)
- Returns an object within the object stack, at depth.
Depth 0 is the top object, depth 1 is the next-to-top object,
etc.
pop
public java.lang.Object pop()
- Removes and returns the top object on the object stack.
pop
private java.lang.Object pop(java.util.List list, java.lang.String name)
peek
private java.lang.Object peek(java.util.List list, int depth)
push
private void push(java.util.List list, java.lang.Object object, java.lang.String name)
pushRule
protected void pushRule(IRule rule)
- Pushes a new rule onto the rule stack.
peekRule
protected IRule peekRule()
- Returns the top rule on the stack.
popRule
protected IRule popRule()
addRule
public void addRule(java.lang.String localElementName, IRule rule)
registerEntity
public void registerEntity(java.lang.String publicId, java.lang.String entityPath)
- Registers
a public id and corresponding input source. Generally, the source
is a wrapper around an input stream to a package resource.
selectRule
protected IRule selectRule(java.lang.String localName, org.xml.sax.Attributes attributes)
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator locator)
- Uses the org.xml.sax.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.
characters
public void characters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
- Accumulates the content in a buffer; the concatinated content
is provided to the top rule just before any start or end tag.
endElement
public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
- Pops the top rule off the stack and
invokes
IRule#endElementt(RuleDirectedParser).
ignorableWhitespace
public void ignorableWhitespace(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
- Ignorable content is ignored.
startElement
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
- Invokes
selectRule(String, Attributes)55 to choose a new rule, which is pushed onto the rule stack, then invokesIRule.startElement(RuleDirectedParser, Attributes)55 .
extractName
private java.lang.String extractName(java.lang.String uri, java.lang.String localName, java.lang.String qName)
constructParser
protected javax.xml.parsers.SAXParser constructParser()
- Uses javax.xml.parsers.SAXParserFactory to create a instance
of a validation SAX2 parser.
configureParserFactory
protected void configureParserFactory(javax.xml.parsers.SAXParserFactory factory)
- Configures a javax.xml.parsers.SAXParserFactory before
SAXParserFactory.newSAXParser()>
SAXParserFactory.newSAXParser()55 is invoked. The default implementation sets validating to true and namespaceAware to false,
error
public void error(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
- Throws the exception.
fatalError
public void fatalError(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
- Throws the exception.
warning
public void warning(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException
- Throws the exception.
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
- Description copied from class:
org.xml.sax.helpers.DefaultHandler - Resolve an external entity.
Always return null, so that the parser will use the system identifier provided in the XML document. This method implements the SAX default behaviour: application writers can override it in a subclass to do special translations such as catalog lookups or URI redirection.
validate
public void validate(java.lang.String value, java.lang.String pattern, java.lang.String errorKey) throws DocumentParseException
- Validates that the input value matches against the specified
Perl5 pattern. If valid, the method simply returns.
If not a match, then an error message is generated (using the
errorKey and the input value) and a
InvalidStringException is thrown.
getDocumentLocation
public org.apache.hivemind.Resource getDocumentLocation()
getLocalName
public java.lang.String getLocalName()
- Returns the localName for the current element.
getQName
public java.lang.String getQName()
- Returns the qualified name for the current element.
getUri
public java.lang.String getUri()
- Returns the URI for the current element.
fireContentRule
private void fireContentRule()
|
|||||||||
| Home >> All >> org >> apache >> tapestry >> util >> [ xml overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC