Hi Emily; My main input is to add to URLUtilsTest; you are on the right track.
I did not write the URLUtils methods ... Andrea had the sugestions of ussing commonsio (which also has functions for handling paths and so on). When I went to look commonsio had deprecated all their file handling code asking people to instead use the file objects from Java directly (ie do not treat file paths as a strings as you will always screw it up). With that advise in mind I would like to "rewrite" URLUtils; in particular the relative path handling code; during the last sprint it was easier to just kludge on extra test cases; however the result is now that the catalog will not load :-( Jody On Thu, Apr 23, 2009 at 4:17 AM, Emily Gouge <[email protected]> wrote: > So looking into the problem with spaces in filename and restarting udig it > seems that this might be an issue with the constructURL function in > URLUtils. > > I can fix the issue by changing line 242 from > > File tmp = new File(base.getParentFile(), substring); > > to > > File tmp = new File(base.getParentFile(), file.getPath()); > > but I'm not sure what other impacts this might have. I'm not sure what the > purpose of "substring" is. Anyone have any input for me? > > Emily > > Emily Gouge wrote: >> >> Okay, so it seems to me there are at least two places where updates need >> to be made. >> >> 1) FileConnectionPage.java >> >> Line 312 needs to be changed from >> URL url = new File(path + System.getProperty("file.separator") + >> filenames[i]).toURL(); >> >> to >> >> URL url = new File(path + System.getProperty("file.separator") + >> filenames[i]).toURI().toURL(); >> >> 2) CatalogImportDropAction.java >> Line 154 (the try statement) needs to be updated to use the URLUtils >> function. I'm not so sure about this update though. >> >> Change: >> String string = "file:" + line; >> result = new URL(string); >> >> To: >> result = URLUtils.fileToURL(new File(line)); >> >> >> These changes allow me to load a shapefile that has spaces in the path >> name. If they seem okay I can commit them. >> >> However they do not fix the error that occurs when udig is restarted. When >> you restart udig the files are not found. I will look into that and see if >> I can find out anything interesting. >> >> Emily >> >> >> >> Jody Garnett wrote: >>> >>> Hi Emily; I am madly trying to hook up the ID class since I am sick of >>> all these path based issues in our code base. >>> >>>> >>>> net.refractions.udig.catalog.internal.shp.ShpGeoResourceImpl.<init>(ShpGeoResourceImpl.java:75) >>>> at >>>> >>>> net.refractions.udig.catalog.internal.shp.ShpServiceImpl.resources(ShpServiceImpl.java:177) >>>> ... >>> >>> So why is the ID class being created with null? >>> >>>> From what I can tell this boils down to the ID.java class. >>>> >>>> public ID( URL url ){ >>>> >>>> this.url = url; >>>> try { >>>> this.uri = url.toURI(); >>>> } catch (URISyntaxException e) { >>>> } >>>> >>>> >>>> this.uri = url.toURI() -> this throws an exception and thus uri is null. >>>> I >>>> believe this is the source of the null pointer exception above. >>> >>> I agree; now I wonder why the provided url is null? >>> >>>> From experimenting: >>>> >>>> If you have a url with spaces: >>>> url = new URL("file:/C:/temp/habc poa/my border.shp"); >>>> >>>> You cannot convert it to a URI without an error. >>> >>> That would probably be correct; since " " is not valid in a URL; can >>> we detect where in the code this is happening? >>> >>>> However if you encode the spaces in this url everything is okay. >>>> url = new URL("file:/C:/temp/habc%20poa/my%20border.shp"); >>>> >>>> Is there some way we can encode the url's that have spaces so we can >>>> properly create uri's out of them? >>> >>> Richard made a URLUtils class that handles these cases (I added a test >>> case based on a File with spaces; but not for a URL with spaces). All >>> our code should be using this URLUtils; so it is my hope we can use >>> the debugger to find a case where this is not being called. Use of >>> this class is covered in the udig coding conventions: >>> - http://udig.refractions.net/confluence/display/DEV/5+Coding+Conventions >>> >>> Jody >>> _______________________________________________ >>> User-friendly Desktop Internet GIS (uDig) >>> http://udig.refractions.net >>> http://lists.refractions.net/mailman/listinfo/udig-devel >> >> _______________________________________________ >> User-friendly Desktop Internet GIS (uDig) >> http://udig.refractions.net >> http://lists.refractions.net/mailman/listinfo/udig-devel > > _______________________________________________ > User-friendly Desktop Internet GIS (uDig) > http://udig.refractions.net > http://lists.refractions.net/mailman/listinfo/udig-devel > _______________________________________________ User-friendly Desktop Internet GIS (uDig) http://udig.refractions.net http://lists.refractions.net/mailman/listinfo/udig-devel
