我假设“data.xml”是您要导入到存储库的文档视图 XML。Jackrabbit 没有定义如何从存储库的文档视图导入/导出具有多个值的多值属性。从JCR 2.0 规范看来,多值属性的解释取决于实现。但是 Jackrabbit 确实支持从存储库的系统视图导入多值属性。出口也一样。
您可以使用 Session.exportSystemView() API 下载或导出存储库的系统视图,或者为您的测试存储库手动创建一个。
这是一个例子。注意 - “汽车:引擎(字符串)多个”。
<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>