The following are the methods of Session associated with accessing information about a repository and for accessing content from this Session's workspace. Session has other methods as well. In a level 1-only implementation, these other methods will either do nothing or throw an exception. See and 7.1 Writing Repository Content.
The most important methods exposed by Session are those that provide access to the Items in the workspace tree: typically the user would begin by calling Session.getRootNode(), which returns the root node of the workspace. From this the user can traverse the workspace tree. It is also possible to directly access a node in the workspace with Session.getNodeByUUID or Session.getItem.
javax.jcr. |
|
Repository |
getRepository() Returns the Repository object through which this Session was acquired. |
String |
getUserID() Gets the user ID associated with this Session. How the user ID is set is up to the implementation, it may be a string passed in as part of the credentials or it may be a string acquired in some other way. This method is free to return an “anonymous user ID” or null. |
String[] |
getAttributeNames() Returns the names of the attributes set in this session as a result of the Credentials that were used to acquire it. Not all Credentials implementations will contain attributes (though, for example, SimpleCredentials does allow for them). This method returns an empty array if the Credentials instance did not provide attributes. |
Object |
getAttribute(String name) Returns the value of the named attribute as an Object, or null if no attribute of the given name exists. See Session.getAttributeNames, above. |
Workspace |
getWorkspace() Returns the Workspace attached to this Session. |
Node |
getRootNode() Returns the root node of the workspace, /. This node is the main access point to the content of the workspace. A RepositoryException is thrown if an error occurs. |
Item |
getItem(String absPath) Returns the item at the specified absolute path in the workspace. A PathNotFoundException is thrown if no item at absPath exists. A RepositoryException is thrown if another error occurs. |
boolean |
itemExists(String absPath) Returns true if an item exists at absPath and this Session has read access to it; otherwise returns false. Also returns false if the specified absPath is malformed. A RepositoryException is thrown if an error occurs. |
Node |
getNodeByUUID(String uuid) Returns the node specified by the given UUID. Only applies to nodes that expose a UUID, in other words, those of mixin node type mix:referenceable. An ItemNotFoundException is thrown if no item with the specified UUID exists. A RepositoryException is thrown if another error occurs. |
Session |
impersonate(Credentials c) Returns a new Session in accordance with the specified (new) Credentials. Allows the current user to “impersonate” another using incomplete or relaxed credentials requirements (perhaps including a user name but no password, for example), assuming that this Session gives them that permission. The new Session is tied to a new Workspace instance. In other words, Workspace instances are not re-used. However, the Workspace instance returned represents the same actual persistent workspace entity in the repository as is represented by the Workspace object tied to this Session. A LoginException is thrown if this session does not have sufficient permissions to perform the operation. A RepositoryException is thrown if another error occurs. |
void |
logout() Releases all resources associated with this Session. This method should be called when a Session is no longer needed. |
boolean |
isLive() Returns true if this Session object is usable by the client. A usable Session object is one that is neither logged-out, timed-out nor in any other way disconnected from the repository. |