gpt4 book ai didi

java - 无法通过 RMI 在 JackRabbit 中加载 Nodetypes

转载 作者:行者123 更新时间:2023-12-01 19:41:02 26 4
gpt4 key购买 nike

我正在尝试加载包含一些自定义节点类型定义的 CND 文件。文件看起来像这样

<ca = 'http://www.stuff.com/training'>
[ca:article]
- ca:headline (string)
mandatory
- ca:body (string)
mandatory

这是加载节点类型的类

public class JcrRegisterNodeTypes {

public static void RegisterCustomNodeTypes(Session session, String cndFileName){

NodeType[] nodeTypes;
try {
File file = new File(cndFileName);
FileReader fr = new FileReader(file);
nodeTypes = CndImporter.registerNodeTypes(fr, session);
for (NodeType nt : nodeTypes) {
System.out.println("Registered: " + nt.getName());
}
} catch (InvalidNodeTypeDefinitionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NodeTypeExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedRepositoryOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

然后引发“解析异常”,并显示此消息

10:37:23,052 ERROR [stderr] (default task-48) org.apache.jackrabbit.commons.cnd.ParseException: javax.jcr.UnsupportedRepositoryOperationException: TODO: JCR-3206 (cnd input stream, line 2)

该方法似乎没有为 RMI 实现。是否有替代方法来生成/node types/custom_node_types.xml?

<小时/>

我已经在 WildFly 14 上部署了 jackrabbit-webapp-2.18.4.war 并且我可以上传/下载文件,所以我认为安装运行正常。

项目中包含的 jar 是最后一个稳定版本

jackrabbit-api-2.18.4.jarjackrabbit-core-2.18.4.jarjackrabbit-jcr-commons-2.18.4.jarjackrabbit-jcr-rmi-2.18.4.jarjcr-2.0.jar

最佳答案

因此,我遵循 Julian 的建议并尝试直接在服务器上修改 NodeTypes。

方法CndImporter.registerNodeTypes(fr, session)将CND文件转换为custom_nodetypes.xml文件。该 XML 文件在加载时由存储库管理器读取。 CND 和 XML 的语法不同,但很容易弄清楚如何从一种语法转换到另一种语法。

我已经基于

手动创建了一个 xml

https://github.com/onehippo/essentials/blob/master/plugin-sdk/implementation/src/test/resources/custom_nodetypes.xml

我更改了 xml 的命名空间标记 ( xmlns:ocm="http://jackrabbit.apache.org/ocm") 并将其手动添加到 namespaces/ns_reg.properties

之后,我启动了服务器并解决了一些拼写错误,它终于启动了。我已经编写了这个小方法来检查它,似乎没问题。

public void showNodeTypes(){

NodeTypeManager manager;
try {
manager = (NodeTypeManager)jcrSession.getWorkspace().getNodeTypeManager();

NodeTypeIterator nodeTypeIterator = manager.getAllNodeTypes();
NodeType actual;

while (nodeTypeIterator.hasNext()){
System.out.println("----------------");
actual= (NodeType)nodeTypeIterator.next();
System.out.println(actual.getName());
for(PropertyDefinition propertyDef:actual.getPropertyDefinitions()) {
System.out.println(propertyDef.getName() +" --> Mandatory: " + propertyDef.isMandatory());
}
}

} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

这是我使用的custom_nodetypes.xml

<?xml version="1.0" encoding="UTF-8"?>
<nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:spi="http://www.example.ad/spi">

<nodeType name="spi:cmsobjectimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
<supertypes>
<supertype>nt:base</supertype>
</supertypes>
<propertyDefinition name="spi:name" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
</nodeType>

<nodeType name="spi:contentimpl" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
<supertypes>
<supertype>spi:cmsobjectimpl</supertype>
</supertypes>
</nodeType>

<nodeType name="spi:documentstream" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
<supertypes>
<supertype>mix:versionable</supertype>
<supertype>nt:base</supertype>
</supertypes>
<propertyDefinition name="spi:encoding" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
<propertyDefinition name="spi:binarycontent" requiredType="Binary" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
</nodeType>

<nodeType name="spi:Expedient" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
<supertypes>
<supertype>spi:contentimpl</supertype>
</supertypes>
<propertyDefinition name="spi:contenttype" requiredType="String" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
<propertyDefinition name="spi:size" requiredType="Long" autoCreated="false" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
<propertyDefinition name="spi:numExpedient" requiredType="Long" autocreated="true" mandatory="true" onParentVersion="COPY" protected="false" multiple="false"/>
<childNodeDefinition name="*" defaultPrimaryType="spi:documentstream" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" sameNameSiblings="false">
<requiredPrimaryTypes>
<requiredPrimaryType>spi:documentstream</requiredPrimaryType>
</requiredPrimaryTypes>
</childNodeDefinition>
</nodeType>

</nodeTypes>

关于java - 无法通过 RMI 在 JackRabbit 中加载 Nodetypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59173828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com