org.apache.cocoon.components.source
Class SourceUtil

java.lang.Object
  extended by org.apache.cocoon.components.source.SourceUtil

public final class SourceUtil
extends Object

This class contains some utility methods for the source resolving.

Version:
$Id: SourceUtil.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Carsten Ziegeler, Stephan Michels

Method Summary
static String getAuthority(String uri)
          Return the authority of a URI.
static String getFragment(String uri)
          Return the fragment of a URI.
static InputSource getInputSource(Source source)
          Get an InputSource object
static String getPath(String uri)
          Return the path of a URI.
static String getPathWithoutAuthority(String uri)
          Return the path of a URI, if the URI can't contains a authority.
static String getQuery(String uri)
          Return the query of a URI.
static String getScheme(String uri)
          Return the scheme of a URI.
static Source getSource(String uri, Parameters typeParameters, SourceParameters resourceParameters, SourceResolver resolver)
          Get a Source object
static ProcessingException handle(SourceException se)
          Make a ProcessingException from a SourceException.
static ProcessingException handle(String message, SourceException se)
          Make a ProcessingException from a SourceException.
static void handleSAXException(String source, SAXException e)
          Handle SAXException catched in Generator's generate method.
static void parse(ComponentManager manager, Source source, ContentHandler handler)
          Deprecated. Use parse(ServiceManager, Source, ContentHandler).
static void parse(ServiceManager manager, Source source, ContentHandler handler)
          Generates SAX events from the given source by parsing it.
static DocumentFragment readDOM(String location, Parameters typeParameters, SourceParameters parameters, SourceResolver resolver)
          Deprecated. This method will be removed in future versions.
static void toCharacters(Source source, String encoding, ContentHandler handler)
          Generates character SAX events from the given source.
static Document toDOM(ServiceManager manager, Source source)
          Generates a DOM from the given source
static Document toDOM(ServiceManager manager, String mimeTypeHint, Source source)
          Generates a DOM from the given source
static Document toDOM(Source source)
          Generates a DOM from the given source
static void toSAX(ComponentManager manager, Source source, String mimeTypeHint, ContentHandler handler)
          Deprecated. Use the toSAX(ServiceManager, Source, String, ContentHandler) method instead.
static void toSAX(ServiceManager manager, Source source, String mimeTypeHint, ContentHandler handler)
          Generates SAX events from the given source NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!
static void toSAX(Source source, ContentHandler handler)
          Generates SAX events from the given source.
static void toSAX(Source source, ContentHandler handler, Parameters typeParameters, boolean filterDocumentEvent)
          Generates SAX events from the given source NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!
static void toSAX(Source source, String mimeTypeHint, ContentHandler handler)
          Generates SAX events from the given source by using XMLizer.
static void toSAX(XMLizable source, ContentHandler handler)
          Generates SAX events from the XMLizable and handle SAXException.
static void writeDOM(String location, Parameters typeParameters, SourceParameters parameters, DocumentFragment frag, SourceResolver resolver, String serializerName)
          Deprecated. This method will be removed in future versions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toSAX

