 | OO-Snippets: Create UNO compatible URLCommons| Keywords | URL, UNO, File, file:/// |
|---|
| Language | Java |
|---|
| Application | Office |
|---|
| Authors | Tobias Krais
|
|---|
| Supported Versions | 2.0.x 1.1.x |
|---|
| Supported OS | All |
|---|
| Question | How to create a URL that is usable by UNO from a normal file location
Normal file locations are e.g.:
for Linux/UNIX: "/tmp/myDocument.odt"
for Windows: "C:\myFolder\myDocument"
But UNO needs this (e.g. for Linux) "file:///tmp/myDocument.odt".
The code below explains how to solve this in Java
|
|---|
| Answer | |
|---|
Creating a correct File URL that OpenOffice can handle.
@param filelocation
@return
public String createUNOFileURL(String filelocation)
{
java.io.File newfile = new java.io.File(filelocation);
java.net.URL before = null;
try
{
before = newfile.toURL();
}
catch (MalformedURLException e) {
System.out.println(e);
}
String myUNOFileURL = com.sun.star.uri.ExternalUriReferenceTranslator
.create(xRemoteContext).translateToInternal(before.toExternalForm());
if (myUNOFileURL.length() == 0 && filelocation.length() > 0)
{
System.out.println("File URL conversion faild. Filelocation " +
"contains illegal characters: " + filelocation);
}
return myUNOFileURL;
}
|
Changelog| Date | User | Modification |
|---|
| 2006-03-27 | tobiaskrais | Initial version |
|