Movatterモバイル変換


[0]ホーム

URL:


7.3.6 Workspace Import Methods

TheWorkspace interface provides the following methods for importing content into the repository:

javax.jcr.
Workspace

ContentHandler

getImportContentHandler(
String parentAbsPath,
int uuidBehavior)

Returns anorg.xml.sax.ContentHandler which can be used to push SAX events into the repository. If the incoming XML stream (in the form of SAX events) does not appear to be asystem view XML document then it is interpreted as adocument view XML document.

The incoming XML is deserialized into a subtree of items immediately below the node atparentAbsPath.

This method simply returns theContentHandler without altering the state of the repository; the actual deserialization is done through the methods of theContentHandler. Invalid XML data will cause theContentHandler to throw aSAXException.

As SAX events are fed into theContentHandler, changes are made directly at the workspace level, without going through theSession. As a result, there is not need to callsave. The advantage of this direct-to-workspace method is that a large import will not result in a large cache of pending nodes in theSession. The disadvantage is that structures that violate node type constraints cannot be imported, fixed and then saved. Instead, a constraint violation will cause theContentHandler to throw aSAXException. SeeSession.getImportContentHandler for a version of this method thatdoes go through theSession.

The flaguuidBehavior governs how the UUIDs of incoming (deserialized) nodes are handled. There are four options (defined as constants in the interfacejavax.jcr.ImportUUIDBehavior):

  • IMPORT_UUID_CREATE_NEW: Incoming referenceable nodes are assigned newly created UUIDs upon addition to the workspace. As a result UUID collisions never occur.

  • IMPORT_UUID_COLLISION_REMOVE_EXISTING: If an incoming referenceable node has the same UUID as a node already existing in the workspace then the already existing node (and its subtree) 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 subtree is being written.

  • IMPORT_UUID_COLLISION_REPLACE_EXISTING: If an incoming referenceable node has the same UUID 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 subtree being disaggregated and “spread around” to different locations in the workspace. In the most extreme case this behavior may result in no node at all being added as child ofparentAbsPath. This will occur if the topmost element of the incoming XML has the same UUID as an existing node elsewhere in the workspace.

  • IMPORT_UUID_COLLISION_THROW: If an incoming referenceable node has the same UUID as a node already existing in the workspace then aSAXException is thrown by theContentHandler during deserialization.

ASAXException will be thrown by the returnedContentHandler during deserialization if the top-most element of the incoming XML would deserialize to a node with the same name as an existing child ofparentAbsPath and that child does not allow same-name siblings.

ASAXException will also be thrown by the returnedContentHandler during deserialization ifuuidBehavior is set toIMPORT_UUID_COLLISION_REMOVE_EXISTING and an incoming node has the same UUID as the node atparentAbsPath or one of its ancestors.

APathNotFoundException is thrown if no node exists atparentAbsPath.

AConstraintViolationException is thrown if the new subtree cannot be added to the node atparentAbsPath due to node-type or other implementation-specific constraints, and this can be determined before the first SAX event is sent.

UnlikeSession.getImportContentHandler, this method will also enforce node type constraints by having the returnedContentHandler throw aSAXException during deserialization. However, which node type constraints are enforced depends upon whether node type information in the imported data is respected, and this is an implementation-specific issue (see 7.3.3 Respecting Property Semantics).

AVersionException is thrown if the node atparentAbsPath is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in.

ALockException is thrown if a lock prevents the addition of the subtree.

AnAccessDeniedException is thrown if the session associated with thisWorkspace object does not have sufficient permissions to perform the import.

ARepositoryException is thrown if another error occurs.

void

importXML(String parentAbsPath,
InputStream in,
int uuidBehavior)

Deserializes an XML document and adds the resulting item subtree as a child of the node atparentAbsPath.

If the incoming XML stream does not appear to be asystem view XML document then it is interpreted as adocument view XML document.

Changes are made directly at the workspace level, without going through theSession. As a result, there is not need to callsave. The advantage of this direct-to-workspace method is that a large import will not result in a large cache of pending nodes in theSession. The disadvantage is that invalid data cannot be imported, fixed and then saved. Instead, invalid data will cause this method to throw anInvalidSerializedDataException. SeeSession.importXML for a version of this method thatdoes go through theSession.

The flaguuidBehavior governs how the UUIDs of incoming (deserialized) nodes are handled. There are four options (defined as constants in the interfacejavax.jcr.ImportUUIDBehavior):

  • IMPORT_UUID_CREATE_NEW: Incoming referenceable nodes are assigned newly created UUIDs upon addition to the workspace. As a result UUID collisions never occur.

  • IMPORT_UUID_COLLISION_REMOVE_EXISTING: If an incoming referenceable node has the same UUID as a node already existing in the workspace then the already existing node (and its subtree) 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 subtree is being written.

  • IMPORT_UUID_COLLISION_REPLACE_EXISTING: If an incoming referenceable node has the same UUID 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 subtree 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 ofparentAbsPath. This will occur if the topmost element of the incoming XML has the same UUID as an existing node elsewhere in the workspace.

  • IMPORT_UUID_COLLISION_THROW: If an incoming referenceable node has the same UUID as a node already existing in the workspace then anItemExistsException is thrown.

AnItemExistsException will be thrown if the top-most element of the incoming XML would deserialize to a node with the same name as an existing child ofparentAbsPath and that child does not allow same-name siblings.

AnIOException is thrown if an I/O error occurs.

If no node exists atparentAbsPath, aPathNotFoundException is thrown.

If node-type or other implementation-specific constraints prevent the addition of the subtree, aConstraintViolationException is thrown.

AConstraintViolationException will also be thrown ifuuidBehavior is set toIMPORT_UUID_COLLISION_REMOVE_EXISTING and an incoming node has the same UUID as the node atparentAbsPath or one of its ancestors.

AVersionException is thrown if the node atparentAbsPath is versionable and checked-in, or is non-versionable but its nearest versionable ancestor is checked-in.

ALockException is thrown if a lock prevents the addition of the subtree.

AnAccessDeniedException is thrown if the session associated with thisWorkspace object does not have sufficient permissions to perform the import.

If another error occurs, aRepositoryException is thrown.




[8]ページ先頭

©2009-2025 Movatter.jp