Class RootElementNameContentWorkerSelector<W extends ContentWorker>

  • All Implemented Interfaces:
    ContentWorkerSelector<ContentWorker>, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

    public class RootElementNameContentWorkerSelector<W extends ContentWorker>
    extends org.xml.sax.helpers.DefaultHandler
    implements ContentWorkerSelector<ContentWorker>
    A selector that looks at the root node of an XML document to determine which worker to provide. There are many ways to identify XML documents and this is probably the simplest. Alternate implementations might execute a series of xpath statements or look for specific namespace declarations in the document. The net result is the same, i.e. given an XML document, a worker is provided to the caller.
    Since:
    2.1
    Author:
    Derek Hulley
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      W getWorker​(org.alfresco.service.cmr.repository.ContentReader reader)
      Performs a match of the root element name to find the correct content worker.
      void init()
      Checks the configuration.
      void setSupportedMimetypes​(java.util.Set<java.lang.String> supportedMimetypes)
      Optionally set the mimetypes supported.
      void setWorkers​(java.util.Map<java.lang.String,​W> workers)
      Set the workers to choose from.
      void startElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)  
      java.lang.String toString()  
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RootElementNameContentWorkerSelector

        public RootElementNameContentWorkerSelector()
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • setSupportedMimetypes

        public void setSupportedMimetypes​(java.util.Set<java.lang.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​(java.util.Map<java.lang.String,​W> workers)
        Set the workers to choose from.
        Parameters:
        workers - a map of ContentWorker instances keyed by root element name
      • init

        public void init()
        Checks the configuration.
      • getWorker

        public W getWorker​(org.alfresco.service.cmr.repository.ContentReader reader)
        Performs a match of the root element name to find the correct content worker.
        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.
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException