Interface Filter

  • All Superinterfaces:
    All Known Subinterfaces:
    BytesDocumentFilter, StringDocumentFilter

    public interface Filter
    extends NamedFilter
    Filters a document.

    A Filter can take a single document change it and return a new document by returning: a FilterResult. A filter result can either consist of zero documents (removing the document possibly stopping it from being stored, one document that may have been the result of editing the given document, many documents which may be the result of splitting the given document or FilterResult.skipped() to mark that this filter is making no changes and should be considered skipped.

    Typically it is simpler to implement StringDocumentFilter or BytesDocumentFilter than it is to implement this.

    • Method Detail

      • filter

        FilterResult filter​(FilterableDocument document,
                            FilterContext context)
                     throws RuntimeException,
        Filter a document.

        Typically the interfaces BytesDocumentFilter or StringDocumentFilter are implemented instead of Filter as they gives easier access to the document content. This interface should be implemented when the filter does not need to read or modify the documents content.

        Filtering only throws unchecked exceptions. In the case a unchecked exception is thrown filtering for that document is stopped and the document may or not be stored. When an exception is raised in a filter the filter can choose to:

        • Re-throw the exception as a unchecked exception, ideally as a FilterException.
        • Return FilterResult.isSkipped() to indicate that the filter should be considered skipped, in the case of a choice filter this will cause it to try the next filter.
        • Ignore the exception and return any other type of FilterResult with or without changes to the given document.
        If a checked Exception is raised the filter should catch the exception and typically return the original document or return FilterResult.skipped().
        document - The document to be filtered.
        context - The context the filter is running under.
        A FilterResult which comes from one of the static methods on FilterResult.
        RuntimeException - when a programming error occurs and the filtering of the given document should be considered a failure. Within gathering this may stop the document from being stored, however other documents will continue to be filtered.
        FilterException - when an error occurs during the filtering of the document, and the document should not be filtered any further. Within gathering this may stop the document from being stored, howeber other documents will contine to be filtered.