本文整理了Java中javax.jcr.Session.getImportContentHandler()
方法的一些代码示例,展示了Session.getImportContentHandler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.getImportContentHandler()
方法的具体详情如下:
包路径:javax.jcr.Session
类名称:Session
方法名:getImportContentHandler
[英]Returns an org.xml.sax.ContentHandler
which is used to push SAX events to the repository. If the incoming XML (in the form of SAX events) does not appear to be a JCR system view XML document then it is interpreted as a JCR document view XML document.
The incoming XML is deserialized into a subgraph of items immediately below the node at parentAbsPath
.
This method simply returns the ContentHandler
without altering the state of the session; the actual deserialization to the session transient space is done through the methods of the ContentHandler
. Invalid XML data will cause the ContentHandler
to throw a SAXException
.
As SAX events are fed into the ContentHandler
, the tree of new items is built in the transient storage of the session. In order to dispatch the new content, save
must be called. See Workspace#getImportContentHandler for a workspace-write version of this method.
The flag uuidBehavior
governs how the identifiers of incoming nodes are handled:
Node.addNode
. That is, they are either assigned newly created identifiers upon addition or upon save
(depending on the implementation). In either case, identifier collisions will not occur.save
.parentAbsPath
. This will occur if the topmost element of the incoming XML has the same identifier as an existing node elsewhere in the workspace. The change will be persisted on save
.SAXException
is thrown by the ContentHandler
during deserialization.Workspace.getImportContentHandler
, this method does not necessarily enforce all node type constraints during deserialization. Those that would be immediately enforced in a session-write method (Node.addNode
, Node.setProperty
etc.) of this implementation cause the returned ContentHandler
to throw an immediate SAXException
during deserialization. All other constraints are checked on save, just as they are in normal write operations. 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.A SAXException
will also be thrown by the returned ContentHandler
during deserialization 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.
A PathNotFoundException
is thrown either immediately, on dispatch or on persist, if no node exists at parentAbsPath
. Implementations may differ on when this validation is performed
A ConstraintViolationException
is thrown either immediately, on dispatch or on persist, if the new subgraph cannot be added to the node at parentAbsPath
due to node-type or other implementation-specific constraints, and this can be determined before the first SAX event is sent. Implementations may differ on when this validation is performed.
A VersionException
is thrown either immediately, on dispatch or on persist, if the node at parentAbsPath
is read-only due to a check-in. Implementations may differ on when this validation is performed.
A LockException
is thrown either immediately, on dispatch or on persist, if a lock prevents the addition of the subgraph. Implementations may differ on when this validation is performed.
[中]返回一个org.xml.sax.ContentHandler
,用于将SAX事件推送到存储库。如果传入的XML(以SAX事件的形式)看起来不是JCR系统视图XML文档,那么它将被解释为JCR文档视图XML文档。
传入的XML被反序列化为位于parentAbsPath
节点正下方的项目子图。
这个方法只返回ContentHandler
,而不改变会话的状态;对会话临时空间的实际反序列化是通过ContentHandler
的方法完成的。无效的XML数据将导致ContentHandler
抛出SAXException
。
当SAX事件被输入到ContentHandler
中时,新项目的树被构建在会话的临时存储中。为了发送新内容,必须调用save
。有关此方法的工作区写入版本,请参阅工作区#getImportContentHandler。
标志uuidBehavior
控制如何处理传入节点的标识符:
*ImportUUIDBehavior#IMPORT_UUID_CREATE_NEW:传入标识符节点的添加方式与新节点添加[$9$]的方式相同。也就是说,它们要么在添加时被分配新创建的标识符,要么在save
时被分配(取决于实现)。在这两种情况下,都不会发生标识符冲突。
*ImportUUIDBehavior#IMPORT UID U COLLISION _REMOVE U EXISTING:如果传入节点与工作区中已存在的节点具有相同的标识符,则在添加传入节点之前,将已存在的节点(及其子图)从工作区中的任何位置移除。请注意,这可能会导致节点从工作区中远离写入传入子图的位置的位置“消失”。删除和新添加的内容都将在[$11$]上保留。
*ImportUUIDBehavior#IMPORT UID U COLLISION _REPLACE U EXISTING:如果传入节点与工作区中已存在的节点具有相同的标识符,则已存在的节点将被与现有节点位于相同位置的传入节点替换。请注意,这可能会导致传入的子图被分解并“分散”到工作区中的不同位置。在最极端的情况下,这种行为可能会导致根本没有节点被添加为parentAbsPath
的子节点。如果传入XML的最顶层元素与工作区中其他地方的现有节点具有相同的标识符,就会发生这种情况。更改将在[$13$]上保留。
*ImportUUIDBehavior#IMPORT UID U COLLISION U THROW:如果传入节点与工作区中已存在的节点具有相同的标识符,则在反序列化过程中,ContentHandler
会抛出一个SAXException
。
与Workspace.getImportContentHandler
不同,此方法在反序列化期间不一定强制所有节点类型约束。在这个实现的会话写入方法(Node.addNode
、Node.setProperty
等)中立即强制执行的那些操作会导致返回的ContentHandler
在反序列化过程中立即抛出SAXException
。所有其他约束在保存时都会被检查,就像在正常的写入操作中一样。然而,实施哪些节点类型约束取决于导入数据中的节点类型信息是否得到尊重,这是一个特定于实现的问题。
如果uuidBehavior
设置为IMPORT_UUID_COLLISION_REMOVE_EXISTING
,并且传入节点与parentAbsPath
处的节点或其祖先节点具有相同的标识符,则在反序列化过程中,返回的ContentHandler
也将抛出SAXException
。
如果[$27$]上不存在节点,则在分派或持久化时立即抛出PathNotFoundException
。执行此验证的时间可能会有所不同
如果由于节点类型或其他特定于实现的约束而无法将新子图添加到parentAbsPath
处的节点,则ConstraintViolationException
会立即在分派或持久化时抛出,这可以在发送第一个SAX事件之前确定。执行此验证的时间可能会有所不同。
如果parentAbsPath
处的节点由于签入而为只读,则VersionException
会在分派或持久化时立即抛出。执行此验证的时间可能会有所不同。
如果锁阻止子图的添加,则LockException
会在分派或持久化时立即抛出。执行此验证的时间可能会有所不同。
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/**
* Forwards the method call to the underlying session.
*/
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehaviour)
throws PathNotFoundException, ConstraintViolationException, VersionException, LockException,
RepositoryException {
return session.getImportContentHandler(parentAbsPath, uuidBehaviour);
}
代码示例来源:origin: apache/jackrabbit
private static ContentHandler createContentHandler(Node parent) throws RepositoryException {
return parent.getSession().getImportContentHandler(parent.getPath(), ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
}
代码示例来源:origin: apache/jackrabbit
/**
* Return the import content handler.
*/
public ContentHandler getImportContentHandler(String arg0, int arg1)
throws PathNotFoundException, ConstraintViolationException, VersionException,
LockException, RepositoryException {
return getSession().getImportContentHandler(arg0, arg1);
}
代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons
@Override
default ContentHandler getImportContentHandler(final String parentAbsPath, final int uuidBehavior)
throws PathNotFoundException, ConstraintViolationException, VersionException, LockException,
RepositoryException {
return unwrapSession().getImportContentHandler(parentAbsPath, uuidBehavior);
}
代码示例来源:origin: ModeShape/modeshape
@Override
public ContentHandler getImportContentHandler( String string,
int i )
throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
return session().getImportContentHandler(string, i);
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jca
/**
* Return the import content handler.
*/
public ContentHandler getImportContentHandler(String arg0, int arg1)
throws PathNotFoundException, ConstraintViolationException, VersionException,
LockException, RepositoryException {
return getSession().getImportContentHandler(arg0, arg1);
}
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
return getWrappedSession().getImportContentHandler(parentAbsPath, uuidBehavior);
}
代码示例来源:origin: brix-cms/brix-cms
public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior)
throws RepositoryException {
return getDelegate().getImportContentHandler(parentAbsPath, uuidBehavior);
}
代码示例来源:origin: apache/jackrabbit
/**
* Supplying an invalid repository path for import must throw a
* PathNotFoundException
*/
public void testSessionGetImportContentHandlerExceptions() throws RepositoryException {
//Specifying a path that does not exist throws a PathNotFound exception
try {
session.getImportContentHandler(treeComparator.targetFolder + "/thisIsNotAnExistingNode",
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
fail("Specifying a non-existing path must throw a PathNotFoudException.");
} catch (PathNotFoundException e) {
// success
}
}
代码示例来源:origin: org.apache.jackrabbit.vault/org.apache.jackrabbit.vault
private Node sysCopy(Node src, Node dstParent, String dstName) throws RepositoryException {
try {
ContentHandler handler = dstParent.getSession().getImportContentHandler(dstParent.getPath(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
src.getSession().exportSystemView(src.getPath(), handler, true, false);
return dstParent.getNode(dstName);
} catch (SAXException e) {
throw new RepositoryException("Unable to perform sysview copy", e);
}
}
代码示例来源:origin: net.adamcin.recap/net.adamcin.recap.core
private Node sysCopy(Node src, Node dstParent, String dstName)
throws RepositoryException {
try {
ContentHandler handler = dstParent.getSession().getImportContentHandler(dstParent.getPath(), 0);
src.getSession().exportSystemView(src.getPath(), handler, true, false);
return dstParent.getNode(dstName);
} catch (SAXException e) {
throw new RepositoryException("Unable to perform sysview copy", e);
}
}
代码示例来源:origin: apache/jackrabbit
public void doImportNoSave(String absPath, FileInputStream in, boolean useHandler)
throws Exception {
if (useHandler) {
ContentHandler ih = session.getImportContentHandler(absPath, 0);
createXMLReader(ih).parse(new InputSource(in));
} else {
session.importXML(absPath, in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
}
}
//------------< System view export import tests >-----------------------------------
代码示例来源:origin: net.adamcin.commons/net.adamcin.commons.jcr
public ContentHandler getImportContentHandler(String s, int i) throws RepositoryException {
commit();
return getSession().getImportContentHandler(s, i);
}
代码示例来源:origin: apache/jackrabbit
handler = workspace.getImportContentHandler(absPath, uuidBehaviour);
} else {
handler = session.getImportContentHandler(absPath, uuidBehaviour);
代码示例来源:origin: apache/jackrabbit
createXMLReader(ih).parse(new InputSource(in));
} else {
ContentHandler ih = session.getImportContentHandler(absPath, 0);
createXMLReader(ih).parse(new InputSource(in));
session.save();
代码示例来源:origin: apache/jackrabbit
createXMLReader(ih).parse(new InputSource(in));
} else {
ContentHandler ih = session.getImportContentHandler(treeComparator.targetFolder,
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
createXMLReader(ih).parse(new InputSource(in));
代码示例来源:origin: org.apache.jackrabbit.vault/org.apache.jackrabbit.vault
JcrSysViewTransformer(Node node, String existingPath) throws RepositoryException, SAXException {
Session session = node.getSession();
parent = node;
handler = session.getImportContentHandler(
node.getPath(),
existingPath != null
? ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING
: ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
);
// first define the current namespaces
String[] prefixes = session.getNamespacePrefixes();
handler.startDocument();
for (String prefix: prefixes) {
handler.startPrefixMapping(prefix, session.getNamespaceURI(prefix));
}
this.existingPath = existingPath;
if (existingPath != null) {
// check if there is an existing node with the name
recovery = new ChildNodeStash(session).excludeName("rep:cache");
recovery.stashChildren(existingPath);
}
excludeNode("rep:cache");
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests whether importing an invalid XML file throws a SAX exception. The
* file used here is more or less garbage.
*/
public void testInvalidXmlThrowsSaxException()
throws IOException, ParserConfigurationException {
StringReader in = new StringReader("<this is not a <valid> <xml> file/>");
ContentHandler ih = null;
try {
ih = session.getImportContentHandler(treeComparator.targetFolder,
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
} catch (RepositoryException e) {
fail("ImportHandler not created: " + e);
}
helpTestSaxException(ih, in, "session");
in = new StringReader("<this is not a <valid> <xml> file/>");
try {
ih = workspace.getImportContentHandler(treeComparator.targetFolder, 0);
} catch (RepositoryException e) {
fail("ImportHandler not created: " + e);
}
helpTestSaxException(ih, in, "workspace");
}
代码示例来源:origin: apache/jackrabbit
try {
final Session session = parent.getSession();
final ContentHandler handler = session.getImportContentHandler(
parent.getPath(),
ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
代码示例来源:origin: apache/jackrabbit
String svprefix = Name.NS_SV_PREFIX + ":";
ContentHandler ch = superuser.getImportContentHandler(testRootNode.getPath(), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
ch.startDocument();
ch.startPrefixMapping(prefix, uri);
内容来源于网络,如有侵权,请联系作者删除!