/** Sanitize a "file:" URL. Must start "file:" */ private static String normalizeFilenameURI(String fn) { if ( ! fn.startsWith("file:/") ) { // Relative path. String fn2 = fn.substring("file:".length()) ; return plainFilenameToURL(fn2) ; } // Starts file:// or file:/// if ( fn.startsWith("file:///") ) // Assume it's good and return as-is. return fn ; if ( fn.startsWith("file://") ) { // file: URL with host name (maybe!) return fn ; } // Must be file:/ String fn2 = fn.substring("file:".length()) ; return plainFilenameToURL(fn2) ; }
/** Sanitize a "file:" URL. Must start "file:" */ private static String normalizeFilenameURI(String fn) { if ( ! fn.startsWith("file:/") ) { // Relative path. String fn2 = fn.substring("file:".length()) ; return plainFilenameToURL(fn2) ; } // Starts file:// or file:/// if ( fn.startsWith("file:///") ) // Assume it's good and return as-is. return fn ; if ( fn.startsWith("file://") ) { // file: URL with host name (maybe!) return fn ; } // Must be file:/ String fn2 = fn.substring("file:".length()) ; return plainFilenameToURL(fn2) ; }
/** Create a string that is a IRI for the filename. * <li>The file name may already have {@code file:}. * <li>The file name may be relative. * <li>Encode using the rules for a path (e.g. ':' and'/' do not get encoded) * <li>Non-IRI characters get %-encoded. */ public static String filenameToIRI(String fn) { if ( fn == null ) return cwdURL ; if ( fn.length() == 0 ) return cwdURL ; if ( fn.startsWith("file:") ) return normalizeFilenameURI(fn) ; return plainFilenameToURL(fn) ; }
/** Create a string that is a IRI for the filename. * <li>The file name may already have {@code file:}. * <li>The file name may be relative. * <li>Encode using the rules for a path (e.g. ':' and'/' do not get encoded) * <li>Non-IRI characters get %-encoded. */ public static String filenameToIRI(String fn) { if ( fn == null ) return cwdURL ; if ( fn.length() == 0 ) return cwdURL ; if ( fn.startsWith("file:") ) return normalizeFilenameURI(fn) ; return plainFilenameToURL(fn) ; }