org.apache.tika.parser.xml
Class ElementMetadataHandler

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.apache.tika.parser.xml.ElementMetadataHandler
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class ElementMetadataHandler
extends org.xml.sax.helpers.DefaultHandler

SAX event handler that maps the contents of an XML element into a metadata field.

Since:
Apache Tika 0.10

Constructor Summary
ElementMetadataHandler(String uri, String localName, org.apache.tika.metadata.Metadata metadata, org.apache.tika.metadata.Property targetProperty)
          Constructor for Property metadata keys.
ElementMetadataHandler(String uri, String localName, org.apache.tika.metadata.Metadata metadata, org.apache.tika.metadata.Property targetProperty, boolean allowDuplicateValues, boolean allowEmptyValues)
          Constructor for Property metadata keys which allows change of behavior for duplicate and empty entry values.
ElementMetadataHandler(String uri, String localName, org.apache.tika.metadata.Metadata metadata, String name)
          Constructor for string metadata keys.
ElementMetadataHandler(String uri, String localName, org.apache.tika.metadata.Metadata metadata, String name, boolean allowDuplicateValues, boolean allowEmptyValues)
          Constructor for string metadata keys which allows change of behavior for duplicate and empty entry values.
 
Method Summary
protected  void addMetadata(String value)
          Adds the given metadata value.
 void characters(char[] ch, int start, int length)
           
 void endElement(String uri, String localName, String name)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
protected  boolean isMatchingElement(String uri, String localName)
           
protected  boolean isMatchingParentElement(String uri, String localName)
           
 void startElement(String uri, String localName, String name, Attributes attributes)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementMetadataHandler

public ElementMetadataHandler(String uri,
                              String localName,
                              org.apache.tika.metadata.Metadata metadata,
                              String name)
Constructor for string metadata keys.

Parameters:
uri - the uri of the namespace of the element
localName - the local name of the element
metadata - the Tika metadata object to populate
name - the Tika metadata field key

ElementMetadataHandler

public ElementMetadataHandler(String uri,
                              String localName,
                              org.apache.tika.metadata.Metadata metadata,
                              String name,
                              boolean allowDuplicateValues,
                              boolean allowEmptyValues)
Constructor for string metadata keys which allows change of behavior for duplicate and empty entry values.

Parameters:
uri - the uri of the namespace of the element
localName - the local name of the element
metadata - the Tika metadata object to populate
name - the Tika metadata field key
allowDuplicateValues - add duplicate values to the Tika metadata
allowEmptyValues - add empty values to the Tika metadata

ElementMetadataHandler

public ElementMetadataHandler(String uri,
                              String localName,
                              org.apache.tika.metadata.Metadata metadata,
                              org.apache.tika.metadata.Property targetProperty)
Constructor for Property metadata keys.

Parameters:
uri - the uri of the namespace of the element
localName - the local name of the element
metadata - the Tika metadata object to populate
targetProperty - the Tika metadata Property key

ElementMetadataHandler

public ElementMetadataHandler(String uri,
                              String localName,
                              org.apache.tika.metadata.Metadata metadata,
                              org.apache.tika.metadata.Property targetProperty,
                              boolean allowDuplicateValues,
                              boolean allowEmptyValues)
Constructor for Property metadata keys which allows change of behavior for duplicate and empty entry values.

Parameters:
uri - the uri of the namespace of the element
localName - the local name of the element
metadata - the Tika metadata object to populate
targetProperty - the Tika metadata Property key
allowDuplicateValues - add duplicate values to the Tika metadata
allowEmptyValues - add empty values to the Tika metadata
Method Detail

isMatchingParentElement

protected boolean isMatchingParentElement(String uri,
                                          String localName)

isMatchingElement

protected boolean isMatchingElement(String uri,
                                    String localName)

startElement

public void startElement(String uri,
                         String localName,
                         String name,
                         Attributes attributes)
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler

endElement

public void endElement(String uri,
                       String localName,
                       String name)
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
Specified by:
characters in interface ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.helpers.DefaultHandler

addMetadata

protected void addMetadata(String value)
Adds the given metadata value. The value is ignored if it is null or empty. If the metadata entry already exists, then the given value is appended to it with a comma as the separator.

Parameters:
value - metadata value


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.