de.pangaea.metadataportal.utils
Class ExtendedDigester

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.commons.digester.Digester
          extended by 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 for SaxRule, 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
static class ExtendedDigester.DoNothingRule
          This rule does nothing.
 
Field Summary
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
ExtendedDigester()
           
 
Method Summary
 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 throws ex.
 void fatalError(SAXParseException ex)
          Just throws ex.
 Set<String> getCurrentAssignedPrefixes()
          Returns all current namespace prefix that are assigned.
 NamespaceContext getCurrentNamespaceContext(boolean strict, boolean reDefineDefaultPrefix)
          Returns the current NamespaceContext 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 modifiable Map 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 returns null
 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 another ContentHandler (end mapping).
 void replayStartPrefixMappings(ContentHandler handler, Set<String> excludeNamespaces)
          Replays all current prefix mappings for another ContentHandler (start mapping).
 void setCustomContentHandler(ContentHandler c)
          Sets a custom ContentHandler, that receives all SAX events until disabled (null).
 void setErrorHandler(ErrorHandler err)
          Not suppoted, always throws IllegalArgumentException if not null.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentNamespaceMap

protected final HashMap<String,LinkedList<String>> currentNamespaceMap

custContentHandler

protected ContentHandler custContentHandler
Constructor Detail

ExtendedDigester

public ExtendedDigester()
Method Detail

setCustomContentHandler

public void setCustomContentHandler(ContentHandler c)
Sets a custom ContentHandler, that receives all SAX events until disabled (null).

Overrides:
setCustomContentHandler in class org.apache.commons.digester.Digester

getCustomContentHandler

public ContentHandler getCustomContentHandler()
Gets the custom event handler.

Overrides:
getCustomContentHandler in class org.apache.commons.digester.Digester

setErrorHandler

public void setErrorHandler(ErrorHandler err)
Not suppoted, always throws IllegalArgumentException if not null.

Overrides:
setErrorHandler in class org.apache.commons.digester.Digester

getErrorHandler

public ErrorHandler getErrorHandler()
Not supported, always returns null

Overrides:
getErrorHandler in class org.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 using setRules(Rules rules).


clear

public void clear()
Overrides:
clear in class org.apache.commons.digester.Digester

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class org.apache.commons.digester.Digester
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Overrides:
endPrefixMapping in class org.apache.commons.digester.Digester
Throws:
SAXException

startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class org.apache.commons.digester.Digester
Throws:
SAXException

endElement

public void endElement(String uri,
                       String localName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class org.apache.commons.digester.Digester
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class org.apache.commons.digester.Digester
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class org.apache.commons.digester.Digester
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class org.apache.commons.digester.Digester
Throws:
SAXException

skippedEntity

public void skippedEntity(String name)
                   throws SAXException
Specified by:
skippedEntity in interface ContentHandler
Overrides:
skippedEntity in class org.apache.commons.digester.Digester
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class org.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 interface ErrorHandler
Overrides:
warning in class org.apache.commons.digester.Digester
Throws:
SAXException

error

public void error(SAXParseException ex)
           throws SAXException
Just throws ex.

Specified by:
error in interface ErrorHandler
Overrides:
error in class org.apache.commons.digester.Digester
Throws:
SAXException

fatalError

public void fatalError(SAXParseException ex)
                throws SAXException
Just throws ex.

Specified by:
fatalError in interface ErrorHandler
Overrides:
fatalError in class org.apache.commons.digester.Digester
Throws:
SAXException

replayStartPrefixMappings

public void replayStartPrefixMappings(ContentHandler handler,
                                      Set<String> excludeNamespaces)
                               throws SAXException
Replays all current prefix mappings for another ContentHandler (start mapping).

Parameters:
handler - the handler which ContentHandler.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 another ContentHandler (end mapping).

Parameters:
handler - the handler which ContentHandler.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 modifiable Map 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 current NamespaceContext for compiling XPath expressions.

Parameters:
strict - denotes, that undeclared prefixes throw an IllegalArgumentException, like XSLT does it.
reDefineDefaultPrefix - denotes, that the default "xmlns" is reassigned. This conforms to XSLT.


Copyright ©2007-2009 panFMP Developers c/o Uwe Schindler