org.mmbase.util.xml
Class URIResolver

java.lang.Object
  extended byorg.mmbase.util.xml.URIResolver
All Implemented Interfaces:
SizeMeasurable, javax.xml.transform.URIResolver

public class URIResolver
extends java.lang.Object
implements javax.xml.transform.URIResolver, SizeMeasurable

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,v 1.16.2.1 2004/05/09 14:52:52 michiel Exp $
Author:
Michiel Meeuwissen.

Nested Class Summary
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(java.io.File c)
          Create an URIResolver for a certain directory.
URIResolver(java.io.File c, boolean overhead)
          This constructor does not create an actual object that can be used.
URIResolver(java.io.File c, URIResolver.EntryList extradirs)
          Besides the current working directory you can also supply an ordered list of URIResolver.Entry's.
 
Method Summary
 boolean equals(java.lang.Object o)
          URIResolver can be used as a key in Maps (Caches).
 int getByteSize()
          Determins the byte-size of this object
 int getByteSize(SizeOf sizeof)
          Determins the byte-size of this object using the given SizeOf instance.
 java.io.File getCwd()
          Returns the working directory which was supplied in the constructor.
 java.lang.String getPath()
          Creates a 'path' string, which is a list of directories.
 java.util.List 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).
 javax.xml.transform.Source resolve(java.lang.String href, java.lang.String base)
          Implementation of the resolve method of javax.xml.transform.URIResolver.
 java.io.File resolveToFile(java.lang.String href)
          Resolves a given string to a File.
 java.io.File resolveToFile(java.lang.String href, java.lang.String base)
          Resolves the string href (possible with use of base directory 'base') to a File.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URIResolver

public URIResolver(java.io.File 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(java.io.File c)
Create an URIResolver for a certain directory.

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

URIResolver

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


URIResolver

public URIResolver(java.io.File 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:
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 java.io.File getCwd()
Returns the working directory which was supplied in the constructor.


resolveToFile

public java.io.File resolveToFile(java.lang.String href)
Resolves a given string to a File.

Parameters:
href - A string, which can be a relative Path or an URI starting with mm: or one of the other configured prefixes.
Returns:
A File

getPath

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

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

getPrefixPath

public java.util.List 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 java.io.File resolveToFile(java.lang.String href,
                                  java.lang.String base)
Resolves the string href (possible with use of base directory 'base') to a File. If href is a relative Path (without prefix), and cannot be found in the cwd or 'base', then all 'extra' dirs are tried, until it finds a file that exists. It starts with first entry in these 'extradirs' List and ends with the MMBase configuration directory.

Parameters:
href -
base -
Returns:
A File
Throws:
I
See Also:
resolveToFile(java.lang.String)

resolve

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

Specified by:
resolve in interface javax.xml.transform.URIResolver
Throws:
javax.xml.transform.TransformerException
See Also:
URIResolver

hashCode

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


equals

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


getByteSize

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

Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
Description copied from interface: SizeMeasurable
Determins 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 java.lang.String toString()


MMBase build 1.7.4.20050922