我正在玩JCR存储库 - 特别是Jackrabbit - 用于存储当前项目的数据。一切都很顺利,但遗憾的是有时很难找到文档。我现在正在努力的是为某些测试设置单元测试数据。我已经运行了一个内存中的Jackrabbit,并正确地将我的Nodetypes.cnd和data.xml文件导入其中,以便我有种子数据进行测试。但是,我无法确定如何从data.xml文件导入节点具有多个具有相同名称的属性。
具体来说,由于数据结构的方式,我有一个规则节点链接到其他规则节点 - 其中一个规则实际上按照其他规则工作。我已经通过在Rules节点上具有“rule(PATH)multiple”的属性来实现这一点,因此只需要链接到规则节点的节点路径列表。我可以通过编写
轻松地在我的xml中添加一个链接<rule1 name="Rule #1" description="This is Rule number 1" rule="/rules/rule2" />
正确创建一个名为“rule1”的规则,该规则具有指向“rule2”的链接。我希望能够使用session.importXML()方法创建此规则,其中它有多个链接...我已经尝试了
<rule1 name="Rule #1" description="This is Rule number 1" rule="/rules/rule2,/rules/rule3" />
<rule1 name="Rule #1" description="This is Rule number 1" rule="/rules/rule2" rule="/rules/rule3" />
<rule1 Rule #1" description="This is Rule number 1">
<@rule>/rules/rule2</@rule>
<@rule>/rules/rule3</@rule>
</rule1>
这些都没有奏效。实际上 - 显然已经足够了 - 第二个和第三个甚至都不解析为XML。
有办法做到这一点吗?或者,我是否需要更改导入过程以使其在此处有所不同?
导入完全是用
完成的 InputStream xml = getClass().getResourceAsStream("/jcr/data.xml");
session.importXML(session.getRootNode().getPath(), xml, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
所以根本没什么特别的。
答案 0 :(得分:1)
我假设“data.xml”是您要导入存储库的文档视图XML。 Jackrabbit没有定义如何从/向存储库的文档视图导入/导出具有多个值的多值属性。 从JCR 2.0 spec来看,多值属性的解释取决于实现。 但是,Jackrabbit确实支持从存储库的系统视图导入多值属性。出口相同。
您可以使用Session.exportSystemView()API下载或导出存储库的系统视图,也可以为您的测试存储库手动创建一个。
这是一个例子。注 - “car:engines(string)multiple”。
<car='http://www.modeshape.org/examples/cars/1.0'>
[car:Car] > nt:unstructured, mix:created, mix:referenceable
- car:maker (string)
- car:model (string)
- car:year (string) < '(19|20)[0-9]{2}' // any 4 digit number starting with '19' or '20'
- car:msrp (string) < '[$][0-9]{1,3}[,]?[0-9]{3}([.][0-9]{2})?' // of the form "$X,XXX.ZZ", "$XX,XXX.ZZ" or "$XXX,XXX.ZZ"
// where '.ZZ' is optional
- car:userRating (long) < '[1,5]' // any value from 1 to 5 (inclusive)
- car:valueRating (long) < '[1,5]' // any value from 1 to 5 (inclusive)
- car:mpgCity (long) < '(0,]' // any value greater than 0
- car:mpgHighway (long) < '(0,]' // any value greater than 0
- car:lengthInInches (double) < '(0,]' // any value greater than 0
- car:wheelbaseInInches (double) < '(0,]' // any value greater than 0
- car:alternateModels (reference) < 'car:Car'
- car:engines (string) multiple
以下是包含上述CND的存储库的示例系统视图XML。 请注意,多值属性“car:engines”表示为列表元素。
<sv:property sv:name="car:engines" sv:type="String" sv:multiple="true">
<sv:value>1.8L</sv:value>
<sv:value>1.5L</sv:value>
</sv:property>
可以使用Session.importXML()API将此系统视图XML导入到另一个存储库。
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="Hybrid" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:car="http://www.modeshape.org/examples/cars/1.0" xmlns:rep="internal" xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name" sv:multiple="true">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>7e999653-e558-4131-8889-af1e16872f4d</sv:value>
</sv:property>
<sv:node sv:name="Toyota Prius">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>car:Car</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>0111cbd0-8f9b-4588-8ded-d66907174bcd</sv:value>
</sv:property>
<sv:property sv:name="car:engines" sv:type="String" sv:multiple="true">
<sv:value>1.8L</sv:value>
<sv:value>1.5L</sv:value>
</sv:property>
<sv:property sv:name="car:maker" sv:type="String">
<sv:value>Toyota</sv:value>
</sv:property>
<sv:property sv:name="car:model" sv:type="String">
<sv:value>Prius</sv:value>
</sv:property>
<sv:property sv:name="car:mpgCity" sv:type="Long">
<sv:value>48</sv:value>
</sv:property>
<sv:property sv:name="car:mpgHighway" sv:type="Long">
<sv:value>45</sv:value>
</sv:property>
<sv:property sv:name="car:msrp" sv:type="String">
<sv:value>$21,500</sv:value>
</sv:property>
<sv:property sv:name="car:userRating" sv:type="Long">
<sv:value>4</sv:value>
</sv:property>
<sv:property sv:name="car:valueRating" sv:type="Long">
<sv:value>5</sv:value>
</sv:property>
<sv:property sv:name="car:year" sv:type="String">
<sv:value>2008</sv:value>
</sv:property>
<sv:property sv:name="jcr:created" sv:type="Date">
<sv:value>2011-06-13T23:45:59.175-04:00</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:node sv:name="carImage">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:file</sv:value>
</sv:property>
<sv:property sv:name="jcr:created" sv:type="Date">
<sv:value>2011-06-13T23:45:59.181-04:00</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:node sv:name="jcr:content">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:resource</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>7de51be4-1466-414b-a3ff-d840095e61bf</sv:value>
</sv:property>
<sv:property sv:name="jcr:data" sv:type="Binary">
<sv:value/>
</sv:property>
<sv:property sv:name="jcr:encoding" sv:type="String">
<sv:value>binary</sv:value>
</sv:property>
<sv:property sv:name="jcr:lastModified" sv:type="Date">
<sv:value>2011-05-18T16:14:30.000-04:00</sv:value>
</sv:property>
<sv:property sv:name="jcr:lastModifiedBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="jcr:mimeType" sv:type="String">
<sv:value>image/jpeg</sv:value>
</sv:property>
</sv:node>
</sv:node>
<sv:node sv:name="carImage">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:file</sv:value>
</sv:property>
<sv:property sv:name="jcr:created" sv:type="Date">
<sv:value>2011-06-13T23:45:59.322-04:00</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:node sv:name="jcr:content">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:resource</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>6ad955e2-6e75-4833-904c-6ee3bf7c18b6</sv:value>
</sv:property>
<sv:property sv:name="jcr:data" sv:type="Binary">
<sv:value/>
</sv:property>
<sv:property sv:name="jcr:encoding" sv:type="String">
<sv:value>binary</sv:value>
</sv:property>
<sv:property sv:name="jcr:lastModified" sv:type="Date">
<sv:value>2011-05-18T16:14:30.000-04:00</sv:value>
</sv:property>
<sv:property sv:name="jcr:lastModifiedBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
<sv:property sv:name="jcr:mimeType" sv:type="String">
<sv:value>image/jpeg</sv:value>
</sv:property>
</sv:node>
</sv:node>
</sv:node>
<sv:node sv:name="Toyota Highlander">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>car:Car</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>99b2afd4-74e8-4a45-a6d2-623bfc66387a</sv:value>
</sv:property>
<sv:property sv:name="car:maker" sv:type="String">
<sv:value>Toyota</sv:value>
</sv:property>
<sv:property sv:name="car:model" sv:type="String">
<sv:value>Highlander</sv:value>
</sv:property>
<sv:property sv:name="car:mpgCity" sv:type="Long">
<sv:value>27</sv:value>
</sv:property>
<sv:property sv:name="car:mpgHighway" sv:type="Long">
<sv:value>25</sv:value>
</sv:property>
<sv:property sv:name="car:msrp" sv:type="String">
<sv:value>$34,200</sv:value>
</sv:property>
<sv:property sv:name="car:userRating" sv:type="Long">
<sv:value>4</sv:value>
</sv:property>
<sv:property sv:name="car:valueRating" sv:type="Long">
<sv:value>5</sv:value>
</sv:property>
<sv:property sv:name="car:year" sv:type="String">
<sv:value>2008</sv:value>
</sv:property>
<sv:property sv:name="jcr:created" sv:type="Date">
<sv:value>2011-06-13T23:45:59.191-04:00</sv:value>
</sv:property>
<sv:property sv:name="jcr:createdBy" sv:type="String">
<sv:value>admin</sv:value>
</sv:property>
</sv:node>
</sv:node>