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

时间:2019-12-04 10:27:14

标签: java jcr jackrabbit

我正在尝试加载具有某些自定义节点类型定义的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();
        }
    }
}

然后出现“ 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,并且可以上传/下载文件,所以我认为安装运行正常。

项目中包含的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

1 个答案:

答案 0 :(得分:0)

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

方法 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>