sk.baka.tools
Class UrlUtils

java.lang.Object
  extended by sk.baka.tools.UrlUtils

public final class UrlUtils
extends Object

Contains tools for URLs.

Author:
Martin Vysny

Field Summary
static String FILE_URI_HIERARCHICAL_PREFIX
          A hierarchical URI file prefix: "file://".
static String FILE_URI_OPAQUE_PREFIX
          An opaque URI file prefix: "file:".
 
Method Summary
static Map<String,String> getQueryMap(String query)
          Splits the URL query string into a map of parameter name and value pairs.
static String normalizeSlashes(String fileName)
          Normalizes slashes in given string, i.e.
static String toLocalFile(String fileUri)
          Converts given file object to a local filesystem file with absolute path.
static String toUri(String fileUri)
          Converts given path to an URI if OS-dependent path is given.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_URI_OPAQUE_PREFIX

public static final String FILE_URI_OPAQUE_PREFIX
An opaque URI file prefix: "file:".

See Also:
Constant Field Values

FILE_URI_HIERARCHICAL_PREFIX

public static final String FILE_URI_HIERARCHICAL_PREFIX
A hierarchical URI file prefix: "file://".

See Also:
Constant Field Values
Method Detail

getQueryMap

public static Map<String,String> getQueryMap(String query)
Splits the URL query string into a map of parameter name and value pairs.

Parameters:
query - the query string, e.g. foo=bar&q=z, may be null - in this case an empty map is returned.
Returns:
the map which maps parameter name to the parameter value

toLocalFile

public static String toLocalFile(String fileUri)
Converts given file object to a local filesystem file with absolute path. Returns null if the file is not located on a local filesystem.

Parameters:
fileUri - the file to convert, in the URI format. WARNING: if given string is a local filesystem-dependent path then the function may return null.
Returns:
filesystem-dependent location of the file. null if given URL is not a local-filesystem URL.
Throws:
IllegalArgumentException - if the file is not located on the local filesystem.

toUri

public static String toUri(String fileUri)
Converts given path to an URI if OS-dependent path is given. Simply returns the string if an URI is given.

Parameters:
fileUri - the file name to convert, may be in the URI format or it may be a local filesystem reference.
Returns:
URI, never null

normalizeSlashes

public static String normalizeSlashes(String fileName)
Normalizes slashes in given string, i.e. backslashes are converted to forward slashes.

Parameters:
fileName - the file name to normalize
Returns:
name with backslashes converted to forward slashes.


Copyright © 2009-2010. All Rights Reserved.