/** Convert a file: IRI to a filename */ public static String IRIToFilename(String iri) { if ( ! iri.startsWith("file:") ) throw new AtlasException("Not a file: URI: "+iri) ; String fn ; if ( iri.startsWith("file:///") ) fn = iri.substring("file://".length()) ; else fn = iri.substring("file:".length()) ; // MS Windows: we can have // file:///C:/path or file:/C:/path // At this point, we have a filename of /C:/ // so need strip the leading "/" fn = fixupWindows(fn); return decode(fn) ; }
/** Convert a file: IRI to a filename */ public static String IRIToFilename(String iri) { if ( ! iri.startsWith("file:") ) throw new AtlasException("Not a file: URI: "+iri) ; String fn ; if ( iri.startsWith("file:///") ) fn = iri.substring("file://".length()) ; else fn = iri.substring("file:".length()) ; // MS Windows: we can have // file:///C:/path or file:/C:/path // At this point, we have a filename of /C:/ // so need strip the leading "/" fn = fixupWindows(fn); return decode(fn) ; }
/** Convert a plain file name (no file:) to a file: URL */ private static String plainFilenameToURL(String fn) { // No "file:" // Make Absolute filename. boolean trailingSlash = fn.endsWith("/") ; // To get Path.toAbsolutePath to work, we need to convert /C:/ to C:/ // then back again. fn = fixupWindows(fn) ; fn = Paths.get(fn).toAbsolutePath().normalize().toString() ; if ( trailingSlash && ! fn.endsWith("/") ) fn = fn + "/" ; if ( Sys.isWindows ) { // C:\ => file:///C:/... if ( windowsDrive(fn, 0) ) // Windows drive letter - already absolute path. // Make "URI" absolute path fn = "/"+fn ; // Convert \ to / // Maybe should do this on all platforms? i.e consistency. fn = fn.replace('\\', '/' ) ; } fn = encodeFileURL(fn) ; return "file://"+fn ; }
/** Convert a plain file name (no file:) to a file: URL */ private static String plainFilenameToURL(String fn) { // No "file:" // Make Absolute filename. boolean trailingSlash = fn.endsWith("/") ; // To get Path.toAbsolutePath to work, we need to convert /C:/ to C:/ // then back again. fn = fixupWindows(fn) ; fn = Paths.get(fn).toAbsolutePath().normalize().toString() ; if ( trailingSlash && ! fn.endsWith("/") ) fn = fn + "/" ; if ( Sys.isWindows ) { // C:\ => file:///C:/... if ( windowsDrive(fn, 0) ) // Windows drive letter - already absolute path. // Make "URI" absolute path fn = "/"+fn ; // Convert \ to / // Maybe should do this on all platforms? i.e consistency. fn = fn.replace('\\', '/' ) ; } fn = encodeFileURL(fn) ; return "file://"+fn ; }