从小程序启动 OpenOffice

发布于 2024-07-27 17:34:10 字数 2409 浏览 4 评论 0原文

我有这段代码,并且可以从命令行正常工作... 但是当我将其放入小程序中时,我收到以下错误

com.sun.star.lang.IllegalArgumentException 在 com.sun.star.comp.bridgefactory.BridgeFactory.createBridge(BridgeFactory.java:158) 在 com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:130)

有人有这个问题的解决方案吗? 在哪里可以找到 BridgeFactory 源代码?

   Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"); // oooUrlW - the url of soffice.exe
              Thread.sleep(5000);

              XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
              XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
              Object urlResolver  = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",xLocalContext);
              XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class,urlResolver);

              Object initialObject = xUnoUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
              XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,initialObject);
              XComponentContext remoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, xPropertySet.getPropertyValue("DefaultContext"));

              XMultiComponentFactory remoteServiceManager = remoteContext.getServiceManager();
              Object desktop = remoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext);

                 xDesktop =(XDesktop) UnoRuntime.queryInterface( XDesktop.class, desktop);
 XComponent xCalcComponent =
           newDocComponent(xDesktop, "scalc");
           XSpreadsheetDocument xCalcDocument =
                      (XSpreadsheetDocument)UnoRuntime.queryInterface(
                                           XSpreadsheetDocument.class, xCalcComponent);
           XSpreadsheets a=xCalcDocument.getSheets();
           Object o = a.getByName("Sheet1");

           XSpreadsheet sheet = (XSpreadsheet)UnoRuntime.queryInterface(
                    XSpreadsheet.class, o);


           XCell jjjj = sheet.getCellByPosition(0, 0);
           jjjj.setFormula("Some Text ");

I have this code down and this working fine from command line ...
But when I put this in applet I get following error

com.sun.star.lang.IllegalArgumentException
at com.sun.star.comp.bridgefactory.BridgeFactory.createBridge(BridgeFactory.java:158)
at
com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:130)

Anybody have solution for this problem ? Where I can find BridgeFactory source ?

   Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"); // oooUrlW - the url of soffice.exe
              Thread.sleep(5000);

              XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
              XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
              Object urlResolver  = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",xLocalContext);
              XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class,urlResolver);

              Object initialObject = xUnoUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
              XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,initialObject);
              XComponentContext remoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, xPropertySet.getPropertyValue("DefaultContext"));

              XMultiComponentFactory remoteServiceManager = remoteContext.getServiceManager();
              Object desktop = remoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext);

                 xDesktop =(XDesktop) UnoRuntime.queryInterface( XDesktop.class, desktop);
 XComponent xCalcComponent =
           newDocComponent(xDesktop, "scalc");
           XSpreadsheetDocument xCalcDocument =
                      (XSpreadsheetDocument)UnoRuntime.queryInterface(
                                           XSpreadsheetDocument.class, xCalcComponent);
           XSpreadsheets a=xCalcDocument.getSheets();
           Object o = a.getByName("Sheet1");

           XSpreadsheet sheet = (XSpreadsheet)UnoRuntime.queryInterface(
                    XSpreadsheet.class, o);


           XCell jjjj = sheet.getCellByPosition(0, 0);
           jjjj.setFormula("Some Text ");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

骷髅 2024-08-03 17:34:10

您的小程序是否已签名? 否则我认为你不能

Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");

从小程序中调用。

Is your applet signed ? else I don't think you can call

Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");

from an applet.

天暗了我发光 2024-08-03 17:34:10

我同意皮埃尔的观点......你需要一个受信任/签名的小程序来做到这一点。 您可能还想重新考虑为什么要尝试使用小程序而不是独立应用程序(如果需要网络交付,则使用 webstart 或其他应用程序)来执行此操作。

还要考虑的另一件事是,最终用户必须在本地安装 OpenOffice(除非他们更改了 API 的工作方式),才能使任何 Java-OO.o 访问正常工作。 不过这个要求可能已经改变了,我已经有一段时间没有使用他们的 API 了。

祝你好运,我希望这会有所帮助。

I agree with Pierre... you would need a trusted/signed applet to do that. You might also want to reconsider why you are trying to do this with an applet rather than a standalone application (using webstart or something if you need to web-deliverable).

One more thing to consider is that the end-user would have to have OpenOffice installed locally (unless they have changed the way their API works) for any Java-OO.o access to work correctly. This requirement may have changed though, it has been a while since I have played around with their API.

Good luck and I hope this helps a little.

沐歌 2024-08-03 17:34:10

它已签名,我找到了一种解决方案 - 在客户上我同意
permission java.security.AllPermission; 现在一切正常......
我仍然没有尝试授予 SignedBy "MyCompany" 权限 java.securyty.AllPermission
我必须这样做...

错误消息误导了我
com.sun.star.lang.IllegalArgumentException ...愚蠢的消息

我必须使用小程序...它是 Oracle Forms 应用程序,我需要在客户端上启动 Calc 并填充一些数据。

感谢帮助。

It is signed, and I found kind of solution - on client I grant
permission java.security.AllPermission; and now everything work...
I still did'nt try grant SignedBy "MyCompany" permission java.securyty.AllPermission
which I must do...

Error message is misleading me
com.sun.star.lang.IllegalArgumentException ... stupid message

I must use applet ... it is Oracle Forms application and I need to start Calc on client and fill some data.

Thanks on help.

德意的啸 2024-08-03 17:34:10

有一种非常简单的方法可以将 OOo 放入小程序中 - 使用 OfficeBean

虽然您仍然会遇到 Java 安全问题,但您的代码将会更加严格。 我们用它来做同样的事情。 我关于如何让 OO 3.2 在 Java 6 小程序中工作的帖子是 这里是你想看的。 它适用于 3.1 和 3.2。

There is a very simple way to place OOo in an applet - use the OfficeBean

While you'll still have your java security problem, your code will be a lot tighter. We're using this to do the same thing. My post on how to get OO 3.2 working in Java 6 applets is here is you want to take a look. It works for 3.1 and 3.2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文