Package de.pangaea.metadataportal.utils
Class ExtendedDigester
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.apache.commons.digester.Digester
-
- de.pangaea.metadataportal.utils.ExtendedDigester
-
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
public class ExtendedDigester extends org.apache.commons.digester.Digester
Extension of the Commons Digester Class, that works around some limitations/bugs. It is especially important forSaxRule
, as it supports a stack/list of namespace-prefix assignments, and contains a integrated error handler. It also gives the possibility to not allow invalid element names.- Author:
- Uwe Schindler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ExtendedDigester.DoNothingRule
This rule does nothing.
-
Field Summary
Fields Modifier and Type Field Description protected HashMap<String,LinkedList<String>>
currentNamespaceMap
protected ContentHandler
custContentHandler
-
Fields inherited from class org.apache.commons.digester.Digester
bodyText, bodyTexts, classLoader, configured, entityResolver, entityValidator, errorHandler, factory, inputSources, JAXP_SCHEMA_LANGUAGE, locator, log, match, matches, namespaceAware, namespaces, params, parser, publicId, reader, root, rules, saxLog, schema, schemaLanguage, schemaLocation, stack, substitutor, useContextClassLoader, validating, W3C_XML_SCHEMA, xincludeAware
-
-
Constructor Summary
Constructors Constructor Description ExtendedDigester()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDoNothing(String pattern)
Adds a dummy rule for element paths, that are allowed, but not parsed.void
characters(char[] ch, int start, int length)
void
clear()
void
endElement(String uri, String localName, String qName)
void
endPrefixMapping(String prefix)
void
error(SAXParseException ex)
Just throwsex
.void
fatalError(SAXParseException ex)
Just throwsex
.Set<String>
getCurrentAssignedPrefixes()
Returns all current namespace prefix that are assigned.NamespaceContext
getCurrentNamespaceContext(boolean strict, boolean reDefineDefaultPrefix)
Returns the currentNamespaceContext
for compiling XPath expressions.String
getCurrentNamespaceForPrefix(String prefix)
Returns the current namespace URI for the given prefix.Map<String,String>
getCurrentNamespaceMap()
Returns the current namespace prefix mappings as modifiableMap
containing the prefix and the current namespace assignment (it is just a copy of the internal representation's current mapping).ContentHandler
getCustomContentHandler()
Gets the custom event handler.ErrorHandler
getErrorHandler()
Not supported, always returnsnull
void
ignorableWhitespace(char[] ch, int start, int length)
void
processingInstruction(String target, String data)
void
replayEndPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces)
Replays all current prefix mappings for anotherContentHandler
(end mapping).void
replayStartPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces)
Replays all current prefix mappings for anotherContentHandler
(start mapping).void
setCustomContentHandler(ContentHandler c)
Sets a customContentHandler
, that receives all SAX events until disabled (null
).void
setErrorHandler(ErrorHandler err)
Not suppoted, always throwsIllegalArgumentException
if notnull
.void
setRulesWithInvalidElementCheck(org.apache.commons.digester.Rules rules)
Adds a default Rule for not allowing invalid (not registered) event paths.void
skippedEntity(String name)
void
startDocument()
void
startElement(String uri, String localName, String qName, Attributes atts)
void
startPrefixMapping(String prefix, String uri)
void
warning(SAXParseException ex)
Logs the SAX exception as warning (with location).-
Methods inherited from class org.apache.commons.digester.Digester
addBeanPropertySetter, addBeanPropertySetter, addCallMethod, addCallMethod, addCallMethod, addCallMethod, addCallParam, addCallParam, addCallParam, addCallParam, addCallParamPath, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addFactoryCreate, addObjectCreate, addObjectCreate, addObjectCreate, addObjectCreate, addObjectParam, addRule, addRuleSet, addSetNestedProperties, addSetNestedProperties, addSetNestedProperties, addSetNext, addSetNext, addSetProperties, addSetProperties, addSetProperties, addSetProperty, addSetRoot, addSetRoot, addSetTop, addSetTop, cleanup, configure, createInputSourceFromURL, createInputSourceFromURL, createSAXException, createSAXException, createSAXException, endDocument, findNamespaceURI, getClassLoader, getCount, getCurrentElementName, getCurrentNamespaces, getDebug, getDocumentLocator, getEntityResolver, getFactory, getFeature, getLogger, getMatch, getNamespaceAware, getParser, getProperty, getPublicId, getReader, getRoot, getRuleNamespaceURI, getRules, getSAXLogger, getSchema, getSchemaLanguage, getStackAction, getSubstitutor, getUseContextClassLoader, getValidating, getXIncludeAware, getXMLReader, getXMLSchema, initialize, isEmpty, log, log, notationDecl, parse, parse, parse, parse, parse, parse, peek, peek, peek, peek, peekParams, peekParams, pop, pop, popParams, push, push, pushParams, register, register, resetRoot, resolveEntity, setClassLoader, setDebug, setDocumentLocator, setEntityResolver, setFeature, setLogger, setNamespaceAware, setProperty, setPublicId, setRuleNamespaceURI, setRules, setSAXLogger, setSchema, setSchemaLanguage, setStackAction, setSubstitutor, setUseContextClassLoader, setValidating, setXIncludeAware, setXMLSchema, unparsedEntityDecl
-
-
-
-
Field Detail
-
currentNamespaceMap
protected final HashMap<String,LinkedList<String>> currentNamespaceMap
-
custContentHandler
protected ContentHandler custContentHandler
-
-
Method Detail
-
setCustomContentHandler
public void setCustomContentHandler(ContentHandler c)
Sets a customContentHandler
, that receives all SAX events until disabled (null
).- Overrides:
setCustomContentHandler
in classorg.apache.commons.digester.Digester
-
getCustomContentHandler
public ContentHandler getCustomContentHandler()
Gets the custom event handler.- Overrides:
getCustomContentHandler
in classorg.apache.commons.digester.Digester
-
setErrorHandler
public void setErrorHandler(ErrorHandler err)
Not suppoted, always throwsIllegalArgumentException
if notnull
.- Overrides:
setErrorHandler
in classorg.apache.commons.digester.Digester
-
getErrorHandler
public ErrorHandler getErrorHandler()
Not supported, always returnsnull
- Overrides:
getErrorHandler
in classorg.apache.commons.digester.Digester
-
addDoNothing
public void addDoNothing(String pattern)
Adds a dummy rule for element paths, that are allowed, but not parsed.
-
setRulesWithInvalidElementCheck
public void setRulesWithInvalidElementCheck(org.apache.commons.digester.Rules rules)
Adds a default Rule for not allowing invalid (not registered) event paths. The given Rules object is wrapped and set usingsetRules(Rules rules)
.
-
clear
public void clear()
- Overrides:
clear
in classorg.apache.commons.digester.Digester
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Overrides:
startPrefixMapping
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Overrides:
endPrefixMapping
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Overrides:
ignorableWhitespace
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
processingInstruction
in interfaceContentHandler
- Overrides:
processingInstruction
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntity
in interfaceContentHandler
- Overrides:
skippedEntity
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
warning
public void warning(SAXParseException ex) throws SAXException
Logs the SAX exception as warning (with location).- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
error
public void error(SAXParseException ex) throws SAXException
Just throwsex
.- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
fatalError
public void fatalError(SAXParseException ex) throws SAXException
Just throwsex
.- Specified by:
fatalError
in interfaceErrorHandler
- Overrides:
fatalError
in classorg.apache.commons.digester.Digester
- Throws:
SAXException
-
replayStartPrefixMappings
public void replayStartPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces) throws SAXException
Replays all current prefix mappings for anotherContentHandler
(start mapping).- Parameters:
handler
- the handler whichContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
is called.excludeNamespaces
- are prefixes for namespaces that should not be reported.- Throws:
SAXException
-
replayEndPrefixMappings
public void replayEndPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces) throws SAXException
Replays all current prefix mappings for anotherContentHandler
(end mapping).- Parameters:
handler
- the handler whichContentHandler.endPrefixMapping(java.lang.String)
is called.excludeNamespaces
- are prefixes for namespaces that should not be reported.- Throws:
SAXException
-
getCurrentAssignedPrefixes
public Set<String> getCurrentAssignedPrefixes()
Returns all current namespace prefix that are assigned.
-
getCurrentNamespaceForPrefix
public String getCurrentNamespaceForPrefix(String prefix)
Returns the current namespace URI for the given prefix.
-
getCurrentNamespaceMap
public Map<String,String> getCurrentNamespaceMap()
Returns the current namespace prefix mappings as modifiableMap
containing the prefix and the current namespace assignment (it is just a copy of the internal representation's current mapping).
-
getCurrentNamespaceContext
public NamespaceContext getCurrentNamespaceContext(boolean strict, boolean reDefineDefaultPrefix)
Returns the currentNamespaceContext
for compiling XPath expressions.- Parameters:
strict
- denotes, that undeclared prefixes throw anIllegalArgumentException
, like XSLT does it.reDefineDefaultPrefix
- denotes, that the default "xmlns" is reassigned. This conforms to XSLT.
-
-