public abstract class AbstractImporterHandler extends Object implements IXMLConfigurable
myHandler.setRestriction("document.contentType", "^text/.*$");Subclasses inherit this
IXMLConfigurable
configuration:
<restrictTo caseSensitive="[false|true]" field="(name of metadata field name to match)"> (regular expression of value to match) </restrictTo> <!-- multiple "restrictTo" tags allowed (only one needs to match) -->
Subclasses must test if a document is accepted using the
isApplicable(String, ImporterMetadata, boolean)
method.
Subclasses can safely be used as either pre-parse or post-parse handlers.
Constructor and Description |
---|
AbstractImporterHandler(String xmltag) |
Modifier and Type | Method and Description |
---|---|
void |
addRestriction(PropertyMatcher... restriction)
Adds one or more restrictions this handler should be restricted to.
|
void |
addRestriction(String field,
String regex,
boolean caseSensitive)
Adds a restriction this handler should be restricted to.
|
void |
addRestrictions(List<PropertyMatcher> restrictions)
Adds restrictions this handler should be restricted to.
|
void |
clearRestrictions()
Clears all restrictions.
|
protected String |
detectCharsetIfBlank(String charset,
String reference,
InputStream document,
ImporterMetadata metadata,
boolean parsed)
Convenience method for handlers that need to detect an input encoding
if the explicitly provided encoding is blank.
|
boolean |
equals(Object other) |
List<PropertyMatcher> |
getRestrictions()
Gets all restrictions
|
int |
hashCode() |
protected boolean |
isApplicable(String reference,
ImporterMetadata metadata,
boolean parsed)
Class to invoke by subclasses to find out if this handler should be
rejected or not based on the metadata restriction provided.
|
void |
loadFromXML(Reader in) |
protected abstract void |
loadHandlerFromXML(org.apache.commons.configuration.XMLConfiguration xml)
Loads configuration settings specific to the implementing class.
|
boolean |
removeRestriction(PropertyMatcher restriction)
Removes a restriction.
|
int |
removeRestriction(String field)
Removes all restrictions on a given field.
|
protected abstract void |
saveHandlerToXML(EnhancedXMLStreamWriter writer)
Saves configuration settings specific to the implementing class.
|
void |
saveToXML(Writer out) |
String |
toString() |
public AbstractImporterHandler(String xmltag)
public void addRestriction(String field, String regex, boolean caseSensitive)
field
- metadata property/fieldregex
- regular expressioncaseSensitive
- whether regular expression should be case sensitivepublic void addRestriction(PropertyMatcher... restriction)
restriction
- the restrictionpublic void addRestrictions(List<PropertyMatcher> restrictions)
restrictions
- the restrictionspublic int removeRestriction(String field)
field
- the field to remove restrictions onpublic boolean removeRestriction(PropertyMatcher restriction)
restriction
- the restriction to removetrue
if this handler contained the restrictionpublic void clearRestrictions()
public List<PropertyMatcher> getRestrictions()
protected final boolean isApplicable(String reference, ImporterMetadata metadata, boolean parsed)
reference
- document referencemetadata
- document metadata.parsed
- if the document was parsed (i.e. imported) alreadytrue
if this handler is applicable to the documentprotected final String detectCharsetIfBlank(String charset, String reference, InputStream document, ImporterMetadata metadata, boolean parsed)
charset
- the character encoding to test if blankreference
- the reference of the document to detect charset ondocument
- the document to detect charset onmetadata
- the document metadata to check for declared encodingparsed
- whether the document has already been parsed or not.public final void loadFromXML(Reader in) throws IOException
loadFromXML
in interface IXMLConfigurable
IOException
protected abstract void loadHandlerFromXML(org.apache.commons.configuration.XMLConfiguration xml) throws IOException
xml
- xml configurationIOException
- could not load from XMLpublic final void saveToXML(Writer out) throws IOException
saveToXML
in interface IXMLConfigurable
IOException
protected abstract void saveHandlerToXML(EnhancedXMLStreamWriter writer) throws XMLStreamException
writer
- the xml writerXMLStreamException
- could not save to XMLCopyright © 2009–2021 Norconex Inc.. All rights reserved.