将 XML 导入 JCR 存储库 - 多值属性
我正在使用 JCR 存储库(特别是 Jackrabbit)来存储我当前项目的数据。一切都很顺利,尽管不幸的是有时文档有点难找到。我现在正在努力解决的是为某些测试设置单元测试数据。我已经运行了一个内存中的 Jackrabbit,并且正在将 Nodetypes.cnd 和 data.xml 文件正确导入其中,以便我有种子数据可供测试。然而,我无法弄清楚如何从 data.xml 文件导入,其中节点具有多个同名属性。
具体来说,由于数据的构造方式,我有一个链接到其他规则节点的规则节点 - 其中一个规则实际上根据其他规则起作用。我通过在规则节点上设置一个属性“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);
所以绝对没有什么特别的。
I'm playing with a JCR repository - Jackrabbit specifically - for storing data for my current project. Everything is going fine, though documentation is unfortunately a bit hard to find at times. What I'm struggling with right now is setting up unit-test data for some tests. I've gotten an in-memory Jackrabbit running, and am importing my Nodetypes.cnd and data.xml files into it correctly so that I have seed data to test against. I can't however work out how to import from the data.xml file where the node has multiple properties with the same name.
Specifically, because of the way the data is structured I have a Rules node that links to other Rules nodes - where one rule actually works in terms of other rules. I've implemented this by having a property on the Rules node that is "rule (PATH) multiple", so simply a list of the node paths to the rules nodes that are linked. I can easily add one link in my xml by writing
<rule1 name="Rule #1" description="This is Rule number 1" rule="/rules/rule2" />
which correctly creates a rule called "rule1" that has a link to "rule2". What I want to to be able to create this rule using the session.importXML() method where it has more than one link... I've tried
<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>
And none of these have worked. In fact - obviously enough - the second and third ones don't even parse as XML.
Is there a way to do this? Or do I need to change my import process to work differently here?
The import is literally done with
InputStream xml = getClass().getResourceAsStream("/jcr/data.xml");
session.importXML(session.getRootNode().getPath(), xml, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
So absolutely nothing special about that at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设“data.xml”是您想要导入到存储库的文档视图 XML。
Jackrabbit 没有定义如何从存储库的文档视图导入/导出具有多个值的多值属性。
从JCR 2.0规范看来,多值的解释属性取决于实现。
但是 Jackrabbit 确实支持从存储库的系统视图导入多值属性。出口也一样。
您可以使用 Session.exportSystemView() API 下载或导出存储库的系统视图,或者为您的测试存储库手动创建一个系统视图。
这是一个例子。注意 - “汽车:发动机(字符串)多个”。
以下是包含上述 CND 的存储库的系统视图 XML 示例。
请注意,多值属性“car:engines”表示为列表元素。
可以像您一样使用 Session.importXML() API 将此系统视图 XML 导入到另一个存储库。
I am assuming the "data.xml" is a document-view XML that you want to import to the repository.
Jackrabbit does not define how to import/export a multi-valued property with multiple values from/to a document view of a repository.
It seems from the JCR 2.0 spec, the interpretation of a multi-valued property is dependent on the implementation.
However Jackrabbit does support the import of multi-valued properties from a system-view of a repository. Same for export.
You can download or export the system-view of the repository using Session.exportSystemView() API or manually create one for your test repository.
Here is an example. Note - "car:engines (string) multiple".
Following is an example system-view XML of a repository containing the above CND.
Note the multi-valued property "car:engines" is represented as a list element.
This system-view XML can be imported to another repository using Session.importXML() API as you are doing.