Class BlankCondition

java.lang.Object
com.norconex.importer.handler.condition.impl.BlankCondition
All Implemented Interfaces:
IXMLConfigurable, IImporterCondition

public class BlankCondition extends Object implements IImporterCondition, IXMLConfigurable

A condition based on whether the document content (default) or any of the specified metadata fields are blank or inexistent. For metadata fields, control characters (char <= 32) are removed before evaluating whether their values are empty. Dealing with the document content will rather check if it is null or empty (no bytes returned when read).

Multiple fields and values:

By default, ALL values for all fields matched by your field matcher expression must be blank for this condition to be true. You can change the logic to have ANY values to be blank for the condition to be true with setMatchAnyBlank(boolean).

If no fields are matched, the conditions is also considered empty (true).

XML configuration usage:


<condition
    class="com.norconex.importer.handler.condition.impl.BlankCondition"
    matchAnyBlank="[false|true]">
  <fieldMatcher>
    (Optional expression matching fields we want to test if blank,
    instead of using the document content.)
  </fieldMatcher>
</handler>

XML usage example:


<condition
    class="BlankCondition">
  <fieldMatcher
      method="regex">
    (title|dc:title)
  </fieldMatcher>
</condition>

The above example condition will return true if both "title" or "dc:title" are blank.

Since:
3.0.0
Author:
Pascal Essiembre
  • Constructor Details

    • BlankCondition

      public BlankCondition()
  • Method Details

    • getFieldMatcher

      public TextMatcher getFieldMatcher()
      Gets the field matcher.
      Returns:
      field matcher
    • setFieldMatcher

      public void setFieldMatcher(TextMatcher fieldMatcher)
      Sets the field matcher.
      Parameters:
      fieldMatcher - field matcher
    • isMatchAnyBlank

      public boolean isMatchAnyBlank()
      Whether any matched blank value should satisfy the condition.
      Returns:
      true for any-match behavior
    • setMatchAnyBlank

      public void setMatchAnyBlank(boolean matchAnyBlank)
      Sets whether any matched blank value should satisfy the condition.
      Parameters:
      matchAnyBlank - true for any-match behavior
    • testDocument

      public boolean testDocument(HandlerDoc doc, InputStream input, ParseState parseState) throws ImporterHandlerException
      Description copied from interface: IImporterCondition
      Tests a given document.
      Specified by:
      testDocument in interface IImporterCondition
      Parameters:
      doc - the document to test
      input - document content
      parseState - whether the document has been parsed already or not (a parsed document should normally be text-based)
      Returns:
      true if the condition evaluates as such
      Throws:
      ImporterHandlerException - problem reading the document
    • loadFromXML

      public void loadFromXML(XML xml)
      Specified by:
      loadFromXML in interface IXMLConfigurable
    • saveToXML

      public void saveToXML(XML xml)
      Specified by:
      saveToXML in interface IXMLConfigurable
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object