edu.ucsb.adl.bucket99
Class FileLoader

java.lang.Object
  |
  +--edu.ucsb.adl.bucket99.FileLoader

public final class FileLoader
extends java.lang.Object

Loads files from URLs.

Version:
$Header: /export/home/gjanee/bucket99/edu/ucsb/adl/bucket99/RCS/FileLoader.java,v 1.3 2008/05/19 20:50:11 gjanee Exp $

$Log: FileLoader.java,v $ Revision 1.3 2008/05/19 20:50:11 gjanee
Bug fix: added application/xml as an acceptable MIME type.

Revision 1.2 2001/11/16 05:54:22 gjanee
Internationalization support. In all versions of loadXMLFile we attempt to set the character encoding based on the URL connection's MIME content type. The encoding declaration in the XML header, if any, is ignored and removed. Added a version of loadXMLFile that loads a document from a local file.

Revision 1.1 2000/05/02 20:15:24 gjanee
Initial revision

Author:
Greg Janée
Alexandria Digital Library

Method Summary
static java.lang.String loadXMLFile(java.io.File file)
          Loads a file containing an XML document.
static java.lang.String loadXMLFile(java.net.URL url)
          Loads a file containing an XML document from a URL.
static java.lang.Object[] loadXMLFileIfModified(java.net.URL url, long lastModificationTime)
          Loads a file containing an XML document from a URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadXMLFile

public static java.lang.String loadXMLFile(java.net.URL url)
                                    throws InternalErrorException
Loads a file containing an XML document from a URL. This method attempts to verify that the URL does indeed refer to an XML document by checking that the returned MIME type is text/xml and by looking at the first few characters of the document. The document's character encoding is obtained from the URL connection if the URL protocol supports it and if specified; otherwise, the platform's default encoding is assumed. The encoding declaration in the document, if any, is removed.

Parameters:
url - The URL.
Returns:
An XML document.
Throws:
InternalErrorException - If the load fails for any reason.

loadXMLFileIfModified

public static java.lang.Object[] loadXMLFileIfModified(java.net.URL url,
                                                       long lastModificationTime)
                                                throws InternalErrorException
Loads a file containing an XML document from a URL. If possible (i.e., if the URL protocol and the URL server support it), the file is loaded only if its modification time is later than a specified time.

As with loadXMLFile, this method attempts to verify that the URL does indeed refer to an XML document by checking that the returned MIME type is text/xml and by looking at the first few characters of the document. The document's character encoding is obtained from the URL connection if the URL protocol supports it and if specified; otherwise, the platform's default encoding is assumed. The encoding declaration in the document, if any, is removed.

Parameters:
url - The URL.
lastModificationTime - If positive, a time in the semantics of URLConnection.ifModifiedSince against which the file's modification time is compared. If nonpositive, this argument is ignored and the file is always loaded.
Returns:
If the file was loaded, an array of two elements: the first element, a String, is the XML document, and the second element, a Long, is the file's modification time in the semantics of URLConnection.getLastModified. If the file was not loaded, null.
Throws:
InternalErrorException - If the load fails for any reason.

loadXMLFile

public static java.lang.String loadXMLFile(java.io.File file)
                                    throws InternalErrorException
Loads a file containing an XML document. This method attempts to verify that the file is indeed XML by looking at the first few characters of the document. The document's character encoding is assumed to be the platform's default. The encoding declaration in the document, if any, is removed.

Parameters:
file - The file.
Returns:
An XML document.
Throws:
InternalErrorException - If the load fails for any reason.