无法通过 RMI 在 JackRabbit 中加载节点类型

Can't load Nodetypes in JackRabbit through RMI

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

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

这里是 class 加载节点类型

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();
        }
    }
}

然后 "parse exception" 被引发,带有此消息

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,我可以 upload/download 个文件,所以我认为安装 运行 没问题。

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

jackrabbit-api-2.18.4.jar jackrabbit-core-2.18.4.jar jackrabbit-jcr-commons-2.18.4.jar jackrabbit-jcr-rmi-2.18.4.jar jcr-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>