Package org.silverpeas.core.jcr
Class JCRSession
- java.lang.Object
-
- org.silverpeas.core.jcr.JCRSession
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,javax.jcr.Session
public class JCRSession extends Object implements javax.jcr.Session, Closeable
Implementation of theSession
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, anIllegalStateException
exception is thrown.- Author:
- mmoquillon
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLockToken(String lt)
void
checkPermission(String absPath, String actions)
void
close()
void
exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
void
exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
void
exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
void
exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse)
javax.jcr.security.AccessControlManager
getAccessControlManager()
Object
getAttribute(String name)
String[]
getAttributeNames()
ContentHandler
getImportContentHandler(String parentAbsPath, int uuidBehavior)
javax.jcr.Item
getItem(String absPath)
String[]
getLockTokens()
String
getNamespacePrefix(String uri)
String[]
getNamespacePrefixes()
String
getNamespaceURI(String prefix)
javax.jcr.Node
getNode(String absPath)
javax.jcr.Node
getNodeByIdentifier(String id)
javax.jcr.Node
getNodeByUUID(String uuid)
javax.jcr.Property
getProperty(String absPath)
javax.jcr.Repository
getRepository()
javax.jcr.retention.RetentionManager
getRetentionManager()
javax.jcr.Node
getRootNode()
String
getUserID()
The unique identifier of the user in Silverpeas who has opened this session.javax.jcr.ValueFactory
getValueFactory()
javax.jcr.Workspace
getWorkspace()
boolean
hasCapability(String methodName, Object target, Object[] arguments)
boolean
hasPendingChanges()
boolean
hasPermission(String absPath, String actions)
javax.jcr.Session
impersonate(javax.jcr.Credentials credentials)
void
importXML(String parentAbsPath, InputStream in, int uuidBehavior)
boolean
isLive()
boolean
itemExists(String absPath)
void
logout()
void
move(String srcAbsPath, String destAbsPath)
boolean
nodeExists(String absPath)
static JCRSession
openSystemSession()
Opens a session to the JCR for the system user (id est for Silverpeas with administrative rights).static JCRSession
openUserSession(String login, String domainId, String password)
Opens a session to the JCR for the specified user.boolean
propertyExists(String absPath)
void
refresh(boolean keepChanges)
void
removeItem(String absPath)
void
removeLockToken(String lt)
void
save()
void
setNamespacePrefix(String prefix, String uri)
-
-
-
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 anIllegalStateException
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 interfacejavax.jcr.Session
-
getUserID
public String getUserID()
The unique identifier of the user in Silverpeas who has opened this session.- Specified by:
getUserID
in interfacejavax.jcr.Session
- Returns:
- the user identifier
-
getAttributeNames
public String[] getAttributeNames()
- Specified by:
getAttributeNames
in interfacejavax.jcr.Session
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttribute
in interfacejavax.jcr.Session
-
getWorkspace
public javax.jcr.Workspace getWorkspace()
- Specified by:
getWorkspace
in interfacejavax.jcr.Session
-
getRootNode
public javax.jcr.Node getRootNode() throws javax.jcr.RepositoryException
- Specified by:
getRootNode
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
impersonate
public javax.jcr.Session impersonate(javax.jcr.Credentials credentials) throws javax.jcr.RepositoryException
- Specified by:
impersonate
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getNodeByUUID
public javax.jcr.Node getNodeByUUID(String uuid) throws javax.jcr.RepositoryException
- Specified by:
getNodeByUUID
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getNodeByIdentifier
public javax.jcr.Node getNodeByIdentifier(String id) throws javax.jcr.RepositoryException
- Specified by:
getNodeByIdentifier
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getItem
public javax.jcr.Item getItem(String absPath) throws javax.jcr.RepositoryException
- Specified by:
getItem
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getNode
public javax.jcr.Node getNode(String absPath) throws javax.jcr.RepositoryException
- Specified by:
getNode
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getProperty
public javax.jcr.Property getProperty(String absPath) throws javax.jcr.RepositoryException
- Specified by:
getProperty
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
itemExists
public boolean itemExists(String absPath) throws javax.jcr.RepositoryException
- Specified by:
itemExists
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
nodeExists
public boolean nodeExists(String absPath) throws javax.jcr.RepositoryException
- Specified by:
nodeExists
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
propertyExists
public boolean propertyExists(String absPath) throws javax.jcr.RepositoryException
- Specified by:
propertyExists
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
move
public void move(String srcAbsPath, String destAbsPath) throws javax.jcr.RepositoryException
- Specified by:
move
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
removeItem
public void removeItem(String absPath) throws javax.jcr.RepositoryException
- Specified by:
removeItem
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
save
public void save() throws javax.jcr.RepositoryException
- Specified by:
save
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
refresh
public void refresh(boolean keepChanges) throws javax.jcr.RepositoryException
- Specified by:
refresh
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
hasPendingChanges
public boolean hasPendingChanges() throws javax.jcr.RepositoryException
- Specified by:
hasPendingChanges
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getValueFactory
public javax.jcr.ValueFactory getValueFactory() throws javax.jcr.RepositoryException
- Specified by:
getValueFactory
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
hasPermission
public boolean hasPermission(String absPath, String actions) throws javax.jcr.RepositoryException
- Specified by:
hasPermission
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
checkPermission
public void checkPermission(String absPath, String actions) throws AccessControlException, javax.jcr.RepositoryException
- Specified by:
checkPermission
in interfacejavax.jcr.Session
- Throws:
AccessControlException
javax.jcr.RepositoryException
-
hasCapability
public boolean hasCapability(String methodName, Object target, Object[] arguments) throws javax.jcr.RepositoryException
- Specified by:
hasCapability
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getImportContentHandler
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws javax.jcr.RepositoryException
- Specified by:
getImportContentHandler
in interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.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 interfacejavax.jcr.Session
- Throws:
IOException
javax.jcr.RepositoryException
-
setNamespacePrefix
public void setNamespacePrefix(String prefix, String uri) throws javax.jcr.RepositoryException
- Specified by:
setNamespacePrefix
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getNamespacePrefixes
public String[] getNamespacePrefixes() throws javax.jcr.RepositoryException
- Specified by:
getNamespacePrefixes
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getNamespaceURI
public String getNamespaceURI(String prefix) throws javax.jcr.RepositoryException
- Specified by:
getNamespaceURI
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getNamespacePrefix
public String getNamespacePrefix(String uri) throws javax.jcr.RepositoryException
- Specified by:
getNamespacePrefix
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
logout
public void logout()
- Specified by:
logout
in interfacejavax.jcr.Session
-
isLive
public boolean isLive()
- Specified by:
isLive
in interfacejavax.jcr.Session
-
addLockToken
public void addLockToken(String lt)
- Specified by:
addLockToken
in interfacejavax.jcr.Session
-
getLockTokens
public String[] getLockTokens()
- Specified by:
getLockTokens
in interfacejavax.jcr.Session
-
removeLockToken
public void removeLockToken(String lt)
- Specified by:
removeLockToken
in interfacejavax.jcr.Session
-
getAccessControlManager
public javax.jcr.security.AccessControlManager getAccessControlManager() throws javax.jcr.RepositoryException
- Specified by:
getAccessControlManager
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
getRetentionManager
public javax.jcr.retention.RetentionManager getRetentionManager() throws javax.jcr.RepositoryException
- Specified by:
getRetentionManager
in interfacejavax.jcr.Session
- Throws:
javax.jcr.RepositoryException
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-