OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

URL to path in Java

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
zaphod
Power User
Power User


Joined: 04 Nov 2004
Posts: 51
Location: Magdeburg, Germany

PostPosted: Wed Feb 08, 2006 3:43 am    Post subject: URL to path in Java Reply with quote

When I try to get a directory or file with the UNO API, I get a String in the format of an UNO URL (e.g. with the code at the bottom). But what I want is the (absolute)path and not the Uno URL. In Basic there are the functions ConvertToURL(<path>), which converts the path like "C:\User abc\bla.sxw" to the appropriate "file:///..." and ConvertFromURL(<url>) to transforms it back again. In CPP there is the class osl::FileBase as the appropriate counterpart.

Is it possible to get the same functionality with the Java API?

Code:
Object obj = getServiceManager().createInstanceWithContext("com.sun.star.util.PathSettings", context);
XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, obj);
String sPath = ((String) xPropertySet.getPropertyValue("UserConfig"));
//
//sPath Linux.....: file:///home/arthur/.openoffice.org2/user/config
//sPath Windows: file:///C:/Dokumente%20und%20Einstellungen/pc/Anwendungsdaten/OpenOffice.org2/user/config
Back to top
View user's profile Send private message
bolekovnik
General User
General User


Joined: 24 Jan 2006
Posts: 20

PostPosted: Fri Feb 10, 2006 9:08 am    Post subject: Reply with quote

Hi!

Maybe this piece of code can bring you on the right way:

Code:

private static String APPLICATION_DIRECTORY = "file:///"+System.getProperty( "user.dir" ).replace( '\\', '/' );


Cheers!
Back to top
View user's profile Send private message
Lew Wadoo
General User
General User


Joined: 05 Jul 2009
Posts: 7
Location: Russia, Moscow

PostPosted: Tue Jun 19, 2012 10:36 pm    Post subject: Re: URL to path in Java Reply with quote

zaphod wrote:
When I try to get a directory or file with the UNO API, I get a String in the format of an UNO URL (e.g. with the code at the bottom). But what I want is the (absolute)path and not the Uno URL. In Basic there are the functions ConvertToURL(<path>), which converts the path like "C:\User abc\bla.sxw" to the appropriate "file:///..." and ConvertFromURL(<url>) to transforms it back again. In CPP there is the class osl::FileBase as the appropriate counterpart.

Is it possible to get the same functionality with the Java API?

The method getPath() returns the decoded path of the URI.
Try this code:
Code:

   public String decodePath(URI uriFile) {
      return uriFile.getPath();
      
   }
   
   public URI convertStringToUri(String sURI) {
      URI uriFile = null;
      try {
         uriFile = new URI(sURI);
      } catch (URISyntaxException e) {
         e.printStackTrace();
      }
      
      return uriFile;
   }

   private void test() {
      URI uriFile = convertStringToUri("file:///C:/Dokumente%20und%20Einstellungen/pc/Anwendungsdaten/OpenOffice.org2/user/config");
      String sDecodedPath = decodePath(uriFile);
   }
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group