Loic, As you can see in my second snippet, I used Reference.encode helper class to encode the url (which use URLEncoder), but it seems that the Reference does not recognize the encoded path as an absolute path, as described in the exception.
Regards Stephane On Tue, Jun 3, 2008 at 11:09 AM, <[EMAIL PROTECTED]> wrote: > Hello, > > You need to encode your URL because the space are not valid character for a > URL. (space needs to become %20), I think their is an existing helper class > that can help you in the restlety API or check jakarta commons-net. > > Regards, > > Loïc > > ------------------------------ > *From:* Stephane Fellah [mailto:[EMAIL PROTECTED] > *Sent:* 03 June 2008 17:06 > *To:* [email protected] > *Subject:* Handling of file path with space in Reference > > > Hi, > > I am trying to create a Directory using a path with some space character in > it. Here a sample code: > > public static void main(String[] args) throws MalformedURLException { > String path = "C:\\Program Files\\Apache Software > Foundation\\Tomcat 5.5\\webapps\\mywebapp\\"; > System.out.println("Path: "+path); > URL url = new File(path).toURL(); > System.out.println("File URL: "+url); > Directory d = new Directory(new Context(),url.toString()); > System.out.println(d); > } > > > Here the output and exception I get: > > Path: C:\Program Files\Apache Software Foundation\Tomcat > 5.5\webapps\mywebapp\ > > File URL: file:/C:/Program Files/Apache Software Foundation/Tomcat > 5.5/webapps/mywebapp > > Exception in thread "main" java.lang.IllegalArgumentException: Invalid > character detected in URI reference at index '16': " " > at org.restlet.data.Reference.checkValidity(Reference.java:666) > at org.restlet.data.Reference.<init>(Reference.java:531) > at org.restlet.data.Reference.<init>(Reference.java:562) > at org.restlet.Directory.<init>(Directory.java:142) > at > com.usersmarts.ksb.services.servlet.TestReference.main(TestReference.java:27) > > I tried to encode the URL by doing using the Reference.encode or URLEncoder > > public static void main(String[] args) throws MalformedURLException { > String path = "C:\\Program Files\\Apache Software > Foundation\\Tomcat 5.5\\webapps\\mywebapp\\"; > System.out.println("Path"+path); > URL url = new File(path).toURL(); > System.out.println("File URL"+url); > System.out.println("Encoded > reference:"+Reference.encode(url.toString())); > Directory d = new Directory(new > Context(),Reference.encode(url.toString())); > System.out.println(d); > } > > > Path: C:\Program Files\Apache Software Foundation\Tomcat > 5.5\webapps\mywebapp\ > File URL: file:/C:/Program Files/Apache Software Foundation/Tomcat > 5.5/webapps/mywebapp > Encoded reference: > file%3A%2FC%3A%2FProgram+Files%2FApache+Software+Foundation%2FTomcat+5.5%2Fwebapps%2Fmywebapp > Exception in thread "main" java.lang.IllegalArgumentException: Relative > references are only usable when a base reference is set. > at org.restlet.data.Reference.getTargetRef(Reference.java:1674) > at org.restlet.Directory.<init>(Directory.java:104) > at org.restlet.Directory.<init>(Directory.java:142) > at > com.usersmarts.ksb.services.servlet.TestReference.main(TestReference.java:23) > > I cannot see what is wrong here. Could you help. > > Thanks in advance. > > Stephane Fellah > Senior Software Engineer > Image Matters LLC > > > > > **** DISCLAIMER **** > http://www.belgacom.be/maildisclaimer >

