Class AbstractSession

  • All Implemented Interfaces:
    javax.jcr.Session

    public abstract class AbstractSession
    extends java.lang.Object
    implements javax.jcr.Session
    Abstract base class for implementing the JCR Session interface.
    • Field Summary

      • Fields inherited from interface javax.jcr.Session

        ACTION_ADD_NODE, ACTION_READ, ACTION_REMOVE, ACTION_SET_PROPERTY
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractSession()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void exportDocumentView​(java.lang.String absPath, java.io.OutputStream out, boolean skipBinary, boolean noRecurse)
      Calls Session.exportDocumentView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.
      void exportDocumentView​(java.lang.String path, org.xml.sax.ContentHandler handler, boolean skipBinary, boolean noRecurse)
      Generates a document view export using a DocumentViewExporter instance.
      void exportSystemView​(java.lang.String absPath, java.io.OutputStream out, boolean skipBinary, boolean noRecurse)
      Calls Session.exportSystemView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.
      void exportSystemView​(java.lang.String path, org.xml.sax.ContentHandler handler, boolean skipBinary, boolean noRecurse)
      Generates a system view export using a SystemViewExporter instance.
      javax.jcr.Item getItem​(java.lang.String absPath)
      Returns the node or property at the given path.
      java.lang.String getNamespacePrefix​(java.lang.String uri)
      Returns the namespace prefix mapped to the given URI.
      java.lang.String[] getNamespacePrefixes()
      Returns the prefixes of all known namespace mappings.
      java.lang.String getNamespaceURI​(java.lang.String prefix)
      Returns the namespace URI mapped to the given prefix.
      javax.jcr.Node getNode​(java.lang.String absPath)
      Returns the node with the given absolute path.
      javax.jcr.Property getProperty​(java.lang.String absPath)
      Returns the property with the given absolute path.
      javax.jcr.Session impersonate​(javax.jcr.Credentials credentials)
      Logs in the same workspace with the given credentials.
      void importXML​(java.lang.String parentAbsPath, java.io.InputStream in, int uuidBehavior)
      Parses the given input stream as an XML document and processes the SAX events using the ContentHandler returned by Session.getImportContentHandler(String, int).
      boolean itemExists​(java.lang.String absPath)
      Calls getItem(String) with the given path and returns true if the call succeeds.
      void logout()
      Clears the local namespace mappings.
      boolean nodeExists​(java.lang.String absPath)
      Checks whether a node with the given absolute path exists.
      boolean propertyExists​(java.lang.String absPath)
      Checks whether a property with the given absolute path exists.
      void removeItem​(java.lang.String absPath)
      Removes the identified item.
      void setNamespacePrefix​(java.lang.String prefix, java.lang.String uri)
      Modifies the session local namespace mappings to contain the given prefix to URI mapping.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.jcr.Session

        addLockToken, checkPermission, getAccessControlManager, getAttribute, getAttributeNames, getImportContentHandler, getLockTokens, getNodeByIdentifier, getNodeByUUID, getRepository, getRetentionManager, getRootNode, getUserID, getValueFactory, getWorkspace, hasCapability, hasPendingChanges, hasPermission, isLive, move, refresh, removeLockToken, save
    • Constructor Detail

      • AbstractSession

        public AbstractSession()
    • Method Detail

      • logout

        public void logout()
        Clears the local namespace mappings. Subclasses that for example want to participate in a session pools should remember to call super.logout() when overriding this method to avoid namespace mappings to be carried over to a new session.
        Specified by:
        logout in interface javax.jcr.Session
      • getNamespacePrefix

        public java.lang.String getNamespacePrefix​(java.lang.String uri)
                                            throws javax.jcr.NamespaceException,
                                                   javax.jcr.RepositoryException
        Returns the namespace prefix mapped to the given URI. The mapping is added to the set of session-local namespace mappings unless it already exists there.

        This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

        Specified by:
        getNamespacePrefix in interface javax.jcr.Session
        Parameters:
        uri - namespace URI
        Returns:
        namespace prefix
        Throws:
        javax.jcr.NamespaceException - if the namespace is not found
        javax.jcr.RepositoryException - if a repository error occurs
      • getNamespaceURI

        public java.lang.String getNamespaceURI​(java.lang.String prefix)
                                         throws javax.jcr.NamespaceException,
                                                javax.jcr.RepositoryException
        Returns the namespace URI mapped to the given prefix. The mapping is added to the set of session-local namespace mappings unless it already exists there.

        This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

        Specified by:
        getNamespaceURI in interface javax.jcr.Session
        Parameters:
        prefix - namespace prefix
        Returns:
        namespace URI
        Throws:
        javax.jcr.NamespaceException - if the namespace is not found
        javax.jcr.RepositoryException - if a repository error occurs
      • getNamespacePrefixes

        public java.lang.String[] getNamespacePrefixes()
                                                throws javax.jcr.RepositoryException
        Returns the prefixes of all known namespace mappings. All global mappings not already included in the local set of namespace mappings are added there.

        This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

        Specified by:
        getNamespacePrefixes in interface javax.jcr.Session
        Returns:
        namespace prefixes
        Throws:
        javax.jcr.RepositoryException - if a repository error occurs
      • setNamespacePrefix

        public void setNamespacePrefix​(java.lang.String prefix,
                                       java.lang.String uri)
                                throws javax.jcr.NamespaceException,
                                       javax.jcr.RepositoryException
        Modifies the session local namespace mappings to contain the given prefix to URI mapping.

        This behaviour is based on JSR 283 (JCR 2.0), but remains backwards compatible with JCR 1.0.

        Specified by:
        setNamespacePrefix in interface javax.jcr.Session
        Parameters:
        prefix - namespace prefix
        uri - namespace URI
        Throws:
        javax.jcr.NamespaceException - if the mapping is illegal
        javax.jcr.RepositoryException - if a repository error occurs
      • exportDocumentView

        public void exportDocumentView​(java.lang.String path,
                                       org.xml.sax.ContentHandler handler,
                                       boolean skipBinary,
                                       boolean noRecurse)
                                throws javax.jcr.PathNotFoundException,
                                       org.xml.sax.SAXException,
                                       javax.jcr.RepositoryException
        Generates a document view export using a DocumentViewExporter instance.
        Specified by:
        exportDocumentView in interface javax.jcr.Session
        Parameters:
        path - of the node to be exported
        handler - handler for the SAX events of the export
        skipBinary - whether binary values should be skipped
        noRecurse - whether to export just the identified node
        Throws:
        javax.jcr.PathNotFoundException - if a node at the given path does not exist
        org.xml.sax.SAXException - if the SAX event handler failed
        javax.jcr.RepositoryException - if another error occurs
      • exportSystemView

        public void exportSystemView​(java.lang.String path,
                                     org.xml.sax.ContentHandler handler,
                                     boolean skipBinary,
                                     boolean noRecurse)
                              throws javax.jcr.PathNotFoundException,
                                     org.xml.sax.SAXException,
                                     javax.jcr.RepositoryException
        Generates a system view export using a SystemViewExporter instance.
        Specified by:
        exportSystemView in interface javax.jcr.Session
        Parameters:
        path - of the node to be exported
        handler - handler for the SAX events of the export
        skipBinary - whether binary values should be skipped
        noRecurse - whether to export just the identified node
        Throws:
        javax.jcr.PathNotFoundException - if a node at the given path does not exist
        org.xml.sax.SAXException - if the SAX event handler failed
        javax.jcr.RepositoryException - if another error occurs
      • exportDocumentView

        public void exportDocumentView​(java.lang.String absPath,
                                       java.io.OutputStream out,
                                       boolean skipBinary,
                                       boolean noRecurse)
                                throws java.io.IOException,
                                       javax.jcr.RepositoryException
        Calls Session.exportDocumentView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.
        Specified by:
        exportDocumentView in interface javax.jcr.Session
        Parameters:
        absPath - passed through
        out - output stream to which the SAX events are serialized
        skipBinary - passed through
        noRecurse - passed through
        Throws:
        java.io.IOException - if the SAX serialization failed
        javax.jcr.RepositoryException - if another error occurs
      • exportSystemView

        public void exportSystemView​(java.lang.String absPath,
                                     java.io.OutputStream out,
                                     boolean skipBinary,
                                     boolean noRecurse)
                              throws java.io.IOException,
                                     javax.jcr.RepositoryException
        Calls Session.exportSystemView(String, ContentHandler, boolean, boolean) with the given arguments and a ContentHandler that serializes SAX events to the given output stream.
        Specified by:
        exportSystemView in interface javax.jcr.Session
        Parameters:
        absPath - passed through
        out - output stream to which the SAX events are serialized
        skipBinary - passed through
        noRecurse - passed through
        Throws:
        java.io.IOException - if the SAX serialization failed
        javax.jcr.RepositoryException - if another error occurs
      • importXML

        public void importXML​(java.lang.String parentAbsPath,
                              java.io.InputStream in,
                              int uuidBehavior)
                       throws java.io.IOException,
                              javax.jcr.InvalidSerializedDataException,
                              javax.jcr.RepositoryException
        Parses the given input stream as an XML document and processes the SAX events using the ContentHandler returned by Session.getImportContentHandler(String, int).
        Specified by:
        importXML in interface javax.jcr.Session
        Parameters:
        parentAbsPath - passed through
        in - input stream to be parsed as XML and imported
        uuidBehavior - passed through
        Throws:
        java.io.IOException - if an I/O error occurs
        javax.jcr.InvalidSerializedDataException - if an XML parsing error occurs
        javax.jcr.RepositoryException - if a repository error occurs
      • getItem

        public javax.jcr.Item getItem​(java.lang.String absPath)
                               throws javax.jcr.PathNotFoundException,
                                      javax.jcr.RepositoryException
        Returns the node or property at the given path.

        The default implementation:

        • Returns the root node if the given path is "/"
        • Delegates to Session.getNodeByIdentifier(String) for identifier paths
        • Throws a PathNotFoundException if the given path does not start with a slash.
        • Calls Node.getNode(String) on the root node with the part of the given path after the first slash
        • Calls Node.getProperty(String) similarly in case the above call fails with a PathNotFoundException
        Specified by:
        getItem in interface javax.jcr.Session
        Parameters:
        absPath - absolute path
        Returns:
        the node or property with the given path
        Throws:
        javax.jcr.PathNotFoundException - if the given path is invalid or not found
        javax.jcr.RepositoryException - if another error occurs
        See Also:
        Session.getItem(String)
      • itemExists

        public boolean itemExists​(java.lang.String absPath)
                           throws javax.jcr.RepositoryException
        Calls getItem(String) with the given path and returns true if the call succeeds. Returns false if a PathNotFoundException was thrown. Other exceptions are passed through.
        Specified by:
        itemExists in interface javax.jcr.Session
        Parameters:
        absPath - absolute path
        Returns:
        true if an item exists at the given path, false otherwise
        Throws:
        javax.jcr.RepositoryException - if an error occurs
        See Also:
        Session.itemExists(String)
      • removeItem

        public void removeItem​(java.lang.String absPath)
                        throws javax.jcr.RepositoryException
        Removes the identified item. Implemented by calling Item.remove() on the item removed by getItem(String).
        Specified by:
        removeItem in interface javax.jcr.Session
        Parameters:
        absPath - An absolute path of the item to be removed
        Throws:
        javax.jcr.RepositoryException - if the item can not be removed
        See Also:
        Session.removeItem(String)
      • getNode

        public javax.jcr.Node getNode​(java.lang.String absPath)
                               throws javax.jcr.RepositoryException
        Returns the node with the given absolute path.
        Specified by:
        getNode in interface javax.jcr.Session
        Parameters:
        absPath - absolute path
        Returns:
        node at the given path
        Throws:
        javax.jcr.RepositoryException - if the node can not be accessed
        See Also:
        Session.getNode(String)
      • nodeExists

        public boolean nodeExists​(java.lang.String absPath)
                           throws javax.jcr.RepositoryException
        Checks whether a node with the given absolute path exists.
        Specified by:
        nodeExists in interface javax.jcr.Session
        Parameters:
        absPath - absolute path
        Returns:
        true if a node with the given path exists, false otherwise
        Throws:
        javax.jcr.RepositoryException - if the path is invalid
        See Also:
        Session.nodeExists(String)
      • getProperty

        public javax.jcr.Property getProperty​(java.lang.String absPath)
                                       throws javax.jcr.RepositoryException
        Returns the property with the given absolute path.
        Specified by:
        getProperty in interface javax.jcr.Session
        Parameters:
        absPath - absolute path
        Returns:
        node at the given path
        Throws:
        javax.jcr.RepositoryException - if the property can not be accessed
        See Also:
        Session.getProperty(String)
      • propertyExists

        public boolean propertyExists​(java.lang.String absPath)
                               throws javax.jcr.RepositoryException
        Checks whether a property with the given absolute path exists.
        Specified by:
        propertyExists in interface javax.jcr.Session
        Parameters:
        absPath - absolute path
        Returns:
        true if a property with the given path exists, false otherwise
        Throws:
        javax.jcr.RepositoryException - if the path is invalid
        See Also:
        Session.propertyExists(String)
      • impersonate

        public javax.jcr.Session impersonate​(javax.jcr.Credentials credentials)
                                      throws javax.jcr.RepositoryException
        Logs in the same workspace with the given credentials.

        The default implementation:

        • Retrieves the Repository instance using Session.getRepository()
        • Retrieves the current workspace using Session.getWorkspace()
        • Retrieves the name of the current workspace using Workspace.getName()
        • Calls Repository.login(Credentials, String) on the retrieved repository with the given credentials and the retrieved workspace name.
        Specified by:
        impersonate in interface javax.jcr.Session
        Parameters:
        credentials - login credentials
        Returns:
        logged in session
        Throws:
        javax.jcr.RepositoryException - if an error occurs