TheWorkspace interface provides the following methods for importing content into the repository:
javax.jcr. | |
ContentHandler | getImportContentHandler( 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):
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, 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):
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. |