org.mmbase.util.xml
Class URIResolver

java.lang.Object
  extended by org.mmbase.util.xml.URIResolver
All Implemented Interfaces:
Serializable, URIResolver, SizeMeasurable

public class URIResolver
extends Object
implements URIResolver, SizeMeasurable, Serializable

This URIResolver can be used to resolve URI's, also in TransformerFactory's. It has knowledge of a kind of path (as used by shells). Every entry of this path is labeled with a 'prefix'. This path always has at least (and on default) two entries:

  1. Current working directory (prefix: none or 'file:')
  2. MMBase configuration directory (prefix: 'mm:')
Optionially you can add other dirs between these two. When you start searching in the current working dir, and the URI does not point to an existing file, it starts searching downwards in this list, until it finds a file that does exist.

Since:
MMBase-1.6
Version:
$Id: URIResolver.java 41059 2010-02-16 00:15:41Z michiel $
Author:
Michiel Meeuwissen.
See Also:
Serialized Form

Nested Class Summary
(package private) static class URIResolver.Entry
          Objects of this type connect a prefix (must normally end in :) with a File (which must be a Directory).
static class URIResolver.EntryList
          This is a list of prefix/directory pairs which is used in the constructor of URIResolver.
 
Constructor Summary
URIResolver()
          Create an URIResolver without support for a certain directory.
URIResolver(File f)
          Deprecated.  
URIResolver(File f, URIResolver.EntryList extraDirs)
          Deprecated.  
URIResolver(URL c)
          Create an URIResolver for a certain directory.
URIResolver(URL c, boolean overhead)
          This constructor does not create an actual object that can be used.
URIResolver(URL c, URIResolver.EntryList extraDirs)
          Besides the current working directory you can also supply an ordered list of URIResolver.Entry's.
 
Method Summary
 boolean equals(Object o)
          URIResolver can be used as a key in Maps (Caches).
 int getByteSize()
          Determines the byte-size of this object
 int getByteSize(SizeOf sizeof)
          Determines the byte-size of this object using the given SizeOf instance.
 URL getCwd()
          Returns the working directory which was supplied in the constructor.
 String getPath()
          Creates a 'path' string, which is a list of directories.
 List<String> getPrefixPath()
          Creates a List of strings, every entry is a directory prefixed with its 'prefix'.
 int hashCode()
          URIResolver can be used as a key in Maps (Caches).
static void main(String[] argv)
          For testing only
 Source resolve(String href, String base)
          Implementation of the resolve method of javax.xml.transform.URIResolver.
 File resolveToFile(String href)
          Deprecated.  
 File resolveToFile(String href, String base)
          Deprecated.  
 URL resolveToURL(String href, String base)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URIResolver

public URIResolver(URL c,
                   boolean overhead)
This constructor does not create an actual object that can be used. Only the hashCode is filled. This is because I liked it possible a URIResolver to be equal to a File. But 'equals' must be symmetric, and only a File can be equal to a File. It seemed stupid to extend URIResolver from File, only for this. If you want to compare a File to to an URIResolver (in Maps), you could wrap the file in such an empty URIResolver, and avoid all further overhead.

Parameters:
c - The directory for which this URIResolver must (not) be created.
overhead - A boolean. It is ignored. It serves only to distinct this constructor from the other one.
See Also:
FactoryCache

URIResolver

public URIResolver(URL c)
Create an URIResolver for a certain directory.

Parameters:
c - The directory for which this URIResolver must be created.

URIResolver

public URIResolver(File f)
Deprecated. 


URIResolver

public URIResolver()
Create an URIResolver without support for a certain directory. (Will be taken the first root).


URIResolver

public URIResolver(File f,
                   URIResolver.EntryList extraDirs)
Deprecated. 


URIResolver

public URIResolver(URL c,
                   URIResolver.EntryList extraDirs)
Besides the current working directory you can also supply an ordered list of URIResolver.Entry's. First in this list are the directories which must be checked first, in case no prefix is given.

Parameters:
c - 'Current working dir'
extraDirs - A EntryList, containing 'extra' dirs with prefixes. If not specified or null, there will still be one 'extra dir' available, namely the MMBase configuration directory (with prefix mm:)
Method Detail

getCwd

public URL getCwd()
Returns the working directory which was supplied in the constructor.


getPath

public String getPath()
Creates a 'path' string, which is a list of directories. Mainly useful for debugging, of course.

Returns:
A String which could be used as a shell's path.

getPrefixPath

public List<String> getPrefixPath()
Creates a List of strings, every entry is a directory prefixed with its 'prefix'. Handy during debugging.

Returns:
A List with prefix:path Strings.

resolveToFile

public File resolveToFile(String href)
Deprecated. 


resolveToFile

public File resolveToFile(String href,
                          String base)
Deprecated. 


resolveToURL

public URL resolveToURL(String href,
                        String base)
                 throws TransformerException
Throws:
TransformerException

resolve

public Source resolve(String href,
                      String base)
               throws TransformerException
Implementation of the resolve method of javax.xml.transform.URIResolver.

Specified by:
resolve in interface URIResolver
Throws:
TransformerException
See Also:
URIResolver

hashCode

public int hashCode()
URIResolver can be used as a key in Maps (Caches).

Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
URIResolver can be used as a key in Maps (Caches).

Overrides:
equals in class Object

getByteSize

public int getByteSize()
Description copied from interface: SizeMeasurable
Determines the byte-size of this object

Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
Description copied from interface: SizeMeasurable
Determines the byte-size of this object using the given SizeOf instance. A SizeOf instance stores a Set already counted objects. So this method is typically called by SizeOf itself (recursion).

Specified by:
getByteSize in interface SizeMeasurable

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] argv)
                 throws Exception
For testing only

Throws:
Exception
Since:
MMBase-1.8


MMBase 2.0-SNAPSHOT - null