incubator-ooo-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 120273] Can not open a file in UNO mode, if there is a "%" in file name
Date Sat, 14 Jul 2012 00:43:32 GMT
https://issues.apache.org/ooo/show_bug.cgi?id=120273

--- Comment #8 from ChaoHuang <chao.dev.h@gmail.com> ---
(In reply to comment #6)
> (In reply to comment #4)
> > My question is that how can I convert "file:///d:/convert/h%e%l%l%o.odt"
> > into "file:///D:/convert /h%25e%25l%25l%25o.odt". I have hundreds of files
> > which hold "%" in the name. It is impossible for me to correct the name
> > manually one by one. Any suggestion? Thanks!
> 
> 
> You can use
> http://www.openoffice.org/api/docs/common/ref/com/sun/star/ucb/
> XFileIdentifierConverter.html#getFileURLFromSystemPath
> 
> 
> 
>     public static String convertToURL(
>                                         XComponentContext xContext,
>                                         String sBase,
>                                         String sSystemPath) {
>         String sURL = null;
>         try {
>             com.sun.star.ucb.XFileIdentifierConverter xFileConverter =
>                     (com.sun.star.ucb.XFileIdentifierConverter)
> UnoRuntime.queryInterface(
>                     com.sun.star.ucb.XFileIdentifierConverter.class,
>                     xContext.getServiceManager().createInstanceWithContext(
>                     "com.sun.star.ucb.FileContentProvider", xContext));
>             sURL = xFileConverter.getFileURLFromSystemPath(
>                     sBase, sSystemPath);
>         } catch (java.lang.Exception e) {
>             e.printStackTrace();
>         } finally {
>             return sURL;
>         }
>     }
> 
> Usage:
> 
> String sURL = convertToURL(xContext, "", "D:\convert\h%25e%25l%25l%25o.odt");

Another simple way to convert path to url :
   File aFile = new File("d:/convert/h%e%l%l%o.odt");
   String aUrl = aFile.toURI().toString();

The result is "file:/D:/convert/h%25e%25l%25l%25o.odt", which is close to the
target. But need to add two slashes ("//") after "file:/" .

-- 
You are receiving this mail because:
You are the assignee for the bug.

Mime
View raw message