|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
edu.mit.jverbnet.util.parse.MappedHandler<T>
public class MappedHandler<T>
A handler which processes tags internal to its tagged block by assigning handlers to qNames.
Field Summary | |
---|---|
static java.lang.String |
messageIgnoringElementBlockExternal
|
protected static java.util.regex.Matcher |
messageMatcherIgnoreExternal
|
protected static java.util.regex.Matcher |
messageMatcherIgnoreInternal
|
static java.lang.String |
messageParserNotSet
|
static java.lang.String |
messageUnmappedElementBlockInternal
|
protected java.util.Stack<java.lang.String> |
tagStack
The stack of tags encountered inside the tagged block (including the tagged block tag itself) |
Constructor Summary | |
---|---|
MappedHandler(IHasParserHandler parent,
java.lang.String tag)
Convenience constructor. |
|
MappedHandler(java.lang.String tag)
Creates a new mapped handler which is assigned to the specified tag. |
|
MappedHandler(org.xml.sax.XMLReader parser,
org.xml.sax.ContentHandler parent,
java.lang.String tag)
Full control constructor. |
|
MappedHandler(org.xml.sax.XMLReader parser,
java.lang.String tag)
Creates a new mapped handler which uses the specified parser and is assigned to the specified tag. |
Method Summary | |
---|---|
protected void |
checkParserSet()
Throws an exception if the parser is not set. |
void |
clear()
Clears the state of the handler. |
protected void |
clearLocal()
Subclasses may override this method to add code to be invoked when clear() is called. |
protected T |
doGetElement()
If subclasses intend to use the getElement() method, they should
override this method to provide the code that constructs the object
corresponding to the tagged block. |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Handle an end element. |
void |
endTaggedBlock(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
This method is used to run when exiting a tagged block. |
org.xml.sax.Locator |
getDocumentLocator()
Returns the document locator for this handler; may be null |
T |
getElement()
Returns the object representing the data in the parsed tagged block. |
java.util.Map<java.lang.String,org.xml.sax.ContentHandler> |
getHandlerMappings()
Returns the set of tag to handler mappings for this mapped handler. |
org.xml.sax.ContentHandler |
getParent()
Returns the parent of this child handler. |
org.xml.sax.XMLReader |
getParser()
Returns the parser for this handler. |
java.lang.String |
getTag()
Returns the tag that is handled by this handler. |
java.util.List<ITaggedBlockTaskHandler> |
getTaggedBlockTasks()
Returns the list of task handlers that are run when the tagged block is entered and exited. |
protected void |
handleUnmappedEndElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Subclasses may override this method to handle end tags. |
protected void |
handleUnmappedStartElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
Subclasses may override this method to handle unmapped start tags. |
protected void |
initHandlerMap(java.util.Map<java.lang.String,org.xml.sax.ContentHandler> map)
Adds handlers to the element map. |
boolean |
isInsideTaggedBlock()
Returns true if the handler currently thinks it is inside of
its assigned tagged block. |
protected void |
reportWarning(java.lang.String message)
Reports a warning. |
boolean |
reportWarnings()
Returns true if the handler is currently reporting unmapped
tags to the error handler (or to standard error, if no error handler is
available). |
void |
setDocumentLocator(org.xml.sax.Locator locator)
|
void |
setParent(org.xml.sax.ContentHandler parent)
Sets the parent for this handler. |
void |
setParser(org.xml.sax.XMLReader parser)
Sets the parser for this handler; may be set to null |
void |
setReportWarnings(boolean value)
Sets whether the handler reports unampped tags to the error stream. |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
Handle a start element. |
void |
startTaggedBlock(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes attrs)
This method is used to run code when entering a tagged block. |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
characters, endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.xml.sax.ContentHandler |
---|
characters, endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, skippedEntity, startDocument, startPrefixMapping |
Field Detail |
---|
public static final java.lang.String messageParserNotSet
public static final java.lang.String messageIgnoringElementBlockExternal
public static final java.lang.String messageUnmappedElementBlockInternal
protected static final java.util.regex.Matcher messageMatcherIgnoreExternal
protected static final java.util.regex.Matcher messageMatcherIgnoreInternal
protected java.util.Stack<java.lang.String> tagStack
Constructor Detail |
---|
public MappedHandler(java.lang.String tag)
null
.
tag
- the tag for this handler; may not be null
, empty,
or all whitespace; leading and trailing whitespace will be
trimmed
java.lang.NullPointerException
- if the specified tag is null
java.lang.IllegalArgumentException
- if the tag is empty or all whitespacepublic MappedHandler(org.xml.sax.XMLReader parser, java.lang.String tag)
null
.
parser
- the parser for this handler; may not be null
tag
- the tag for this handler; may not be null
, empty,
or all whitespace; leading and trailing whitespace will be
trimmed
java.lang.NullPointerException
- if the specified parser or tag is null
java.lang.IllegalArgumentException
- if the tag is empty or all whitespacepublic MappedHandler(IHasParserHandler parent, java.lang.String tag)
parent
- the parent of this handler, which has a parsertag
- the xml tag which this handler handles; may not be
null
, empty, or all whitespace
java.lang.NullPointerException
- if either parameter is null
java.lang.IllegalArgumentException
- if the tag is empty or all whitespacepublic MappedHandler(org.xml.sax.XMLReader parser, org.xml.sax.ContentHandler parent, java.lang.String tag)
parser
- the parser for this handlerparent
- the parent of this handler, which has a parsertag
- the xml tag which this handler handles; may not be
null
, empty, or all whitespace; the tag will be
trimmed of extra whitespace.
java.lang.NullPointerException
- if either parameter is null
java.lang.IllegalArgumentException
- if the tag is empty or all whitespaceMethod Detail |
---|
public org.xml.sax.XMLReader getParser()
IHasParserHandler
null
.
getParser
in interface IHasParserHandler
null
parser for this handlerpublic void setParser(org.xml.sax.XMLReader parser)
IHasParserHandler
null
setParser
in interface IHasParserHandler
parser
- the new parser for this handler; may be null
public org.xml.sax.ContentHandler getParent()
getParent
in interface ITaggedHandler<T>
null
parent of this child handlerprotected void checkParserSet()
java.lang.IllegalStateException
- if this method is called and the parser is not setpublic void setParent(org.xml.sax.ContentHandler parent)
ITaggedHandler
null
setParent
in interface ITaggedHandler<T>
parent
- the new parent for the handler; may be null
public java.lang.String getTag()
ITaggedHandler
null
or empty, and will be trimmed of leading and trailing
whitespace.
getTag
in interface ITaggedHandler<T>
null
, non-empty, trimmed tag that is handled
by this handlerpublic boolean reportWarnings()
true
if the handler is currently reporting unmapped
tags to the error handler (or to standard error, if no error handler is
available).
true
if unmapped tags will be reported to the error
stream; false
otherwisepublic void setReportWarnings(boolean value)
value
- true
if the handler should report unmapped tags;
false
otherwisepublic void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in interface org.xml.sax.ContentHandler
setDocumentLocator
in class org.xml.sax.helpers.DefaultHandler
public org.xml.sax.Locator getDocumentLocator()
null
null
document locator for this handlerpublic java.util.List<ITaggedBlockTaskHandler> getTaggedBlockTasks()
ITaggedHandler
getTaggedBlockTasks
in interface ITaggedHandler<T>
public final java.util.Map<java.lang.String,org.xml.sax.ContentHandler> getHandlerMappings()
protected void initHandlerMap(java.util.Map<java.lang.String,org.xml.sax.ContentHandler> map)
map
- the map to which handlers should be addedpublic final void clear()
ITaggedHandler
clear
in interface ITaggedHandler<T>
protected void clearLocal()
clear()
is called.
public boolean isInsideTaggedBlock()
true
if the handler currently thinks it is inside of
its assigned tagged block.
true
if the handler currently thinks it is inside of
its assigned tagged block; false
otherwisepublic final void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
startTaggedBlock(String, String, String, Attributes)
method.
Otherwise, try to find a mapped handler to handle the element.
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
uri
- the Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace processing is not being
performedlocalName
- the local name (without prefix), or the empty string if
Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if
qualified names are not availableattrs
- the attributes attached to the element. If there are no
attributes, it shall be an empty Attributes object. The value
of this object after startElement returns is undefined
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another exception
java.lang.IllegalStateException
- if the parser has not been set when this method is calledpublic void startTaggedBlock(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
ITaggedBlockTaskHandler
startTaggedBlock
in interface ITaggedBlockTaskHandler
uri
- the Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace processing is not being
performedlocalName
- the local name (without prefix), or the empty string if
Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if
qualified names are not availableattrs
- the attributes attached to the element. If there are no
attributes, it shall be an empty Attributes object. The value
of this object after startElement returns is undefined
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another exceptionprotected void handleUnmappedStartElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
uri
- the Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace processing is not being
performedlocalName
- the local name (without prefix), or the empty string if
Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if
qualified names are not availableattrs
- the attributes attached to the element. If there are no
attributes, it shall be an empty Attributes object. The value
of this object after startElement returns is undefined
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another exceptionpublic final void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endTaggedBlock(String, String, String)
method.
Otherwise, try to find a mapped handler to handle the element.
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
uri
- the Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace processing is not being
performedlocalName
- the local name (without prefix), or the empty string if
Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if
qualified names are not available
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another exception
java.lang.IllegalStateException
- if the parser has not been set when this method is calledpublic void endTaggedBlock(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
ITaggedBlockTaskHandler
endTaggedBlock
in interface ITaggedBlockTaskHandler
uri
- the Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace processing is not being
performedlocalName
- the local name (without prefix), or the empty string if
Namespace processing is not being performedqName
- the qualified XML name (with prefix), or the empty string if
qualified names are not available
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another exceptionprotected void handleUnmappedEndElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
uri
- the Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace processing is not being
performedlocalName
- the local name (without prefix), or the empty string if
Namespace processing is not being performedqName
- the qualified name (with prefix), or the empty string if
qualified names are not available
org.xml.sax.SAXException
- any SAX exception, possibly wrapping another exceptionprotected void reportWarning(java.lang.String message)
System.err
.
message
- the message to reportpublic T getElement()
ITaggedHandler
getElement
in interface ITaggedHandler<T>
protected T doGetElement()
getElement()
method, they should
override this method to provide the code that constructs the object
corresponding to the tagged block.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |