Class XPathContentWorkerSelector<W extends ContentWorker>

  • All Implemented Interfaces:
    ContentWorkerSelector

    public class XPathContentWorkerSelector<W extends ContentWorker>
    extends Object
    implements ContentWorkerSelector
    A selector that executes a set of XPath statements against the XML document to determine which content worker to provide. The XPath rules are simple, i.e. if an XML node is found by the XPath statement, then it is considered to be a hit and the corresponding worker is returned.

    Currently, the only namespaces supported are those contained in the XML documents being tested.

    Since:
    2.1
    Author:
    Derek Hulley
    • Constructor Detail

      • XPathContentWorkerSelector

        public XPathContentWorkerSelector()
    • Method Detail

      • setSupportedMimetypes

        public void setSupportedMimetypes​(Set<String> supportedMimetypes)
        Optionally set the mimetypes supported. They must be XML formats that the chosen parser will be able to handle.
        Parameters:
        supportedMimetypes - the list of mimetypes. The default is text/xml.
      • setWorkers

        public void setWorkers​(Map<String,​W> workers)
        Set the workers to use. All the XPath statements provided must be compatible with a return value of type NODE.
        Parameters:
        workers - a map of ContentWorker instances keyed by XPath statements
      • init

        public void init()
        Checks the configuration.
      • getWorker

        public W getWorker​(ContentReader reader)
        Execute the XPath statements, in order, against the document. Any statements that fail to run will be ignored.
        Specified by:
        getWorker in interface ContentWorkerSelector<W extends ContentWorker>
        Parameters:
        reader - the content reader, providing the actual stream metadata and even the stream, if required.
        Returns:
        Return a worker that can operate on the content, or null if this identifier doesn't support the content.