public static void toSAX(XMLizable source,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Generates SAX events from the XMLizable and handle SAXException.

Parameters:
source - the data
Throws:
SAXException
IOException
ProcessingException

toSAX

public static void toSAX(Source source,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Generates SAX events from the given source.

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

toSAX

public static void toSAX(Source source,
                         String mimeTypeHint,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Generates SAX events from the given source by using XMLizer. Current sitemap manager will be used to lookup XMLizer.

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

toSAX

public static void toSAX(ComponentManager manager,
                         Source source,
                         String mimeTypeHint,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Deprecated. Use the toSAX(ServiceManager, Source, String, ContentHandler) method instead.

Generates SAX events from the given source by using XMLizer.

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

toSAX

public static void toSAX(ServiceManager manager,
                         Source source,
                         String mimeTypeHint,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Generates SAX events from the given source

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

parse

public static void parse(ComponentManager manager,
                         Source source,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Deprecated. Use parse(ServiceManager, Source, ContentHandler).

Generates SAX events from the given source by parsing it.

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

toCharacters

public static void toCharacters(Source source,
                                String encoding,
                                ContentHandler handler)
                         throws SAXException,
                                IOException,
                                ProcessingException
Generates character SAX events from the given source.

Parameters:
source - The data
encoding - The character encoding of the data
Throws:
SAXException
IOException
ProcessingException

parse

public static void parse(ServiceManager manager,
                         Source source,
                         ContentHandler handler)
                  throws SAXException,
                         IOException,
                         ProcessingException
Generates SAX events from the given source by parsing it.

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

toSAX

public static void toSAX(Source source,
                         ContentHandler handler,
                         Parameters typeParameters,
                         boolean filterDocumentEvent)
                  throws SAXException,
                         IOException,
                         ProcessingException
Generates SAX events from the given source

NOTE: If the implementation can produce lexical events, care should be taken that handler can actually directly implement the LexicalHandler interface!

Parameters:
source - the data
Throws:
ProcessingException - if no suitable converter is found
SAXException
IOException

toDOM

public static Document toDOM(Source source)
                      throws SAXException,
                             IOException,
                             ProcessingException
Generates a DOM from the given source

Parameters:
source - The data
Returns:
Created DOM document.
Throws:
IOException - If a io exception occurs.
ProcessingException - if no suitable converter is found
SAXException - If a SAX exception occurs.

toDOM

public static Document toDOM(ServiceManager manager,
                             Source source)
                      throws SAXException,
                             IOException,
                             ProcessingException
Generates a DOM from the given source

Parameters:
source - The data
Returns:
Created DOM document.
Throws:
IOException - If a io exception occurs.
ProcessingException - if no suitable converter is found
SAXException - If a SAX exception occurs.

toDOM

public static Document toDOM(ServiceManager manager,
                             String mimeTypeHint,
                             Source source)
                      throws SAXException,
                             IOException,
                             ProcessingException
Generates a DOM from the given source

Parameters:
source - The data
Returns:
Created DOM document.
Throws:
IOException - If a io exception occurs.
ProcessingException - if no suitable converter is found
SAXException - If a SAX exception occurs.

handle

public static ProcessingException handle(SourceException se)
Make a ProcessingException from a SourceException. If the exception is a SourceNotFoundException then a ResourceNotFoundException is thrown.

Parameters:
se - Source exception
Returns:
Created processing exception.

handle

public static ProcessingException handle(String message,
                                         SourceException se)
Make a ProcessingException from a SourceException. If the exception is a SourceNotFoundException then a ResourceNotFoundException is thrown.

Parameters:
message - Additional exception message.
se - Source exception.
Returns:
Created processing exception.

handleSAXException

public static void handleSAXException(String source,
                                      SAXException e)
                               throws ProcessingException,
                                      IOException,
                                      SAXException
Handle SAXException catched in Generator's generate method.

Parameters:
source - Generator's source
e - SAXException happened in the generator's generate method.
Throws:
ProcessingException
IOException
SAXException

getInputSource

public static InputSource getInputSource(Source source)
                                  throws IOException,
                                         ProcessingException
Get an InputSource object

Parameters:
source - Source.
Returns:
Input stream of the source.
Throws:
IOException - If a io exception occurs.
ProcessingException - If an exception occurs during processing.

getSource

public static Source getSource(String uri,
                               Parameters typeParameters,
                               SourceParameters resourceParameters,
                               SourceResolver resolver)
                        throws IOException,
                               SAXException,
                               SourceException
Get a Source object

Parameters:
uri - URI of the source.
typeParameters - Type of Source query. Currently, only method parameter (value typically GET or POST) is recognized. May be null.
resourceParameters - Parameters of the source. May be null
resolver - Resolver for the source.
Returns:
The resolved source.
Throws:
IOException - If a io exception occurs.
SAXException - If a SAX exception occurs.
SourceException - If the source an exception throws.

writeDOM

public static void writeDOM(String location,
                            Parameters typeParameters,
                            SourceParameters parameters,
                            DocumentFragment frag,
                            SourceResolver resolver,
                            String serializerName)
                     throws ProcessingException
Deprecated. This method will be removed in future versions.

Write a DOM Fragment to a source. If the source is a ModifiableSource the interface is used. If not, the source is invoked with an additional parameter named "content" containing the XML.

Parameters:
location - URI of the Source
typeParameters - Type of Source query. Currently, only method parameter (value typically GET or POST) is recognized. May be null.
parameters - Parameters (e.g. URL params) of the source. May be null
frag - DOM fragment to serialize to the Source
resolver - Resolver for the source.
serializerName - The serializer to use
Throws:
ProcessingException

readDOM

public static DocumentFragment readDOM(String location,
                                       Parameters typeParameters,
                                       SourceParameters parameters,
                                       SourceResolver resolver)
                                throws ProcessingException
Deprecated. This method will be removed in future versions.

Read a DOM Fragment from a source

Parameters:
location - URI of the Source
typeParameters - Type of Source query. Currently, only method parameter (value typically GET or POST) is recognized. May be null.
parameters - Parameters (e.g. URL params) of the source. May be null
resolver - Resolver for the source.
Returns:
DOM DocumentFragment constructed from the specified source.
Throws:
ProcessingException

getScheme

public static String getScheme(String uri)
Return the scheme of a URI. Just as there are many different methods of access to resources, there are a variety of schemes for identifying such resources. (see RFC 2396).

Parameters:
uri - Uniform resource identifier.
Returns:
Scheme of the URI.

getAuthority

public static String getAuthority(String uri)
Return the authority of a URI. This authority is typically defined by an Internet-based server or a scheme-specific registry of naming authorities (see RFC 2396).

Parameters:
uri - Uniform resource identifier.
Returns:
Scheme of the URI.

getPath

public static String getPath(String uri)
Return the path of a URI. The path contains data, specific to the authority (or the scheme if there is no authority component), identifying the resource within the scope of that scheme and authority (see RFC 2396).

Parameters:
uri - Uniform resource identifier.
Returns:
Path of the URI.

getPathWithoutAuthority

public static String getPathWithoutAuthority(String uri)
Return the path of a URI, if the URI can't contains a authority. This implementation differ to the RFC 2396.

Parameters:
uri - Uniform resource identifier.
Returns:
Path of the URI.

getQuery

public static String getQuery(String uri)
Return the query of a URI. The query is a string of information to be interpreted by the resource (see RFC 2396).

Parameters:
uri - Uniform resource identifier.
Returns:
Query of the URI.

getFragment

public static String getFragment(String uri)
Return the fragment of a URI. When a URI reference is used to perform a retrieval action on the identified resource, the optional fragment identifier, consists of additional reference information to be interpreted by the user agent after the retrieval action has been successfully completed (see RFC 2396).

Parameters:
uri - Uniform resource identifier.
Returns:
Fragment of the URI.


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.