jackrabbit食用指南:关于NodeType

JSR 170 node types 分为 Mixin types 和 Primary types。

这篇文章主要讨论Primary types,我参考了Jackrabbit Wikijcr2.0Api 将所有的Primary types节点整理如下图所示。
JCR Primary types.png

可以看到所有的节点都是基于nt:base产生的,并且**nt:base**是一个abstract节点,如果你直接将nt:base节点当作节点类型创建新节点会得到一个抽象节点的异常提示。

Node ntbase = rootNode.addNode("ntbase", NodeType.NT_BASE);

javax.jcr.nodetype.ConstraintViolationException: Unable to add a node with an abstract node type: nt:base

jackrabbit wiki 上只针对
nt:base,
nt:unstructured,
nt:hierarchyNode,
nt:file,
nt:folder,
nt:resource
这几个NodeType做了说明,其他的节点没有任何提示。所以本文只对这些NodeType做使用说明,其他的节点cleanup123会在尝试之后补充更新。

上述6个节点类型一共分为

  1. nt:base 基础类型
    此类型是抽象节点类型不能直接用来新建新的节点,但是可以用SQL-2语法来查询。
  2. nt:unstructured 非结构化节点
    可以设置所有类型的属性和子节点。

原文为: The nt:unstructured node type permits all kinds of properties and child nodes to be added to a node

  1. nt:hierarchyNode 结构化节点

    nt:hierarchyNode也是一个抽象节点,他的具体实现节点有三个:

    1. nt:file
      可以新增一个jcr:content 的节点,通常使用nt:resources类型的节点。

    2. nt:folder
      可以新增一个nt:hierarchyNode类型的节点

    3. nt:linkedFile
      可以添加一个jcr:content 的属性,通常使用nt:resources类型的节点。

  2. nt:resource
    可以设置Property.JCR_ENCODING,Property.JCR_MIMETYPE,Property.JCR_DATA,Property.JCR_LAST_MODIFIED这四个属性。


以下是具体使用这些节点的代码:

        //在基础节点后增加非结构化
        Node unstructured = rootNode.addNode("unstructured", NodeType.NT_UNSTRUCTURED);
        //非结构化节点可以自定义自己的属性
        unstructured.setProperty("p1","abc");
        unstructured.setProperty("p2","1234");

        //在基础节点下新增nt:hierarchyNode类型的nt:folder
        Node picfolder = rootNode.addNode("picfolder", NodeType.NT_FOLDER);
        //在folder下面建立nt:file节点
        Node mypic1 = picfolder.addNode("mypic1", NodeType.NT_FILE);
        //在mypic1文件下可建立Node.JCR_CONTENT的节点可以是任何类型,但是通常会选择nt:resource节点
        Node sky = mypic1.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE);
        sky.setProperty(Property.JCR_ENCODING,"utf-8");
        sky.setProperty(Property.JCR_MIMETYPE,"application/json");
        sky.setProperty(Property.JCR_DATA, new BinaryImpl("{'id':001,'msg':'sky is blue!'}".getBytes()));
        sky.setProperty(Property.JCR_LAST_MODIFIED,Calendar.getInstance().getTimeInMillis());
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提示错误[ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] Unresolveable build extension: Plugin org.apache.maven.wagon:wagon-webdav-jackrabbit:1.0-beta-6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: commons-httpclient:commons-httpclient:jar:3.1 (absent): Could not transfer artifact commons-httpclient:commons-httpclient:jar:3.1 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.112.215] failed: connect timed out @ @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project org.drools:droolsjbpm-integration:7.74.0-SNAPSHOT (D:\droolsjbpm-integration-main\droolsjbpm-integration-main\pom.xml) has 1 error [ERROR] Unresolveable build extension: Plugin org.apache.maven.wagon:wagon-webdav-jackrabbit:1.0-beta-6 or one of its dependencies could not be resolved: The following artifacts could not be resolved: commons-httpclient:commons-httpclient:jar:3.1 (absent): Could not transfer artifact commons-httpclient:commons-httpclient:jar:3.1 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.112.215] failed: connect timed out -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginManagerException
最新发布
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值