phpcr/src/PHPCR/WorkspaceInterface.php
Copyright 2008-2011 Karsten Dambekalns karsten@typo3.org
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
\PHPCR\WorkspaceInterface
A Workspace object represents a view onto a persistent workspace within a repository. This view is defined by the authorization settings of the Session object associated with the Workspace object. Each Workspace object is associated one-to-one with a Session object. The Workspace object can be acquired by calling $session->getWorkspace() on the associated Session object.
- Api
Constants
NAME_SYSTEM_NODE
= '{http://www.jcp.org/jcr/1.0}system'
- Api
PATH_SYSTEM_NODE
= '/{http://www.jcp.org/jcr/1.0}system'
This is '/' . NAME_SYSTEM_NODE
- Api
NAME_NODE_TYPES_NODE
= '{http://www.jcp.org/jcr/1.0}nodeTypes'
- Api
PATH_NODE_TYPES_NODE
= '/{http://www.jcp.org/jcr/1.0}system/{http://www.jcp.org/jcr/1.0}nodeTypes'
This is PATH_SYSTEM_NODE . '/' . NAME_NODE_TYPES_NODE
- Api
NAME_VERSION_STORAGE_NODE
= '{http://www.jcp.org/jcr/1.0}versionStorage'
- Api
PATH_VERSION_STORAGE_NODE
= '/{http://www.jcp.org/jcr/1.0}system/{http://www.jcp.org/jcr/1.0}versionStorage'
This is PATH_SYSTEM_NODE . '/' . NAME_VERSION_STORAGE_NODE
- Api
NAME_ACTIVITIES_NODE
= '{http://www.jcp.org/jcr/1.0}activities'
- Api
PATH_ACTIVITIES_NODE
= '/{http://www.jcp.org/jcr/1.0}system/{http://www.jcp.org/jcr/1.0}activities'
This is PATH_SYSTEM_NODE . '/' . NAME_ACTIVITIES_NODE
- Api
NAME_CONFIGURATIONS_NODE
= '{http://www.jcp.org/jcr/1.0}configurations'
- Api
PATH_CONFIGURATIONS_NODE
= '/{http://www.jcp.org/jcr/1.0}system/{http://www.jcp.org/jcr/1.0}configurations'
This is PATH_SYSTEM_NODE . '/' . NAME_CONFIGURATIONS_NODE
- Api
NAME_UNFILED_NODE
= '{http://www.jcp.org/jcr/1.0}unfiled'
- Api
PATH_UNFILED_NODE
= '/{http://www.jcp.org/jcr/1.0}system/{http://www.jcp.org/jcr/1.0}unfiled'
This is PATH_SYSTEM_NODE . '/' . NAME_UNFILED_NODE
- Api
NAME_JCR_XMLTEXT
= '{http://www.jcp.org/jcr/1.0}xmltext'
- Api
NAME_JCR_XMLCHARACTERS
= '{http://www.jcp.org/jcr/1.0}xmlcharacters'
- Api
RELPATH_JCR_XMLCHARACTERS
= '{http://www.jcp.org/jcr/1.0}xmltext/{http://www.jcp.org/jcr/1.0}xmlcharacters'
This is NAME_JCR_XMLTEXT . '/' . NAME_JCR_XMLCHARACTERS
- Api
Methods
cloneFrom(string $srcWorkspace, string $srcAbsPath, string $destAbsPath, boolean $removeExisting) : void
Clones the subgraph at the node srcAbsPath in srcWorkspace to the new location at destAbsPath in the current workspace.
Unlike the signature of copy that copies between workspaces, this method does not assign new identifiers to the newly cloned nodes but preserves the identifiers of their respective source nodes. This applies to both referenceable and non-referenceable nodes.
In some implementations there may be cases where preservation of a non-referenceable identifier is not possible, due to how non-referenceable identifiers are constructed in that implementation. In such a case this method will throw a RepositoryException.
If removeExisting is true and an existing node in this workspace (the destination workspace) has the same identifier as a node being cloned from srcWorkspace, then the incoming node takes precedence, and the existing node (and its subgraph) is removed. If removeExisting is false then an identifier collision causes this method to throw an ItemExistsException and no changes are made.
If successful, the change is persisted immediately, there is no need to call save.
The destAbsPath provided must not have an index on its final element. If it does then a RepositoryException is thrown. If ordering is supported by the node type of the parent node of the new location, then the new clone of the node is appended to the end of the child node list.
This method cannot be used to clone just an individual property; it clones a node and its subgraph.
PHP Notice: The JCR method is called clone, but that is a reserved keyword in PHP, thus we named the method cloneFrom.
Name | Type | Description |
---|---|---|
$srcWorkspace | string | The name of the workspace from which the node is to be copied. |
$srcAbsPath | string | The path of the node to be copied in srcWorkspace. |
$destAbsPath | string | The location to which the node at srcAbsPath is to be copied in this workspace. |
$removeExisting | boolean | if false then this method throws an ItemExistsException on identifier conflict with an incoming node. If true then a identifier conflict is resolved by removing the existing node from its location in this workspace and cloning (copying in) the one from srcWorkspace. |
Exception | Description |
---|---|
\PHPCR\NoSuchWorkspaceException | if destWorkspace does not exist. |
\PHPCR\NodeType\ConstraintViolationException | if the operation would violate a node-type or other implementation-specific constraint. |
\PHPCR\Version\VersionException | if the parent node of destAbsPath is read-only due to a checked-in node. This exception will also be thrown if removeExisting is true, and an identifier conflict occurs that would require the moving and/or altering of a node that is checked-in. |
\PHPCR\AccessDeniedException | if the current session does not have sufficient access to complete the operation. |
\PHPCR\PathNotFoundException | if the node at srcAbsPath in srcWorkspace or the parent of destAbsPath in this workspace does not exist. |
\PHPCR\ItemExistsException | if a node already exists at destAbsPath and same-name siblings are not allowed or if removeExisting is false and an identifier conflict occurs. |
\PHPCR\Lock\LockException | if a lock prevents the clone. |
\PHPCR\RepositoryException | if the last element of destAbsPath has an index or if another error occurs. |
- Api
copy(string $srcAbsPath, string $destAbsPath, string $srcWorkspace = null) : void
Copies a Node including its children to a new location to the given workspace.
This method copies the subgraph rooted at, and including, the node at $srcWorkspace (if given) and $srcAbsPath to the new location in this Workspace at $destAbsPath.
This is a workspace-write operation and therefore dispatches changes immediately and does not require a save.
When a node N is copied to a path location where no node currently exists, a new node N' is created at that location. The subgraph rooted at and including N' (call it S') is created and is identical to the subgraph rooted at and including N (call it S) with the following exceptions: - Every node in S' is given a new and distinct identifier - or, if $srcWorkspace is given - Every referenceable node in S' is given a new and distinct identifier while every non-referenceable node in S' may be given a new and distinct identifier. - The repository may automatically drop any mixin node type T present on any node M in S. Dropping a mixin node type in this context means that while M remains unchanged, its copy M' will lack the mixin T and any child nodes and properties defined by T that are present on M. For example, a node M that is mix:versionable may be copied such that the resulting node M' will be a copy of N except that M' will not be mix:versionable and will not have any of the properties defined by mix:versionable. In order for a mixin node type to be dropped it must be listed by name in the jcr:mixinTypes property of M. The resulting jcr:mixinTypes property of M' will reflect any change. - If a node M in S is referenceable and its mix:referenceable mixin is not dropped on copy, then the resulting jcr:uuid property of M' will reflect the new identifier assigned to M'. - Each REFERENCE or WEAKEREFERENCE property R in S is copied to its new location R' in S'. If R references a node M within S then the value of R' will be the identifier of M', the new copy of M, thus preserving the reference within the subgraph.
When a node N is copied to a location where a node N' already exists, the repository may either immediately throw an ItemExistsException or attempt to update the node N' by selectively replacing part of its subgraph with a copy of the relevant part of the subgraph of N. If the node types of N and N' are compatible, the implementation supports update-on-copy for these node types and no other errors occur, then the copy will succeed. Otherwise an ItemExistsException is thrown.
Which node types can be updated on copy and the details of any such updates are implementation-dependent. For example, some implementations may support update-on-copy for mix:versionable nodes. In such a case the versioning-related properties of the target node would remain unchanged (jcr:uuid, jcr:versionHistory, etc.) while the substantive content part of the subgraph would be replaced with that of the source node.
The $destAbsPath provided must not have an index on its final element. If it does then a RepositoryException is thrown. Strictly speaking, the $destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the copied node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the new copy of the node is appended to the end of the child node list.
This method cannot be used to copy an individual property by itself. It copies an entire node and its subgraph (including, of course, any properties contained therein).
Name | Type | Description |
---|---|---|
$srcAbsPath | string | the path of the node to be copied. |
$destAbsPath | string | the location to which the node at srcAbsPath is to be copied in this workspace. |
$srcWorkspace | string | the name of the workspace from which the copy is to be made. |
Exception | Description |
---|---|
\PHPCR\NoSuchWorkspaceException | if srcWorkspace does not exist or if the current Session does not have permission to access it. |
\PHPCR\NodeType\ConstraintViolationException | if the operation would violate a node-type or other implementation-specific constraint. |
\PHPCR\Version\VersionException | if the parent node of destAbsPath is read-only due to a checked-in node. |
\PHPCR\AccessDeniedException | if the current session does have access srcWorkspace but otherwise does not have sufficient access to complete the operation. |
\PHPCR\PathNotFoundException | if the node at srcAbsPath in srcWorkspace or the parent of destAbsPath in this workspace does not exist. |
\PHPCR\ItemExistsException | if a node already exists at destAbsPath and either same-name siblings are not allowed or update on copy is not supported for the nodes involved. |
\PHPCR\Lock\LockException | if a lock prevents the copy. |
\PHPCR\RepositoryException | if the last element of destAbsPath has an index or if another error occurs. |
- Api
createWorkspace(string $name, string $srcWorkspace = null) : void
Creates a new Workspace with the specified name.
The new workspace is empty, meaning it contains only root node.
If srcWorkspace is given:<br/> Creates a new Workspace with the specified name initialized with a clone of the content of the workspace srcWorkspace. Semantically, this method is equivalent to creating a new workspace and manually cloning srcWorkspace to it; however, this method may assist some implementations in optimizing subsequent NodeInterface::update() and NodeInterface::merge() calls between the new workspace and its source.
The new workspace can be accessed through a login specifying its name.
Name | Type | Description |
---|---|---|
$name | string | A String, the name of the new workspace. |
$srcWorkspace | string | The name of the workspace from which the new workspace is to be cloned. |
Exception | Description |
---|---|
\PHPCR\AccessDeniedException | if the session through which this Workspace object was acquired does not have sufficient access to create the new workspace. |
\PHPCR\UnsupportedRepositoryOperationException | if the repository does not support the creation of workspaces. |
\PHPCR\NoSuchWorkspaceException | if $srcWorkspace does not exist. |
\PHPCR\RepositoryException | if another error occurs. |
- Api
deleteWorkspace(string $name) : void
Deletes the workspace with the specified name from the repository, deleting all content within it.
Name | Type | Description |
---|---|---|
$name | string | A String, the name of the workspace to be deleted. |
Exception | Description |
---|---|
\PHPCR\AccessDeniedException | if the session through which this Workspace object was acquired does not have sufficient access to remove the workspace. |
\PHPCR\UnsupportedRepositoryOperationException | if the repository does not support the removal of workspaces. |
\PHPCR\NoSuchWorkspaceException | if $name does not exist. |
\PHPCR\RepositoryException | if another error occurs. |
- Api
getAccessibleWorkspaceNames() : array
Gets a set of workspace accessible to the current user.
Returns a string array containing the names of all workspaces in this repository that are accessible to this user, given the Credentials that were used to get the Session to which this Workspace is tied. In order to access one of the listed workspaces, the user performs another RepositoryInterface::login(), specifying the name of the desired workspace, and receives a new Session object.
Type | Description |
---|---|
array | string array of names of accessible workspaces. |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs |
- Api
getLockManager() : \PHPCR\Lock\LockManagerInterface
Returns the LockManager object, through which locking methods are accessed.
Type | Description |
---|---|
\PHPCR\Lock\LockManagerInterface |
Exception | Description |
---|---|
\PHPCR\UnsupportedRepositoryOperationException | if the implementation does not support locking. |
\PHPCR\RepositoryException | if an error occurs. |
- Api
getName() : string
Returns the name of the actual persistent workspace represented by this Workspace object.
This the name used in Repository->login.
Type | Description |
---|---|
string | the name of this workspace. |
- Api
getNamespaceRegistry() : \PHPCR\NamespaceRegistryInterface
Returns the NamespaceRegistry object, which is used to access the mapping between prefixes and namespaces.
In level 2 repositories the NamespaceRegistry can also be used to change the namespace mappings.
Type | Description |
---|---|
\PHPCR\NamespaceRegistryInterface | the NamespaceRegistry. |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs. |
- Api
getNodeTypeManager() : \PHPCR\NodeType\NodeTypeManagerInterface
Returns the NodeTypeManager through which node type information can be queried.
There is one node type registry per repository, therefore the NodeTypeManager is not workspace-specific; it provides introspection methods for the global, repository-wide set of available node types. In repositories that support it, the NodeTypeManager can also be used to register new node types.
Type | Description |
---|---|
\PHPCR\NodeType\NodeTypeManagerInterface | a NodeTypeManager object. |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs. |
- Api
getObservationManager() : \PHPCR\Observation\ObservationManagerInterface
Returns the ObservationManager object.
Type | Description |
---|---|
\PHPCR\Observation\ObservationManagerInterface | an ObservationManager object. |
Exception | Description |
---|---|
\PHPCR\UnsupportedRepositoryOperationException | if the implementation does not support observation. |
\PHPCR\RepositoryException | if an error occurs. |
- Api
getQueryManager() : \PHPCR\Query\QueryManagerInterface
Returns the QueryManager object, through search methods are accessed.
Type | Description |
---|---|
\PHPCR\Query\QueryManagerInterface | the QueryManager object. |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs. |
- Api
getRepositoryManager() : \PHPCR\RepositoryManagerInterface
Return a RepositoryManager that can be used to administer the repository instance through which this workspace's session was acquired.
Type | Description |
---|---|
\PHPCR\RepositoryManagerInterface |
Exception | Description |
---|---|
\PHPCR\AccessDeniedException | if the caller does not have authorization to obtain the manager. |
\PHPCR\RepositoryException | if another error occurred. |
- Since
- JCR 2.1
getSession() : \PHPCR\SessionInterface
Returns the Session object through which this Workspace object was acquired.
Type | Description |
---|---|
\PHPCR\SessionInterface | a Session object. |
- Api
getTransactionManager() : \PHPCR\Transaction\UserTransactionInterface
Returns the UserTransaction object associated with this session
Type | Description |
---|---|
\PHPCR\Transaction\UserTransactionInterface | a UserTransaction object. |
Exception | Description |
---|---|
\PHPCR\UnsupportedRepositoryOperationException | if the implementation does not support observation. |
- Api
getVersionManager() : \PHPCR\Version\VersionManagerInterface
Returns the VersionManager object.
Type | Description |
---|---|
\PHPCR\Version\VersionManagerInterface | a VersionManager object. |
Exception | Description |
---|---|
\PHPCR\UnsupportedRepositoryOperationException | if the implementation does not support versioning. |
\PHPCR\RepositoryException | if an error occurs. |
- Api
importXML(string $parentAbsPath, string $uri, integer $uuidBehavior) : void
Deserializes an XML document and adds the resulting item subgraph as a child of the node at $parentAbsPath.
If the incoming XML does not appear to be a JCR system view XML document then it is interpreted as a document view XML document.
Changes are made directly at the workspace level, without going through the Session. As a result, there is not need to call save. The advantage of this direct-to-workspace method is that a large import will not result in a large cache of pending nodes in the Session. The disadvantage is that invalid data cannot be imported, fixed and then saved. Instead, invalid data will cause this method to throw an InvalidSerializedDataException. See SessionInterface::importXML() for a version of this method that does go through the Session.
The flag $uuidBehavior governs how the identifiers of incoming (deserialized) nodes are handled. There are four options:
- ImportUUIDBehavior::IMPORT_UUID_CREATE_NEW: Incoming nodes are assigned newly created identifiers upon addition to the workspace. As a result identifier collisions never occur.
- ImportUUIDBehavior::IMPORT_UUID_COLLISION_REMOVE_EXISTING: If an incoming node has the same identifier as a node already existing in the workspace then the already existing node (and its subgraph) is removed from wherever it may be in the workspace before the incoming node is added. Note that this can result in nodes "disappearing" from locations in the workspace that are remote from the location to which the incoming subgraph is being written. If an incoming node has the same identifier as the existing root node of this workspace then
- ImportUUIDBehavior::IMPORT_UUID_COLLISION_REPLACE_EXISTING: If an incoming node has the same identifier as a node already existing in the workspace then the already existing node is replaced by the incoming node in the same position as the existing node. Note that this may result in the incoming subgraph being disaggregated and "spread around" to different locations in the workspace. In the most extreme edge case this behavior may result in no node at all being added as child of parentAbsPath. This will occur if the topmost element of the incoming XML has the same identifier as an existing node elsewhere in the workspace.
- ImportUUIDBehavior::IMPORT_UUID_COLLISION_THROW: If an incoming node has the same identifier as a node already existing in the workspace then an ItemExistsException is thrown.
Name | Type | Description |
---|---|---|
$parentAbsPath | string | the absolute path of the node below which the deserialized subgraph is added. |
$uri | string | Source location for the XML to be read, Can be anything that works with fopen. |
$uuidBehavior | integer | a four-value flag that governs how incoming identifiers are handled. |
Exception | Description |
---|---|
\RuntimeException | if an error during an I/O operation occurs. |
\PHPCR\PathNotFoundException | if no node exists at parentAbsPath. |
\PHPCR\NodeType\ConstraintViolationException | if node-type or other implementation-specific constraints prevent the addition of the subgraph or if uuidBehavior is set to IMPORT_UUID_COLLISION_REMOVE_EXISTING and an incoming node has the same identifier as the node at parentAbsPath or one of its ancestors. |
\PHPCR\Version\VersionException | if the node at parentAbsPath is read-only due to a checked-in node. |
\PHPCR\InvalidSerializedDataException | if incoming stream is not a valid XML document. |
\PHPCR\ItemExistsException | if the top-most element of the incoming XML would deserialize to a node with the same name as an existing child of parentAbsPath and that child does not allow same-name siblings, or if a uuidBehavior is set to IMPORT_UUID_COLLISION_THROW and an identifier collision occurs. |
\PHPCR\Lock\LockException | if a lock prevents the addition of the subgraph. |
\PHPCR\AccessDeniedException | if the session associated with this Workspace object does not have sufficient access to perform the import. |
\PHPCR\RepositoryException | if another error occurs. |
- Api
move(string $srcAbsPath, string $destAbsPath) : void
Moves the node at srcAbsPath (and its entire subgraph) to the new location at destAbsPath.
If successful, the change is persisted immediately, there is no need to call save. Note that this is in contrast to Session->move($srcAbsPath, $destAbsPath) which operates within the transient space and hence requires a save.
The identifiers of referenceable nodes must not be changed by a move. The identifiers of non-referenceable nodes may change.
The destAbsPath provided must not have an index on its final element. If it does then a RepositoryException is thrown. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the moved node. It does not specify a position within the child node ordering. If ordering is supported by the node type of the parent node of the new location, then the newly moved node is appended to the end of the child node list.
This method cannot be used to move just an individual property by itself. It moves an entire node and its subgraph (including, of course, any properties contained therein).
The identifiers of referenceable nodes must not be changed by a move. The identifiers of non-referenceable nodes may change.
Name | Type | Description |
---|---|---|
$srcAbsPath | string | the path of the node to be moved. |
$destAbsPath | string | the location to which the node at srcAbsPath is to be moved. |
Exception | Description |
---|---|
\PHPCR\NodeType\ConstraintViolationException | if the operation would violate a node-type or other implementation-specific constraint. |
\PHPCR\Version\VersionException | if the parent node of destAbsPath is read-only due to a checked-in node. |
\PHPCR\AccessDeniedException | if the current session (i.e. the session that was used to acquire this Workspace object) does not have sufficient access rights to complete the operation. |
\PHPCR\PathNotFoundException | if the node at srcAbsPath or the parent of destAbsPath does not exist. |
\PHPCR\ItemExistsException | if a node already exists at destAbsPath and same-name siblings are not allowed. |
\PHPCR\Lock\LockException | if a lock prevents the move. |
\PHPCR\RepositoryException | if the last element of destAbsPath has an index or if another error occurs. |
- Api
removeItem(string $absPath) : void
Removes the specified item and its subgraph.
This is a workspace-write method and therefore is dispatched immediately. A save is not required. In the absence of a transaction, the changes made by this method will also be persisted immediately. In the presence of a transaction the changes will be persisted upon commit of the transaction.
If a node with same-name siblings is removed, this decrements by one the indices of all the siblings with indices greater than that of the removed node. In other words, a removal compacts the array of same-name siblings and causes the minimal re-numbering required to maintain the original order but leave no gaps in the numbering.
A ReferentialIntegrityException will be thrown if the specified item or an item in its subgraph is currently the target of a REFERENCE property located in this workspace but outside the specified item's subgraph and the current Session has read access to that REFERENCE property.
A ConstraintViolationException will be thrown either on dispatch or on persist, if removing the specified item would violate a node type or implementation-specific constraint. Implementations may differ on when this validation is performed.
A VersionException will be thrown either on dispatch or on persist, if the parent node of the specified item is read-only due to a checked-in node. Implementations may differ on when this validation is performed.
A LockException will be thrown either on dispatch or on persist, if a lock prevents the removal of the specified item. Implementations may differ on when this validation is performed.
A PathNotFoundException will be thrown either on dispatch or on persist, if no accessible item is found at at $absPath.
A AccessDeniedException will be thrown either on dispatch or on persist, if the specified item or an item in its subgraph is currently the target of a REFERENCE property located in this workspace but outside the specified item's subgraph and the current Session does not have read access to that REFERENCE property.
Name | Type | Description |
---|---|---|
$absPath | string | the absolute path of the item to be removed. |
Exception | Description |
---|---|
\PHPCR\Version\VersionException | if the parent node of the item at $absPath is read-only due to a checked-in node and this implementation performs this validation immediately. |
\PHPCR\Lock\LockException | if a lock prevents the removal of the specified item and this implementation performs this validation immediately. |
\PHPCR\NodeType\ConstraintViolationException | if removing the specified item would violate a node type or implementation-specific constraint and this implementation performs this validation immediately. |
\PHPCR\PathNotFoundException | if no accessible item is found at $absPath and this implementation performs this validation immediately. |
\PHPCR\AccessDeniedException | if the specified item or an item in its subgraph is currently the target of a REFERENCE property located in this workspace but outside the specified item's subgraph and the current Session does not have read access to that REFERENCE property and this implementation performs this validation immediately. |
\PHPCR\RepositoryException | if another error occurs. |
- Api
- See
- \PHPCR\Session::removeItem()
- Since
- JCR 2.1