Package org.apache.jackrabbit.commons
Class AbstractSession
- java.lang.Object
-
- org.apache.jackrabbit.commons.AbstractSession
-
- All Implemented Interfaces:
Session
- Direct Known Subclasses:
SessionImpl
,SessionImpl
public abstract class AbstractSession extends Object implements Session
Abstract base class for implementing the JCRSession
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(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
CallsSession.exportDocumentView(String, ContentHandler, boolean, boolean)
with the given arguments and aContentHandler
that serializes SAX events to the given output stream.void
exportDocumentView(String path, ContentHandler handler, boolean skipBinary, boolean noRecurse)
Generates a document view export using aDocumentViewExporter
instance.void
exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse)
CallsSession.exportSystemView(String, ContentHandler, boolean, boolean)
with the given arguments and aContentHandler
that serializes SAX events to the given output stream.void
exportSystemView(String path, ContentHandler handler, boolean skipBinary, boolean noRecurse)
Generates a system view export using aSystemViewExporter
instance.Item
getItem(String absPath)
Returns the node or property at the given path.String
getNamespacePrefix(String uri)
Returns the namespace prefix mapped to the given URI.String[]
getNamespacePrefixes()
Returns the prefixes of all known namespace mappings.String
getNamespaceURI(String prefix)
Returns the namespace URI mapped to the given prefix.Node
getNode(String absPath)
Returns the node with the given absolute path.Property
getProperty(String absPath)
Returns the property with the given absolute path.Session
impersonate(Credentials credentials)
Logs in the same workspace with the given credentials.void
importXML(String parentAbsPath, InputStream in, int uuidBehavior)
Parses the given input stream as an XML document and processes the SAX events using theContentHandler
returned bySession.getImportContentHandler(String, int)
.boolean
itemExists(String absPath)
CallsgetItem(String)
with the given path and returnstrue
if the call succeeds.void
logout()
Clears the local namespace mappings.boolean
nodeExists(String absPath)
Checks whether a node with the given absolute path exists.boolean
propertyExists(String absPath)
Checks whether a property with the given absolute path exists.void
removeItem(String absPath)
Removes the identified item.void
setNamespacePrefix(String prefix, String uri)
Modifies the session local namespace mappings to contain the given prefix to URI mapping.-
Methods inherited from class java.lang.Object
clone, equals, finalize, 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
-
-
-
-
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 callsuper.logout()
when overriding this method to avoid namespace mappings to be carried over to a new session.
-
getNamespacePrefix
public String getNamespacePrefix(String uri) throws NamespaceException, 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 interfaceSession
- Parameters:
uri
- namespace URI- Returns:
- namespace prefix
- Throws:
NamespaceException
- if the namespace is not foundRepositoryException
- if a repository error occurs
-
getNamespaceURI
public String getNamespaceURI(String prefix) throws NamespaceException, 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 interfaceSession
- Parameters:
prefix
- namespace prefix- Returns:
- namespace URI
- Throws:
NamespaceException
- if the namespace is not foundRepositoryException
- if a repository error occurs
-
getNamespacePrefixes
public String[] getNamespacePrefixes() throws 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 interfaceSession
- Returns:
- namespace prefixes
- Throws:
RepositoryException
- if a repository error occurs
-
setNamespacePrefix
public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, 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 interfaceSession
- Parameters:
prefix
- namespace prefixuri
- namespace URI- Throws:
NamespaceException
- if the mapping is illegalRepositoryException
- if a repository error occurs
-
exportDocumentView
public void exportDocumentView(String path, ContentHandler handler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException
Generates a document view export using aDocumentViewExporter
instance.- Specified by:
exportDocumentView
in interfaceSession
- Parameters:
path
- of the node to be exportedhandler
- handler for the SAX events of the exportskipBinary
- whether binary values should be skippednoRecurse
- whether to export just the identified node- Throws:
PathNotFoundException
- if a node at the given path does not existSAXException
- if the SAX event handler failedRepositoryException
- if another error occurs
-
exportSystemView
public void exportSystemView(String path, ContentHandler handler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException
Generates a system view export using aSystemViewExporter
instance.- Specified by:
exportSystemView
in interfaceSession
- Parameters:
path
- of the node to be exportedhandler
- handler for the SAX events of the exportskipBinary
- whether binary values should be skippednoRecurse
- whether to export just the identified node- Throws:
PathNotFoundException
- if a node at the given path does not existSAXException
- if the SAX event handler failedRepositoryException
- if another error occurs
-
exportDocumentView
public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, RepositoryException
CallsSession.exportDocumentView(String, ContentHandler, boolean, boolean)
with the given arguments and aContentHandler
that serializes SAX events to the given output stream.- Specified by:
exportDocumentView
in interfaceSession
- Parameters:
absPath
- passed throughout
- output stream to which the SAX events are serializedskipBinary
- passed throughnoRecurse
- passed through- Throws:
IOException
- if the SAX serialization failedRepositoryException
- if another error occurs
-
exportSystemView
public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, RepositoryException
CallsSession.exportSystemView(String, ContentHandler, boolean, boolean)
with the given arguments and aContentHandler
that serializes SAX events to the given output stream.- Specified by:
exportSystemView
in interfaceSession
- Parameters:
absPath
- passed throughout
- output stream to which the SAX events are serializedskipBinary
- passed throughnoRecurse
- passed through- Throws:
IOException
- if the SAX serialization failedRepositoryException
- if another error occurs
-
importXML
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, InvalidSerializedDataException, RepositoryException
Parses the given input stream as an XML document and processes the SAX events using theContentHandler
returned bySession.getImportContentHandler(String, int)
.- Specified by:
importXML
in interfaceSession
- Parameters:
parentAbsPath
- passed throughin
- input stream to be parsed as XML and importeduuidBehavior
- passed through- Throws:
IOException
- if an I/O error occursInvalidSerializedDataException
- if an XML parsing error occursRepositoryException
- if a repository error occurs
-
getItem
public Item getItem(String absPath) throws PathNotFoundException, 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 aPathNotFoundException
- Specified by:
getItem
in interfaceSession
- Parameters:
absPath
- absolute path- Returns:
- the node or property with the given path
- Throws:
PathNotFoundException
- if the given path is invalid or not foundRepositoryException
- if another error occurs- See Also:
Session.getItem(String)
-
itemExists
public boolean itemExists(String absPath) throws RepositoryException
CallsgetItem(String)
with the given path and returnstrue
if the call succeeds. Returnsfalse
if aPathNotFoundException
was thrown. Other exceptions are passed through.- Specified by:
itemExists
in interfaceSession
- Parameters:
absPath
- absolute path- Returns:
true
if an item exists at the given path,false
otherwise- Throws:
RepositoryException
- if an error occurs- See Also:
Session.itemExists(String)
-
removeItem
public void removeItem(String absPath) throws RepositoryException
Removes the identified item. Implemented by callingItem.remove()
on the item removed bygetItem(String)
.- Specified by:
removeItem
in interfaceSession
- Parameters:
absPath
- An absolute path of the item to be removed- Throws:
RepositoryException
- if the item can not be removed- See Also:
Session.removeItem(String)
-
getNode
public Node getNode(String absPath) throws RepositoryException
Returns the node with the given absolute path.- Specified by:
getNode
in interfaceSession
- Parameters:
absPath
- absolute path- Returns:
- node at the given path
- Throws:
RepositoryException
- if the node can not be accessed- See Also:
Session.getNode(String)
-
nodeExists
public boolean nodeExists(String absPath) throws RepositoryException
Checks whether a node with the given absolute path exists.- Specified by:
nodeExists
in interfaceSession
- Parameters:
absPath
- absolute path- Returns:
true
if a node with the given path exists,false
otherwise- Throws:
RepositoryException
- if the path is invalid- See Also:
Session.nodeExists(String)
-
getProperty
public Property getProperty(String absPath) throws RepositoryException
Returns the property with the given absolute path.- Specified by:
getProperty
in interfaceSession
- Parameters:
absPath
- absolute path- Returns:
- node at the given path
- Throws:
RepositoryException
- if the property can not be accessed- See Also:
Session.getProperty(String)
-
propertyExists
public boolean propertyExists(String absPath) throws RepositoryException
Checks whether a property with the given absolute path exists.- Specified by:
propertyExists
in interfaceSession
- Parameters:
absPath
- absolute path- Returns:
true
if a property with the given path exists,false
otherwise- Throws:
RepositoryException
- if the path is invalid- See Also:
Session.propertyExists(String)
-
impersonate
public Session impersonate(Credentials credentials) throws RepositoryException
Logs in the same workspace with the given credentials.The default implementation:
- Retrieves the
Repository
instance usingSession.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 interfaceSession
- Parameters:
credentials
- login credentials- Returns:
- logged in session
- Throws:
RepositoryException
- if an error occurs
- Retrieves the
-
-