如何使用API​​覆盖ODF根RSID [英] How do I override ODF Root RSID using the API

查看:119
本文介绍了如何使用API​​覆盖ODF根RSID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用openoffice/libreoffice API生成ODT文档,我希望每次输出的文件都是100%相同的(通过MD5比较).

这时,我可以解压缩在不同时间生成的两个文件,并检查zip文件中的所有文件,它们都匹配100%,但Settings.xml具有两个唯一的区别(两者都与RSID有关). /p>

<config:config-item config:name="Rsid" config:type="int">1835643</config:config-item>

<config:config-item config:name="RsidRoot" config:type="int">1835643</config:config-item>

我了解到这是为了合并和追溯到原始文档,但是我希望它们成为我控制的固定值,因为我无论如何都不打算合并这些文件,但是我找不到在何处设置这些属性.

我尝试了一些选项(如下)并输出属性,但到目前为止找不到.有没有一种方法可以覆盖RSID,而无需我(编码)将文件解压缩并修改XML(我已经完成了),但是感觉有点尴尬,因此仍在寻找它.

// Looking for RSID in all the wrong places - test 1
XPropertySet xSettings = (XPropertySet) xRemoteServiceManager.createInstanceWithContext("com.sun.star.document.Settings", componentContext);

// Looking for RSID in all the wrong places - test 2
Object configProvider = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", componentContext);
XMultiServiceFactory xConfigProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, configProvider);

PropertyValue[] lParams = new PropertyValue[1];

lParams[0] = new PropertyValue();
lParams[0].Name = "nodepath";
lParams[0].Value = "/";

Object xAccess = xConfigProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationUpdateAccess" , lParams);

XNameAccess xNameAccess = (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xAccess);

解决方案

简单的解决方案是仅删除软件包Zip中的settings.xml部分.这些都是与实现有关的材料,对于您生成的文档来说无关紧要.

如果您担心它仍在清单中,尽管不在软件包中,则可以选择用标准的创建内容替换settings.xml来支持该模式,这是完成该过程的最基本要求. /p>

请注意,在某些情况下,openoffice/libreoffice的不同运行可能会将不同的UUID和基于UIID的标识符嵌入到content.xml和程序包部件的名称中.看来您通过API生成的代码不会导致任何此类情况.

I am generating ODT documents using the openoffice/libreoffice API, and I want the files to come out to be 100% identical every time (by MD5 comparison).

At this point I can unzip the two files generated at different times and check all the files within the zip file and they all match 100%, except for the Settings.xml which has two unique differences (both RSID related).

<config:config-item config:name="Rsid" config:type="int">1835643</config:config-item>

and

<config:config-item config:name="RsidRoot" config:type="int">1835643</config:config-item>

I learned this is for the purpose of merging and tracking back to the original document, but I want them to be a fixed value that I control, as I don't plan to merge these anyway, but I can't locate where to set these properties.

I have tried a few options (below) and outputting the properties, but been unable to find it so far. Is there a way to override the RSID, without me (coding) unzipping the file, and modifying the XML, which I have done for now, but feels a bit awkward so still looking for this.

// Looking for RSID in all the wrong places - test 1
XPropertySet xSettings = (XPropertySet) xRemoteServiceManager.createInstanceWithContext("com.sun.star.document.Settings", componentContext);

// Looking for RSID in all the wrong places - test 2
Object configProvider = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", componentContext);
XMultiServiceFactory xConfigProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, configProvider);

PropertyValue[] lParams = new PropertyValue[1];

lParams[0] = new PropertyValue();
lParams[0].Name = "nodepath";
lParams[0].Value = "/";

Object xAccess = xConfigProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationUpdateAccess" , lParams);

XNameAccess xNameAccess = (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xAccess);

解决方案

The simple solution is to simply delete the settings.xml part in the package Zip. This is all implementation-dependent material and it should not matter for a document you are generating.

If you are concerned that it is still in the manifest, although not in the package, an alternative is to replace settings.xml with a standard one of your creation that honors the schema and is the least needed to accomplish that.

Note that there are conditions under which different runs of openoffice/libreoffice may embed different UUIDs and UIID-based identifiers in the content.xml and in the names of package parts. It appears that your generation via the API does not lead to any of those.

这篇关于如何使用API​​覆盖ODF根RSID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