Update of /var/cvs/src/org/mmbase/util In directory james.mmbase.org:/tmp/cvs-serv24631
Modified Files: UriParser.java Log Message: added method to be able to use it on one filesystem against another with different path seperators, some debug. See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util Index: UriParser.java =================================================================== RCS file: /var/cvs/src/org/mmbase/util/UriParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -b -r1.3 -r1.4 --- UriParser.java 30 Sep 2004 17:19:50 -0000 1.3 +++ UriParser.java 5 Feb 2009 08:44:47 -0000 1.4 @@ -19,23 +19,27 @@ * * @author Michiel Meeuwissen * @since MMBase-1.7 - * @version $Id: UriParser.java,v 1.3 2004/09/30 17:19:50 pierre Exp $ + * @version $Id: UriParser.java,v 1.4 2009/02/05 08:44:47 andre Exp $ */ public class UriParser { private static final Logger log = Logging.getLoggerInstance(UriParser.class); + final static char SEPARATOR = java.io.File.separator.charAt(0); // '\' for windows '/' for other oses. - final static char separatorChar = java.io.File.separator.charAt(0); // '\' for windows '/' for other oses. + static public String makeRelative(final String basePath, final String path) { + return makeRelative(basePath, path, SEPARATOR); + } /** - * Converts an absolute path into a relative path. + * Converts an absolute path into a relative path, being a path relative to basePath. * * @param basePath The base path. - * @param path The path to convert. + * @param path The path to convert against basePath. */ - static public String makeRelative(final String basePath, final String path ) { + static public String makeRelative(final String basePath, final String path, final char separatorChar) { if (log.isDebugEnabled()) { - log.debug("converting " + path + " relative to " + basePath); + log.debug("converting: " + path); + log.debug("relative to: " + basePath); } // Calculate the common prefix final int basePathLen = basePath.length(); @@ -69,18 +73,15 @@ buffer.append( path.substring( pos ) ); } - // Prepend a '../' for each element in the base path past the common - // prefix + // Prepend a '../' for each element in the base path past the common prefix buffer.insert( 0, ".." ); pos = basePath.indexOf( separatorChar, pos + 1 ); while ( pos != -1 ) { buffer.insert( 0, "../" ); pos = basePath.indexOf( separatorChar, pos + 1 ); } - if (log.isDebugEnabled()) { - log.debug("is: " + buffer); - } + if (log.isDebugEnabled()) log.debug("is: " + buffer); return buffer.toString(); } } _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs