org.apache.excalibur.source
Class SourceUtil

java.lang.Object
  extended byorg.apache.excalibur.source.SourceUtil

public final class SourceUtil
extends java.lang.Object

Utility class for source resolving.

Version:
CVS $Revision: 1.5 $ $Date: 2004/02/28 11:47:26 $
Author:
Avalon Development Team

Field Summary
static int AUTHORITY
           
static int FRAGMENT
           
static int PATH
           
static int QUERY
           
static int SCHEME
           
 
Constructor Summary
SourceUtil()
           
 
Method Summary
static java.lang.String absolutize(java.lang.String url1, java.lang.String url2)
          Calls absolutize(url1, url2, false).
static java.lang.String absolutize(java.lang.String url1, java.lang.String url2, boolean treatAuthorityAsBelongingToPath)
          Calls absolutize(url1, url2, false, true).
static java.lang.String absolutize(java.lang.String url1, java.lang.String url2, boolean treatAuthorityAsBelongingToPath, boolean normalizePath)
          Applies a location to a baseURI.
static java.lang.String appendParameters(java.lang.String uri, Parameters parameters)
          Append parameters to the uri.
static java.lang.String appendParameters(java.lang.String uri, SourceParameters parameters)
          Append parameters to the uri Each parameter is appended to the uri with "parameter=value", the parameters are separated by "&".
static void copy(java.io.InputStream in, java.io.OutputStream out)
          Copy the contents of an InputStream to an OutputStream.
static void copy(Source source, Source destination)
          Copy the source to a specified destination.
static java.lang.String decodePath(java.lang.String path)
          Decode a path.
static java.lang.String encode(java.lang.String s)
          Translates a string into x-www-form-urlencoded format.
static java.lang.String encode(java.lang.String s, java.lang.String enc)
          Translates a string into x-www-form-urlencoded format with specified encoding
static java.lang.String encodeBASE64(byte[] octetString)
          BASE 64 encoding.
static java.lang.String encodeBASE64(java.lang.String s)
          BASE 64 encoding.
static java.io.File getFile(Source source)
          Return a File object associated with the Source object.
static java.lang.String getScheme(java.lang.String uri)
          Get the scheme of an absolute URI.
static java.lang.String getSpecificPart(java.lang.String uri)
          Get the scheme-specific part of an absolute URI.
static int indexOfSchemeColon(java.lang.String uri)
          Get the position of the scheme-delimiting colon in an absolute URI, as specified by RFC 2396, appendix A.
static void move(Source source, Source destination)
          Move the source to a specified destination.
static java.lang.String[] parseUrl(java.lang.String url)
          Parses an URL into the following parts: scheme, authority, path, query and fragment identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCHEME

public static final int SCHEME
See Also:
Constant Field Values

AUTHORITY

public static final int AUTHORITY
See Also:
Constant Field Values

PATH

public static final int PATH
See Also:
Constant Field Values

QUERY

public static final int QUERY
See Also:
Constant Field Values

FRAGMENT

public static final int FRAGMENT
See Also:
Constant Field Values
Constructor Detail

SourceUtil

public SourceUtil()
Method Detail

appendParameters

public static java.lang.String appendParameters(java.lang.String uri,
                                                Parameters parameters)
Append parameters to the uri. Each parameter is appended to the uri with "parameter=value", the parameters are separated by "&".


appendParameters

public static java.lang.String appendParameters(java.lang.String uri,
                                                SourceParameters parameters)
Append parameters to the uri Each parameter is appended to the uri with "parameter=value", the parameters are separated by "&".


encodeBASE64

public static java.lang.String encodeBASE64(java.lang.String s)
BASE 64 encoding. See also RFC 1421


encodeBASE64

public static java.lang.String encodeBASE64(byte[] octetString)
BASE 64 encoding. See also RFC 1421


encode

public static java.lang.String encode(java.lang.String s)
Translates a string into x-www-form-urlencoded format.

