org.apache.cocoon.util
Class NetUtils

java.lang.Object
  extended byorg.apache.cocoon.util.NetUtils

public class NetUtils
extends Object

A collection of File, URL and filename utility methods

Version:
$Id: NetUtils.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Constructor Summary
NetUtils()
           
 
Method Summary
static String absolutize(String path, String resource)
          Absolutize a relative resource path on the given absolute base path.
static String decode(String s, String enc)
          Pass through to the URLDecoder.
static String decodePath(String path)
          Decode a path.
static String deparameterize(String uri, Map parameters)
          Remove parameters from a uri.
static String encode(String s, String enc)
          Pass through to the URLEncoder.
static String encodePath(String path)
          Encode a path as required by the URL specification ( RFC 1738).
static String getExtension(String uri)
          Remove path and file information from a filename returning only its extension component
static String getPath(String uri)
          Returns the path of the given resource.
static String normalize(String uri)
          Normalize a uri containing ../ and ./ paths.
static String parameterize(String uri, Map parameters)
          Add parameters stored in the Map to the uri string.
static String relativize(String path, String absoluteResource)
          Relativize an absolute resource on a given absolute path.
static String removeAuthorisation(String uri)
          Remove any authorisation details from a URI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetUtils

public NetUtils()
Method Detail

decodePath

public static String decodePath(String path)
Decode a path.

Interprets %XX (where XX is hexadecimal number) as UTF-8 encoded bytes.

The validity of the input path is not checked (i.e. characters that were not encoded will not be reported as errors).

This method differs from URLDecoder.decode in that it always uses UTF-8 (while URLDecoder uses the platform default encoding, often ISO-8859-1), and doesn't translate + characters to spaces.

Parameters:
path - the path to decode
Returns:
the decoded path

encodePath

public static String encodePath(String path)
Encode a path as required by the URL specification ( RFC 1738). This differs from java.net.URLEncoder.encode() which encodes according to the x-www-form-urlencoded MIME format.

Parameters:
path - the path to encode
Returns:
the encoded path

getPath

public static String getPath(String uri)
Returns the path of the given resource.

Parameters:
uri - The URI of the resource
Returns:
the resource path

getExtension

public static String getExtension(String uri)
Remove path and file information from a filename returning only its extension component

Parameters:
uri - The filename
Returns:
The filename extension (with starting dot!) or null if filename extension is not found

absolutize

public static String absolutize(String path,
                                String resource)
Absolutize a relative resource path on the given absolute base path.

Parameters:
path - The absolute base path
resource - The relative resource path
Returns:
The absolutized resource path

relativize

public static String relativize(String path,
                                String absoluteResource)
Relativize an absolute resource on a given absolute path.

Parameters:
path - The absolute path
absoluteResource - The absolute resource
Returns:
the resource relative to the given path

normalize

public static String normalize(String uri)
Normalize a uri containing ../ and ./ paths.

Parameters:
uri - The uri path to normalize
Returns:
The normalized uri

deparameterize

public static String deparameterize(String uri,
                                    Map parameters)
Remove parameters from a uri. Passed in parameters map will be populated with parameter names as keys and parameter values as map values. Values are of type String array (similarly to ServletRequest).

Parameters:
uri - The uri path to deparameterize.
parameters - The map that collects parameters.
Returns:
The cleaned uri

parameterize

public static String parameterize(String uri,
                                  Map parameters)
Add parameters stored in the Map to the uri string. Map can contain Object values which will be converted to the string, or Object arrays, which will be treated as multivalue attributes.

Parameters:
uri - The uri to add parameters into
parameters - The map containing parameters to be added
Returns:
The uri with added parameters

removeAuthorisation

public static String removeAuthorisation(String uri)
Remove any authorisation details from a URI


encode

public static String encode(String s,
                            String enc)
                     throws UnsupportedEncodingException
Pass through to the URLEncoder. If running under JDK < 1.4, default encoding will always be used.

Throws:
UnsupportedEncodingException

decode

public static String decode(String s,
                            String enc)
                     throws UnsupportedEncodingException
Pass through to the URLDecoder. If running under JDK < 1.4, default encoding will always be used.

Throws:
UnsupportedEncodingException


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.