Class StripAfterTransformer
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.transformer.AbstractDocumentTransformer
-
- com.norconex.importer.handler.transformer.AbstractCharStreamTransformer
-
- com.norconex.importer.handler.transformer.AbstractStringTransformer
-
- com.norconex.importer.handler.transformer.impl.StripAfterTransformer
-
- All Implemented Interfaces:
IXMLConfigurable
,IImporterHandler
,IDocumentTransformer
public class StripAfterTransformer extends AbstractStringTransformer implements IXMLConfigurable
Strips any content found after first match found for given pattern.
This class can be used as a pre-parsing (text content-types only) or post-parsing handlers.
XML configuration usage:
<handler class="com.norconex.importer.handler.transformer.impl.StripAfterTransformer" inclusive="[false|true]" maxReadSize="(max characters to read at once)" sourceCharset="(character encoding)"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> <stripAfterMatcher> > (expression matching text from which to strip) </stripAfterMatcher> </handler>
XML usage example:
<handler class="StripAfterTransformer" inclusive="true"> <stripAfterMatcher> <![CDATA[<!-- FOOTER -->]]> </stripAfterMatcher> </handler>
The above example will strip all text starting with the following HTML comment and everything after it:
<!-- FOOTER -->
.- Author:
- Pascal Essiembre
-
-
Constructor Summary
Constructors Constructor Description StripAfterTransformer()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(Object other)
TextMatcher
getStripAfterMatcher()
Gets the matcher for the text from which to strip content.String
getStripAfterRegex()
Deprecated.Since 3.0.0, usegetStripAfterMatcher()
.int
hashCode()
boolean
isCaseSensitive()
Deprecated.Since 3.0.0, usegetStripAfterMatcher()
.boolean
isInclusive()
protected void
loadStringTransformerFromXML(XML xml)
Loads configuration settings specific to the implementing class.protected void
saveStringTransformerToXML(XML xml)
Saves configuration settings specific to the implementing class.void
setCaseSensitive(boolean caseSensitive)
Deprecated.Since 3.0.0, usesetStripAfterMatcher(TextMatcher)
.void
setInclusive(boolean inclusive)
Sets whether the match itself should be stripped or not.void
setStripAfterMatcher(TextMatcher stripAfterMatcher)
Sets the matcher for the text from which to strip content.void
setStripAfterRegex(String regex)
Deprecated.Since 3.0.0, usesetStripAfterMatcher(TextMatcher)
.String
toString()
protected void
transformStringContent(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex)
-
Methods inherited from class com.norconex.importer.handler.transformer.AbstractStringTransformer
getMaxReadSize, loadCharStreamTransformerFromXML, saveCharStreamTransformerToXML, setMaxReadSize, transformTextDocument
-
Methods inherited from class com.norconex.importer.handler.transformer.AbstractCharStreamTransformer
getSourceCharset, loadHandlerFromXML, saveHandlerToXML, setSourceCharset, transformApplicableDocument
-
Methods inherited from class com.norconex.importer.handler.transformer.AbstractDocumentTransformer
transformDocument
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.norconex.commons.lang.xml.IXMLConfigurable
loadFromXML, saveToXML
-
-
-
-
Method Detail
-
transformStringContent
protected void transformStringContent(HandlerDoc doc, StringBuilder content, ParseState parseState, int sectionIndex)
- Specified by:
transformStringContent
in classAbstractStringTransformer
-
getStripAfterMatcher
public TextMatcher getStripAfterMatcher()
Gets the matcher for the text from which to strip content.- Returns:
- text matcher
- Since:
- 3.0.0
-
setStripAfterMatcher
public void setStripAfterMatcher(TextMatcher stripAfterMatcher)
Sets the matcher for the text from which to strip content.- Parameters:
stripAfterMatcher
- text matcher- Since:
- 3.0.0
-
isInclusive
public boolean isInclusive()
-
setInclusive
public void setInclusive(boolean inclusive)
Sets whether the match itself should be stripped or not.- Parameters:
inclusive
-true
to strip start and end text
-
isCaseSensitive
@Deprecated public boolean isCaseSensitive()
Deprecated.Since 3.0.0, usegetStripAfterMatcher()
.Gets whether matching is case sensitive.- Returns:
true
if case sensitive
-
setCaseSensitive
@Deprecated public void setCaseSensitive(boolean caseSensitive)
Deprecated.Since 3.0.0, usesetStripAfterMatcher(TextMatcher)
.Sets whether matching is case sensitive.- Parameters:
caseSensitive
-true
if case sensitive
-
getStripAfterRegex
@Deprecated public String getStripAfterRegex()
Deprecated.Since 3.0.0, usegetStripAfterMatcher()
.Gets the expression matching text after which to strip.- Returns:
- expression
-
setStripAfterRegex
@Deprecated public void setStripAfterRegex(String regex)
Deprecated.Since 3.0.0, usesetStripAfterMatcher(TextMatcher)
.Sets the expression matching text after which to strip.- Parameters:
regex
- expression
-
loadStringTransformerFromXML
protected void loadStringTransformerFromXML(XML xml)
Description copied from class:AbstractStringTransformer
Loads configuration settings specific to the implementing class.- Specified by:
loadStringTransformerFromXML
in classAbstractStringTransformer
- Parameters:
xml
- XML configuration
-
saveStringTransformerToXML
protected void saveStringTransformerToXML(XML xml)
Description copied from class:AbstractStringTransformer
Saves configuration settings specific to the implementing class. The parent tag along with the "class" attribute are already written. Implementors must not close the writer.- Specified by:
saveStringTransformerToXML
in classAbstractStringTransformer
- Parameters:
xml
- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equals
in classAbstractStringTransformer
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractStringTransformer
-
toString
public String toString()
- Overrides:
toString
in classAbstractStringTransformer
-
-