简体   繁体   English

在OSX上打开WebDAV word文件

[英]Open WebDAV word file on OSX

I have a Java application that opens WebDAV files on MS Word. 我有一个Java应用程序,可以在MS Word上打开WebDAV文件。 This works successfully on Windows with the next code: 使用下一个代码在Windows上成功运行:

Runtime.getRuntime().exec("cmd /c start winword " + webdavUrl);

But on Mac OSX this is not possible. 但在Mac OSX上,这是不可能的。 I tried this function, but it only opens a blank document: 我试过这个功能,但它只打开一个空白文件:

Runtime.getRuntime().exec(new String[]{"open", "-a", "Microsoft Word", webdavUrl});

if I create a file from the URL, I can open the file but I lose its reference to the WebDav URL. 如果我从URL创建一个文件,我可以打开该文件,但我失去了对WebDav URL的引用。

I have found a discussion about a javascript code that can do this process from the browser. 我找到了一个关于可以从浏览器执行此过程的JavaScript代码的讨论

Any thoughts? 有什么想法吗?

First, can you access the directory where the word doc is? 首先,您可以访问doc这个词的目录吗? are you mounting your webdav? 你正在安装你的webdav?

I believe the terminal will be looking for a path, which is your webdavUrl. 我相信终端将寻找一条路径,这是你的webdavUrl。 To debug, try running the same command but only with the -R and webdavUrl arguments. 要进行调试,请尝试运行相同的命令,但只能使用-R和webdavUrl参数。

Runtime.getRuntime().exec(new String[]{"open", "-R", webdavUrl});

-R will show the file in finder and this way you know that terminal can in fact navigate to your webdavUrl. -R将在finder中显示该文件,这样您就知道该终端实际上​​可以导航到您的webdavUrl。

You may try one of the following: 您可以尝试以下方法之一:

1 : Use the Desktop Api as described here . 1 :使用此处所述的桌面Api。

File myFile = new File(webdavUrl);
Desktop.getDesktop().open(myFile);

2 : Use ms-word: uri as detailed here . 2 :使用ms-word: uri,详见此处

For example enter "ms-word:ofe|u|http://webdavUrl" on your browser. 例如,在浏览器中输入"ms-word:ofe|u|http://webdavUrl" If you have Microsoft Office (2010 SP2+) installed this should open the word application with your document loaded. 如果您安装了Microsoft Office(2010 SP2 +),则应在加载文档时打开应用程序一词。

The following resources might be helpful as they cover different ways you could open/edit word files in a webdav server. 以下资源可能会有所帮助,因为它们涵盖了在webdav服务器中打开/编辑word文件的不同方法。

After almost 4 weeks of investigation, I succesfully developed a solution for this problem: 经过近4周的调查,我成功地为此问题开发了一个解决方案:

  1. First, on the server side, create an end-point to open the word document with the IT HIT's javascript library . 首先,在服务器端,创建一个端点,用IT HIT的javascript 打开word文档。 This library uses the Sharepoint Browser Plugin to open the document on Word 2011 for Mac OSX with the Webdav protocol. 此库使用Sharepoint浏览器插件使用Webdav协议在Word 2011 for Mac OSX上打开文档。
  2. Now on java, use the console to open Safari with the end-point URL to open the word document. 现在在java上,使用控制台打开带有端点URL的Safari以打开word文档。 For this, maybe you need to pass the document's URL as param for the end-point. 为此,您可能需要将文档的URL作为端点的参数传递。

     Runtime.getRuntime().exec(new String[]{"open", "-a", "Safari", getWebdavUrl(document)}); private static String getWebdavUrl(Document document) throws JSONException, UnsupportedEncodingException { RestClient client = RestClient.getClient(); String baseUrl = client.SERVER_URL + "webdav_end_point"; JSONObject params = new JSONObject(); params.put("url", document.getUrl()); //convert the JSON params to GET params for the URL String url = baseUrl + RestClient.buildParamsString(params); //https://wwww.example.com/webdav_end_point?url=www.example.com/path/to/webdav/document.docx return url; } 

This allows to open the document on Word 2011 for MAC OSX, but you have to deal with the security and the user session if you have restrictions on the document edition. 这允许在Word 2011上为MAC OSX打开文档,但如果您对文档版本有限制,则必须处理安全性和用户会话。 Anyway, I implemented this solution succesfully and it is the only solution I found that completes the process. 无论如何,我成功地实现了这个解决方案,这是我发现完成整个过程的唯一解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM