Class JCRSession

  • All Implemented Interfaces:
    Closeable, AutoCloseable, javax.jcr.Session

    public class JCRSession
    extends Object
    implements javax.jcr.Session, Closeable
    Implementation of the Session in Silverpeas. It decorates the real session that was opened for accessing the repository by adding to it auto-closeable trait and reentrant capability. Be aware about the limitation of the hypothesis on which the implementation of this reentrant session is built: it expects only one user session can be opened within a single thread, meaning that any further login attempts along one single thread will return the same session; in the case a login attempt is performed by another user in the same thread, an IllegalStateException exception is thrown.
    Author:
    mmoquillon
    • Method Detail

      • openSystemSession

        public static JCRSession openSystemSession()
                                            throws javax.jcr.RepositoryException
        Opens a session to the JCR for the system user (id est for Silverpeas with administrative rights). If a session already exists, then just returns it. Otherwise, a new session is opened.

        This is a shortcut of:

        
           Repository repository = RepositoryProvider.get().getRepository();
           Credentials credentials = JCRUserCredentialsProvider.getJcrSystemCredentials();
           Session session = repository.login(credentials);
         
        Returns:
        a session
        Throws:
        javax.jcr.RepositoryException - if the session opening fails.
      • openUserSession

        public static JCRSession openUserSession​(String login,
                                                 String domainId,
                                                 String password)
                                          throws javax.jcr.RepositoryException
        Opens a session to the JCR for the specified user. If a session already exists, then just returns it. Otherwise, a new session is opened. It expects any session opening in a same thread are performed for the same user, otherwise an IllegalStateException is throw.

        This is a shortcut of:

        
           Repository repository = RepositoryProvider.get().getRepository();
           Credentials credentials = JCRUserCredentialsProvider.getUserCredentials(login, domainId, password);
           Session session = repository.login(credentials);
         
        Returns:
        a session
        Throws:
        javax.jcr.RepositoryException - if the session opening fails.
      • getRepository

        public javax.jcr.Repository getRepository()
        Specified by:
        getRepository in interface javax.jcr.Session
      • getUserID

        public String getUserID()
        The unique identifier of the user in Silverpeas who has opened this session.
        Specified by:
        getUserID in interface javax.jcr.Session
        Returns:
        the user identifier
      • getAttributeNames

        public String[] getAttributeNames()
        Specified by:
        getAttributeNames in interface javax.jcr.Session
      • getAttribute

        public Object getAttribute​(String name)
        Specified by:
        getAttribute in interface javax.jcr.Session
      • getWorkspace

        public javax.jcr.Workspace getWorkspace()
        Specified by:
        getWorkspace in interface javax.jcr.Session
      • getRootNode

        public javax.jcr.Node getRootNode()
                                   throws javax.jcr.RepositoryException
        Specified by:
        getRootNode in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • impersonate

        public javax.jcr.Session impersonate​(javax.jcr.Credentials credentials)
                                      throws javax.jcr.RepositoryException
        Specified by:
        impersonate in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getNodeByUUID

        public javax.jcr.Node getNodeByUUID​(String uuid)
                                     throws javax.jcr.RepositoryException
        Specified by:
        getNodeByUUID in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getNodeByIdentifier

        public javax.jcr.Node getNodeByIdentifier​(String id)
                                           throws javax.jcr.RepositoryException
        Specified by:
        getNodeByIdentifier in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getItem

        public javax.jcr.Item getItem​(String absPath)
                               throws javax.jcr.RepositoryException
        Specified by:
        getItem in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getNode

        public javax.jcr.Node getNode​(String absPath)
                               throws javax.jcr.RepositoryException
        Specified by:
        getNode in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getProperty

        public javax.jcr.Property getProperty​(String absPath)
                                       throws javax.jcr.RepositoryException
        Specified by:
        getProperty in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • itemExists

        public boolean itemExists​(String absPath)
                           throws javax.jcr.RepositoryException
        Specified by:
        itemExists in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • nodeExists

        public boolean nodeExists​(String absPath)
                           throws javax.jcr.RepositoryException
        Specified by:
        nodeExists in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • propertyExists

        public boolean propertyExists​(String absPath)
                               throws javax.jcr.RepositoryException
        Specified by:
        propertyExists in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • move

        public void move​(String srcAbsPath,
                         String destAbsPath)
                  throws javax.jcr.RepositoryException
        Specified by:
        move in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • removeItem

        public void removeItem​(String absPath)
                        throws javax.jcr.RepositoryException
        Specified by:
        removeItem in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • save

        public void save()
                  throws javax.jcr.RepositoryException
        Specified by:
        save in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • refresh

        public void refresh​(boolean keepChanges)
                     throws javax.jcr.RepositoryException
        Specified by:
        refresh in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • hasPendingChanges

        public boolean hasPendingChanges()
                                  throws javax.jcr.RepositoryException
        Specified by:
        hasPendingChanges in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getValueFactory

        public javax.jcr.ValueFactory getValueFactory()
                                               throws javax.jcr.RepositoryException
        Specified by:
        getValueFactory in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • hasPermission

        public boolean hasPermission​(String absPath,
                                     String actions)
                              throws javax.jcr.RepositoryException
        Specified by:
        hasPermission in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • hasCapability

        public boolean hasCapability​(String methodName,
                                     Object target,
                                     Object[] arguments)
                              throws javax.jcr.RepositoryException
        Specified by:
        hasCapability in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getImportContentHandler

        public ContentHandler getImportContentHandler​(String parentAbsPath,
                                                      int uuidBehavior)
                                               throws javax.jcr.RepositoryException
        Specified by:
        getImportContentHandler in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • importXML

        public void importXML​(String parentAbsPath,
                              InputStream in,
                              int uuidBehavior)
                       throws IOException,
                              javax.jcr.RepositoryException
        Specified by:
        importXML in interface javax.jcr.Session
        Throws:
        IOException
        javax.jcr.RepositoryException
      • exportSystemView

        public void exportSystemView​(String absPath,
                                     ContentHandler contentHandler,
                                     boolean skipBinary,
                                     boolean noRecurse)
                              throws SAXException,
                                     javax.jcr.RepositoryException
        Specified by:
        exportSystemView in interface javax.jcr.Session
        Throws:
        SAXException
        javax.jcr.RepositoryException
      • exportSystemView

        public void exportSystemView​(String absPath,
                                     OutputStream out,
                                     boolean skipBinary,
                                     boolean noRecurse)
                              throws IOException,
                                     javax.jcr.RepositoryException
        Specified by:
        exportSystemView in interface javax.jcr.Session
        Throws:
        IOException
        javax.jcr.RepositoryException
      • exportDocumentView

        public void exportDocumentView​(String absPath,
                                       ContentHandler contentHandler,
                                       boolean skipBinary,
                                       boolean noRecurse)
                                throws SAXException,
                                       javax.jcr.RepositoryException
        Specified by:
        exportDocumentView in interface javax.jcr.Session
        Throws:
        SAXException
        javax.jcr.RepositoryException
      • exportDocumentView

        public void exportDocumentView​(String absPath,
                                       OutputStream out,
                                       boolean skipBinary,
                                       boolean noRecurse)
                                throws IOException,
                                       javax.jcr.RepositoryException
        Specified by:
        exportDocumentView in interface javax.jcr.Session
        Throws:
        IOException
        javax.jcr.RepositoryException
      • setNamespacePrefix

        public void setNamespacePrefix​(String prefix,
                                       String uri)
                                throws javax.jcr.RepositoryException
        Specified by:
        setNamespacePrefix in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getNamespacePrefixes

        public String[] getNamespacePrefixes()
                                      throws javax.jcr.RepositoryException
        Specified by:
        getNamespacePrefixes in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getNamespaceURI

        public String getNamespaceURI​(String prefix)
                               throws javax.jcr.RepositoryException
        Specified by:
        getNamespaceURI in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getNamespacePrefix

        public String getNamespacePrefix​(String uri)
                                  throws javax.jcr.RepositoryException
        Specified by:
        getNamespacePrefix in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • logout

        public void logout()
        Specified by:
        logout in interface javax.jcr.Session
      • isLive

        public boolean isLive()
        Specified by:
        isLive in interface javax.jcr.Session
      • addLockToken

        public void addLockToken​(String lt)
        Specified by:
        addLockToken in interface javax.jcr.Session
      • getLockTokens

        public String[] getLockTokens()
        Specified by:
        getLockTokens in interface javax.jcr.Session
      • removeLockToken

        public void removeLockToken​(String lt)
        Specified by:
        removeLockToken in interface javax.jcr.Session
      • getAccessControlManager

        public javax.jcr.security.AccessControlManager getAccessControlManager()
                                                                        throws javax.jcr.RepositoryException
        Specified by:
        getAccessControlManager in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException
      • getRetentionManager

        public javax.jcr.retention.RetentionManager getRetentionManager()
                                                                 throws javax.jcr.RepositoryException
        Specified by:
        getRetentionManager in interface javax.jcr.Session
        Throws:
        javax.jcr.RepositoryException