gnu.xml.util

Class Resolver

Implemented Interfaces:
Cloneable, EntityResolver

public class Resolver
extends Object
implements EntityResolver, Cloneable

Utility implementation of a SAX resolver, which can be used to improve network utilization of SAX based XML components. It does this by supporting local caches of external entities. SAX parsers should use such local caches when possible.
See Also:
XCat

Constructor Summary

Resolver(Dictionary<K,V> dict)
Constructs a resolver which understands how to map PUBLIC identifiers to other URIs, typically for local copies of standard DTD components.

Method Summary

static void
addDirectoryMapping(Dictionary<K,V> table, mappings[][] , File directory)
Updates a dictionary used to map PUBLIC identifiers to file names, so that it uses the mappings in a specified directory.
static String
fileNameToURL(String filename)
Provides the URL for a named file, without relying on the JDK 1.2 File.toURL() utility method.
static String
fileToURL(File f)
Provides the URL for a file, without relying on the JDK 1.2 File.toURL() utility method.
static String
getEncoding(String contentType)
This parses most MIME content type strings that have charset=... encoding declarations to and returns the specified encoding.
static String
getURL(String fileOrURL)
Returns a URL string.
InputSource
resolveEntity(String publicId, String systemId)
Uses a local dictionary of public identifiers to resolve URIs, normally with the goal of minimizing network traffic or latencies.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Resolver

public Resolver(Dictionary<K,V> dict)
Constructs a resolver which understands how to map PUBLIC identifiers to other URIs, typically for local copies of standard DTD components.
Parameters:
dict - maps PUBLIC identifiers to URIs. This is not copied; subsequent modifications will be reported through the resolution operations.

Method Details

addDirectoryMapping

public static void addDirectoryMapping(Dictionary<K,V> table,
                                       mappings[][] ,
                                       File directory)
            throws IOException
Updates a dictionary used to map PUBLIC identifiers to file names, so that it uses the mappings in a specified directory.
Parameters:
directory - File holding the specified files.

fileNameToURL

public static String fileNameToURL(String filename)
            throws IOException
Provides the URL for a named file, without relying on the JDK 1.2 File.toURL() utility method.
Parameters:
filename - the file name to convert. Relative file names are resolved the way the JVM resolves them (current to the process-global current working directory).
Throws:
IOException - if the file does not exist

fileToURL

public static String fileToURL(File f)
            throws IOException
Provides the URL for a file, without relying on the JDK 1.2 File.toURL() utility method.
Parameters:
f - the file to convert. Relative file names are resolved the way the JVM resolves them (current to the process-global current working directory).
Throws:
IOException - if the file does not exist

getEncoding

public static String getEncoding(String contentType)
This parses most MIME content type strings that have charset=... encoding declarations to and returns the specified encoding. This conforms to RFC 3023, and is useful when constructing InputSource objects from URLConnection objects or other objects using MIME content typing.
Parameters:
contentType - the MIME content type that will be parsed; must not be null.
Returns:
the appropriate encoding, or null if the content type is not text and there's no charset=... attribute

getURL

public static String getURL(String fileOrURL)
Returns a URL string. Note that if a malformed URL is provided, or the parameter names a nonexistent file, the resulting URL may be malformed.
Parameters:
fileOrURL - If this is the name of a file which exists, then its URL is returned. Otherwise the argument is returned.

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
            throws IOException,
                   SAXException
Uses a local dictionary of public identifiers to resolve URIs, normally with the goal of minimizing network traffic or latencies.
Specified by:
resolveEntity in interface EntityResolver

Resolver.java -- Copyright (C) 1999,2000,2001 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.