晚上好
我是 JCR 和 Apache Oak (v1.2.3) 的新手,在从 XML 格式导入 Oak 存储库时似乎遇到问题。 (我将存储库填充到 jdbc 支持的节点,但无法理解为什么在导出到 XML 后无法将其重新导入到新实例)。
XML 文件太长,无法在此处发布,但如果有人有任何想法,那就太好了。非常感谢
导入代码示例:
try {
String tesExampleXML = FileUtils.readFileToString(new File("/testRepository.xml"));
Repository repo = new Jcr(new Oak()).createRepository();
Session sesh = repo.login(new SimpleCredentials("admin", "admin".toCharArray()));
sesh.importXML("/",new StringBufferInputStream(tesExampleXML),0);
Node root = sesh.getRootNode();
NodeIterator it = root.getNodes();
while (it.hasNext()){
Node n = it.nextNode();
System.out.println(n.getName());
}
//By this point not all of the nodes in root were printed
assertTrue(root != null);
导入时日志上出现静默异常...... javax.jcr.nodetype.ConstraintViolationException:不是有效的 JCR 名称 'jcr:propertyDefinition[2]'
2015-09-01 16:36:01.0224 警告 main xml.DocViewImportHandler:206 - 遇到非法解码名称“propertyDefinition[1]” javax.jcr.nodetype.ConstraintViolationException:不是有效的 JCR 名称 'jcr:propertyDefinition[1]' 在 org.apache.jackrabbit.oak.namepath.JcrNameParser.checkName(JcrNameParser.java:210) 在 org.apache.jackrabbit.oak.jcr.xml.DocViewImportHandler.processName(DocViewImportHandler.java:202) 在 org.apache.jackrabbit.oak.jcr.xml.DocViewImportHandler.startElement(DocViewImportHandler.java:230) 在 org.apache.jackrabbit.oak.jcr.xml.ImportHandler.startElement(ImportHandler.java:183) 在 org.apache.jackrabbit.commons.xml.DefaultContentHandler.startElement(DefaultContentHandler.java:161) 在 com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506) 在 com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182) 在 com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2768) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606) 在 com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116) 在 com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) ...
使用调试器我得到 调试器中第一个可疑的异常位置 propertyDefinition_x005b_1_x005d_
XML: propertyDefinition_x005b_1_x005d_
原始 XML:(抱歉,它不允许我发布整个内容...
<jcr:root jcr:primaryType="rep:root" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:oak="http://jackrabbit.apache.org/oak/ns/1.0" xmlns:rep="internal"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
<hello jcr:primaryType="nt:unstructured" count="2" />
<jcr:system jcr:primaryType="rep:system">
<jcr:activities jcr:primaryType="rep:Activities" />
<jcr:nodeTypes jcr:primaryType="rep:nodeTypes">
<mix:atomicCounter jcr:primaryType="rep:NodeType"
jcr:hasOrderableChildNodes="false" jcr:isAbstract="false"
jcr:isMixin="true" jcr:isQueryable="true" jcr:nodeTypeName="mix:atomicCounter"
rep:hasProtectedResidualChildNodes="false"
rep:hasProtectedResidualProperties="false">
<jcr:propertyDefinition_x005b_1_x005d_
jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true"
jcr:isFullTextSearchable="true" jcr:isQueryOrderable="true"
jcr:mandatory="false" jcr:multiple="false" jcr:name="oak:counter"
jcr:onParentVersion="COPY" jcr:protected="true" jcr:requiredType="LONG" />
<rep:namedPropertyDefinitions
jcr:primaryType="rep:NamedPropertyDefinitions">
<oak:counter jcr:primaryType="rep:PropertyDefinitions">
<LONG jcr:primaryType="rep:PropertyDefinition"
jcr:autoCreated="true" jcr:isFullTextSearchable="true"
jcr:isQueryOrderable="true" jcr:mandatory="false" jcr:multiple="false"
jcr:name="oak:counter" jcr:onParentVersion="COPY" jcr:protected="true"
jcr:requiredType="LONG" rep:declaringNodeType="mix:atomicCounter" />
</oak:counter>
</rep:namedPropertyDefinitions>
</mix:atomicCounter>
<mix:created jcr:primaryType="rep:NodeType"
jcr:hasOrderableChildNodes="false" jcr:isAbstract="false"
jcr:isMixin="true" jcr:isQueryable="true" jcr:nodeTypeName="mix:created"
rep:hasProtectedResidualChildNodes="false"
rep:hasProtectedResidualProperties="false">
<jcr:propertyDefinition_x005b_1_x005d_
jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true"
jcr:isFullTextSearchable="true" jcr:isQueryOrderable="true"
jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:created"
jcr:onParentVersion="COPY" jcr:protected="true" jcr:requiredType="DATE" />
<jcr:propertyDefinition_x005b_2_x005d_
jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true"
jcr:isFullTextSearchable="true" jcr:isQueryOrderable="true"
jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:createdBy"
jcr:onParentVersion="COPY" jcr:protected="true" jcr:requiredType="STRING" />
<rep:namedPropertyDefinitions
jcr:primaryType="rep:NamedPropertyDefinitions">
<jcr:created jcr:primaryType="rep:PropertyDefinitions">
<DATE jcr:primaryType="rep:PropertyDefinition"
jcr:autoCreated="true" jcr:isFullTextSearchable="true"
jcr:isQueryOrderable="true" jcr:mandatory="false" jcr:multiple="false"
jcr:name="jcr:created" jcr:onParentVersion="COPY" jcr:protected="true"
jcr:requiredType="DATE" rep:declaringNodeType="mix:created" />
</jcr:created>
<jcr:createdBy jcr:primaryType="rep:PropertyDefinitions">
<STRING jcr:primaryType="rep:PropertyDefinition"
jcr:autoCreated="true" jcr:isFullTextSearchable="true"
jcr:isQueryOrderable="true" jcr:mandatory="false" jcr:multiple="false"
jcr:name="jcr:createdBy" jcr:onParentVersion="COPY"
jcr:protected="true" jcr:requiredType="STRING"
rep:declaringNodeType="mix:created" />
</jcr:createdBy>
</rep:namedPropertyDefinitions>
</mix:created>
<mix:etag jcr:primaryType="rep:NodeType"
jcr:hasOrderableChildNodes="false" jcr:isAbstract="false"
jcr:isMixin="true" jcr:isQueryable="true" jcr:nodeTypeName="mix:etag"
rep:hasProtectedResidualChildNodes="false"
rep:hasProtectedResidualProperties="false">
<jcr:propertyDefinition_x005b_1_x005d_
jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="true"
jcr:isFullTextSearchable="true" jcr:isQueryOrderable="true"
jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:etag"
jcr:onParentVersion="COPY" jcr:protected="true" jcr:requiredType="STRING" />
<rep:namedPropertyDefinitions
jcr:primaryType="rep:NamedPropertyDefinitions">
<jcr:etag jcr:primaryType="rep:PropertyDefinitions">
<STRING jcr:primaryType="rep:PropertyDefinition"
jcr:autoCreated="true" jcr:isFullTextSearchable="true"
jcr:isQueryOrderable="true" jcr:mandatory="false" jcr:multiple="false"
jcr:name="jcr:etag" jcr:onParentVersion="COPY" jcr:protected="true"
jcr:requiredType="STRING" rep:declaringNodeType="mix:etag" />
</jcr:etag>
</rep:namedPropertyDefinitions>
</mix:etag>
<mix:language jcr:primaryType="rep:NodeType"
jcr:hasOrderableChildNodes="false" jcr:isAbstract="false"
jcr:isMixin="true" jcr:isQueryable="true" jcr:nodeTypeName="mix:language"
rep:hasProtectedResidualChildNodes="false"
rep:hasProtectedResidualProperties="false">
<jcr:propertyDefinition_x005b_1_x005d_
jcr:primaryType="nt:propertyDefinition" jcr:autoCreated="false"
jcr:isFullTextSearchable="true" jcr:isQueryOrderable="true"
jcr:mandatory="false" jcr:multiple="false" jcr:name="jcr:language"
jcr:onParentVersion="COPY" jcr:protected="false" jcr:requiredType="STRING" />
<rep:namedPropertyDefinitions
jcr:primaryType="rep:NamedPropertyDefinitions">
<jcr:language jcr:primaryType="rep:PropertyDefinitions">
<STRING jcr:primaryType="rep:PropertyDefinition"
jcr:autoCreated="false"
最佳答案
从堆栈跟踪来看,代码似乎也覆盖了系统节点( propertyDefinition_x005b_1_x005d_ )。
我建议您仅导出自定义根文件夹并重新导入它,而不触及任何系统文件夹(rep:security、jcr:system、oak:index)(如果有帮助的话)。
关于java - Apache Oak - XML 导入失败,异常不是有效的 JCR 名称异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32336098/