Menu

#3 file: URI handling broken on Windows systems

open
nobody
None
5
2005-05-12
2005-05-12
No

I've been trying to use a version of JpegRDF on Windows
[[
/**
* The main application class.
*
* @author Norman Walsh
* @version $Revision: 1.7 $
*/
public class JpegRDF implements ArgumentTaker {

public static String version = "2.1.0";
]]
with Jena:
[[
public static final String VERSION = "2.2-beta-2";
]]

and have found that file: URIs created by simply
prepending file:// to the filename cause Jena to choke
with an invalid URI exception.

To remedy this, I've added new methods in my copy of
RDFkit:
[[
/**
* Get current working directory as a URI.
*/
public static String uriFromCwd()
{
String cwd = System.getProperty("user.dir");
return uriFromFilename( cwd ) + "/" ;
}

/**
* Convert File descriptor string to a URI.
*/
public static String uriFromFile(
File filespec)
{
return uriFromFilename(
filespec.getAbsolutePath() ) ;
}

/**
* Convert filename string to a URI.
* Map '\' characters to '/' (this might break if
'\' is used in
* a Unix filename, but this is assumed to be a
very rare occurrence
* as '\' is often used with special meaning on Unix.)
* For unix-like systems, the absolute filename
begins with a '/'
* and is preceded by "file://".
* For other systems an extra '/' must be supplied.
*/
public static String uriFromFilename(
String filename)
{
StringBuffer mapfilename = new StringBuffer(
filename ) ;
for ( int i = 0 ; i < mapfilename.length() ; i++ )
{
if ( mapfilename.charAt(i) == '\\' )
mapfilename.setCharAt(i, '/') ;
}
if (filename.charAt(0) == '/')
{
return "file://"+mapfilename.toString() ;
}
else
{
return "file:///"+mapfilename.toString() ;
}
}
]]

and changed all occurrences of prepending "file://" to
a call of a corresponding function here. This
overcomes the problem I was experiencing, though there
are others (a topic for another message).

I attach my modified copies of JPegRDF.java and
RDFKit.java.

Discussion

  • Graham Klyne

    Graham Klyne - 2005-05-12

    RDFkit with file->URI functions added

     
  • Graham Klyne

    Graham Klyne - 2005-05-12

    Logged In: YES
    user_id=168177

    And my modifed JpegRDF.java file...