Parameters:
s - String to be translated.
Returns:
the translated String.

encode

public static java.lang.String encode(java.lang.String s,
                                      java.lang.String enc)
                               throws java.io.UnsupportedEncodingException
Translates a string into x-www-form-urlencoded format with specified encoding

Parameters:
s - String to be translated.
enc - The name of a supported charset
Returns:
the translated String.
Throws:
java.io.UnsupportedEncodingException

getFile

public static java.io.File getFile(Source source)
Return a File object associated with the Source object.

Returns:
The corresponding File object or null if the Source object does not point to a file URI.

move

public static void move(Source source,
                        Source destination)
                 throws SourceException
Move the source to a specified destination.

Parameters:
source - Source of the source.
destination - Destination of the source.
Throws:
SourceException - If an exception occurs during the move.

indexOfSchemeColon

public static int indexOfSchemeColon(java.lang.String uri)
Get the position of the scheme-delimiting colon in an absolute URI, as specified by RFC 2396, appendix A. This method is primarily useful for Source implementors that want to separate the scheme part from the specific part of an URI.

Use this method when you need both the scheme and the scheme-specific part of an URI, as calling successively getScheme(String) and getSpecificPart(String) will call this method twice, and as such won't be efficient.

Parameters:
uri - the URI
Returns:
int the scheme-delimiting colon, or -1 if not found.

getScheme

public static java.lang.String getScheme(java.lang.String uri)
Get the scheme of an absolute URI.

Parameters:
uri - the absolute URI
Returns:
the URI scheme

getSpecificPart

public static java.lang.String getSpecificPart(java.lang.String uri)
Get the scheme-specific part of an absolute URI. Note that this includes everything after the separating colon, including the fragment, if any (RFC 2396 separates it from the scheme-specific part).

Parameters:
uri - the absolute URI
Returns:
the scheme-specific part of the URI

copy

public static void copy(Source source,
                        Source destination)
                 throws SourceException
Copy the source to a specified destination.

Parameters:
source - Source of the source.
destination - Destination of the source.
Throws:
SourceException - If an exception occurs during the copy.

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
Copy the contents of an InputStream to an OutputStream.

Parameters:
in -
out -
Throws:
java.io.IOException

absolutize

public static java.lang.String absolutize(java.lang.String url1,
                                          java.lang.String url2)
Calls absolutize(url1, url2, false).


absolutize

public static java.lang.String absolutize(java.lang.String url1,
                                          java.lang.String url2,
                                          boolean treatAuthorityAsBelongingToPath)
Calls absolutize(url1, url2, false, true).


absolutize

public static java.lang.String absolutize(java.lang.String url1,
                                          java.lang.String url2,
                                          boolean treatAuthorityAsBelongingToPath,
                                          boolean normalizePath)
Applies a location to a baseURI. This is done as described in RFC 2396 section 5.2.

Parameters:
url1 - the baseURI
url2 - the location
treatAuthorityAsBelongingToPath - considers the authority to belong to the path. These special kind of URIs are used in the Apache Cocoon project.
normalizePath - should the path be normalized, i.e. remove ../ and /./ etc.

parseUrl

public static java.lang.String[] parseUrl(java.lang.String url)
Parses an URL into the following parts: scheme, authority, path, query and fragment identifier.

The parsing is designed to be robust in the sense that it will never fail, even when an invalid URL is given. The parser will simply look for the most important delimiter characters. Basically it does the same as what would be achieved using the following regular expression (from RFC 2396):

 ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
  12            3  4          5       6  7        8 9
 
but without actually using the regular expression.

The result is returned as a string array, use the constants SCHEME, AUTHORITY, PATH, QUERY and FRAGMENT_IDENTIFIER to access the different parts.

If a part is missing, its corresponding entry in the array will be null, except for the path, which will never be null.


decodePath

public static java.lang.String decodePath(java.lang.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


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.