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.DigesterExtension 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 classExtendedDigester.DoNothingRuleThis rule does nothing.
-
Field Summary
Fields Modifier and Type Field Description protected HashMap<String,LinkedList<String>>currentNamespaceMapprotected ContentHandlercustContentHandler-
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 voidaddDoNothing(String pattern)Adds a dummy rule for element paths, that are allowed, but not parsed.voidcharacters(char[] ch, int start, int length)voidclear()voidendElement(String uri, String localName, String qName)voidendPrefixMapping(String prefix)voiderror(SAXParseException ex)Just throwsex.voidfatalError(SAXParseException ex)Just throwsex.Set<String>getCurrentAssignedPrefixes()Returns all current namespace prefix that are assigned.NamespaceContextgetCurrentNamespaceContext(boolean strict, boolean reDefineDefaultPrefix)Returns the currentNamespaceContextfor compiling XPath expressions.StringgetCurrentNamespaceForPrefix(String prefix)Returns the current namespace URI for the given prefix.Map<String,String>getCurrentNamespaceMap()Returns the current namespace prefix mappings as modifiableMapcontaining the prefix and the current namespace assignment (it is just a copy of the internal representation's current mapping).ContentHandlergetCustomContentHandler()Gets the custom event handler.ErrorHandlergetErrorHandler()Not supported, always returnsnullvoidignorableWhitespace(char[] ch, int start, int length)voidprocessingInstruction(String target, String data)voidreplayEndPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces)Replays all current prefix mappings for anotherContentHandler(end mapping).voidreplayStartPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces)Replays all current prefix mappings for anotherContentHandler(start mapping).voidsetCustomContentHandler(ContentHandler c)Sets a customContentHandler, that receives all SAX events until disabled (null).voidsetErrorHandler(ErrorHandler err)Not suppoted, always throwsIllegalArgumentExceptionif notnull.voidsetRulesWithInvalidElementCheck(org.apache.commons.digester.Rules rules)Adds a default Rule for not allowing invalid (not registered) event paths.voidskippedEntity(String name)voidstartDocument()voidstartElement(String uri, String localName, String qName, Attributes atts)voidstartPrefixMapping(String prefix, String uri)voidwarning(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:
setCustomContentHandlerin classorg.apache.commons.digester.Digester
-
getCustomContentHandler
public ContentHandler getCustomContentHandler()
Gets the custom event handler.- Overrides:
getCustomContentHandlerin classorg.apache.commons.digester.Digester
-
setErrorHandler
public void setErrorHandler(ErrorHandler err)
Not suppoted, always throwsIllegalArgumentExceptionif notnull.- Overrides:
setErrorHandlerin classorg.apache.commons.digester.Digester
-
getErrorHandler
public ErrorHandler getErrorHandler()
Not supported, always returnsnull- Overrides:
getErrorHandlerin 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:
clearin classorg.apache.commons.digester.Digester
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMappingin interfaceContentHandler- Overrides:
endPrefixMappingin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
endElement
public void endElement(String uri, String localName, String qName) throws SAXException
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
characters
public void characters(char[] ch, int start, int length) throws SAXException- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException- Specified by:
ignorableWhitespacein interfaceContentHandler- Overrides:
ignorableWhitespacein classorg.apache.commons.digester.Digester- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
- Specified by:
processingInstructionin interfaceContentHandler- Overrides:
processingInstructionin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntityin interfaceContentHandler- Overrides:
skippedEntityin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
startDocument
public void startDocument() throws SAXException- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin 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:
warningin interfaceErrorHandler- Overrides:
warningin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
error
public void error(SAXParseException ex) throws SAXException
Just throwsex.- Specified by:
errorin interfaceErrorHandler- Overrides:
errorin classorg.apache.commons.digester.Digester- Throws:
SAXException
-
fatalError
public void fatalError(SAXParseException ex) throws SAXException
Just throwsex.- Specified by:
fatalErrorin interfaceErrorHandler- Overrides:
fatalErrorin 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 modifiableMapcontaining 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 currentNamespaceContextfor 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.
-
-