Class Exporter

  • Direct Known Subclasses:
    DocumentViewExporter, SystemViewExporter

    public abstract class Exporter
    extends Object
    Abstract base class for document and system view exporters. This class takes care of all the details related to namespace mappings, shareable nodes, recursive exports, binary values, and so on while leaving the decisions about what kind of SAX events to generate to subclasses.

    A subclass should only need to implement the abstract methods of this class to produce a fully functional exporter.

    Since:
    Jackrabbit JCR Commons 1.5
    • Constructor Detail

      • Exporter

        protected Exporter​(Session session,
                           ContentHandler handler,
                           boolean recurse,
                           boolean binary)
        Creates an exporter instance.
        Parameters:
        session - current session
        handler - SAX event handler
        recurse - whether the export should be recursive
        binary - whether the export should include binary values
    • Method Detail

      • exportNode

        protected abstract void exportNode​(String uri,
                                           String local,
                                           Node node)
                                    throws RepositoryException,
                                           SAXException
        Called to export the given node. The node name (or jcr:root if the node is the root node) is given as an explicit pair of the resolved namespace URI and local part of the name.

        The implementation of this method should call the methods exportProperties(Node) and exportProperties(Node) to respectively export the properties and child nodes of the given node. Those methods will call back to the implementations of this method and the abstract property export methods so the subclass can decide what SAX events to emit for each exported item.

        Parameters:
        uri - node namespace
        local - node name
        node - node
        Throws:
        RepositoryException - if a repository error occurs
        SAXException - if a SAX error occurs
      • exportProperties

        protected void exportProperties​(Node node)
                                 throws RepositoryException,
                                        SAXException
        Processes all properties of the given node by calling the abstract exportProperty(String, String, Value) and exportProperty(String, String, int, Value[]) methods for each property depending on whether the property is single- or multivalued.

        The first properties to be processed are jcr:primaryType, jcr:mixinTypes, and jcr:uuid, and then the remaining properties ordered by their names.

        If the node is a shareable node that has already been encountered by this event generator, then only a jcr:primaryType property with the fixed value "nt:share" and the jcr:uuid property of the shareable node are exported.

        Parameters:
        node - node
        Throws:
        RepositoryException - if a repository error occurs
        SAXException - if a SAX error occurs
        See Also:
        JCR-1084
      • characters

        protected void characters​(char[] ch,
                                  int start,
                                  int length)
                           throws SAXException
        Emits a characters event with the given character content.
        Parameters:
        ch - character array
        start - start offset within the array
        length - number of characters to emit
        Throws:
        SAXException - if a SAX error occurs
      • addAttribute

        protected void addAttribute​(String uri,
                                    String local,
                                    String value)
                             throws RepositoryException
        Adds the given attribute to be included in the next element.
        Parameters:
        uri - namespace URI of the attribute
        local - local name of the attribute
        value - attribute value
        Throws:
        RepositoryException - if a repository error occurs
      • startElement

        protected void startElement​(String uri,
                                    String local)
                             throws SAXException,
                                    RepositoryException
        Emits the start element event for an element with the given name. All the attributes added using addAttribute(String, String, String) are included in the element along with any new namespace mappings. The namespace stack is extended for potential child elements.
        Parameters:
        uri - namespace URI or the element
        local - local name of the element
        Throws:
        RepositoryException - if a repository error occurs
        SAXException - if a SAX error occurs
      • endElement

        protected void endElement​(String uri,
                                  String local)
                           throws SAXException,
                                  RepositoryException
        Emits the end element event for an element with the given name. The namespace stack and mappings are automatically updated.
        Parameters:
        uri - namespace URI or the element
        local - local name of the element
        Throws:
        RepositoryException - if a repository error occurs
        SAXException - if a SAX error occurs
      • getXMLName

        protected String getXMLName​(String uri,
                                    String local)
                             throws RepositoryException
        Returns a prefixed XML name for the given namespace URI and local name. If a prefix mapping for the namespace URI is not yet available, it is created based on the namespace mappings of the current JCR session.
        Parameters:
        uri - namespace URI
        local - local name
        Returns:
        prefixed XML name
        Throws:
        RepositoryException - if a JCR namespace mapping is not available
      • addNamespace

        protected String addNamespace​(String hint,
                                      String uri)
        Adds the given namespace to the export. A unique prefix based on the given prefix hint is mapped to the given namespace URI. If the namespace is already mapped, then the existing prefix is returned.
        Parameters:
        hint - prefix hint
        uri - namespace URI
        Returns:
        registered prefix