简体   繁体   中英

Open WebDAV word file on OSX

I have a Java application that opens WebDAV files on MS Word. This works successfully on Windows with the next code:

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

But on Mac OSX this is not possible. 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.

I have found a discussion about a javascript code that can do this process from the browser.

Any thoughts?

First, can you access the directory where the word doc is? are you mounting your webdav?

I believe the terminal will be looking for a path, which is your webdavUrl. To debug, try running the same command but only with the -R and webdavUrl arguments.

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.

You may try one of the following:

1 : Use the Desktop Api as described here .

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

2 : Use ms-word: uri as detailed here .

For example enter "ms-word:ofe|u|http://webdavUrl" on your browser. If you have Microsoft Office (2010 SP2+) installed this should open the word application with your document loaded.

The following resources might be helpful as they cover different ways you could open/edit word files in a webdav server.

After almost 4 weeks of investigation, I succesfully developed a solution for this problem:

  1. First, on the server side, create an end-point to open the word document with the IT HIT's javascript library . This library uses the Sharepoint Browser Plugin to open the document on Word 2011 for Mac OSX with the Webdav protocol.
  2. Now on java, use the console to open Safari with the end-point URL to open the word document. For this, maybe you need to pass the document's URL as param for the end-point.

     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. Anyway, I implemented this solution succesfully and it is the only solution I found that completes the process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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