[jsword-svn] r1364 - in trunk/common/src/main/java/org/crosswire/common: progress util xml
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Fri Jun 1 04:13:18 MST 2007
Author: dmsmith
Date: 2007-06-01 04:13:18 -0700 (Fri, 01 Jun 2007)
New Revision: 1364
Added:
trunk/common/src/main/java/org/crosswire/common/util/URIFilter.java
Removed:
trunk/common/src/main/java/org/crosswire/common/util/URLFilter.java
Modified:
trunk/common/src/main/java/org/crosswire/common/progress/Job.java
trunk/common/src/main/java/org/crosswire/common/progress/JobManager.java
trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java
trunk/common/src/main/java/org/crosswire/common/util/Msg.java
trunk/common/src/main/java/org/crosswire/common/util/Msg.properties
trunk/common/src/main/java/org/crosswire/common/util/Msg_de.properties
trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
trunk/common/src/main/java/org/crosswire/common/util/OSType.java
trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java
trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java
Log:
Fixed a URI bug.
Modified: trunk/common/src/main/java/org/crosswire/common/progress/Job.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/Job.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/progress/Job.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -52,13 +52,13 @@
* Create a new Job. This will automatically fire a workProgressed event to
* all WorkListeners, with the work property of this job set to 0.
* @param description Short description of this job
- * @param predicturl Optional URI to save/load prediction times from
+ * @param predictURI Optional URI to save/load prediction times from
* @param worker Optional thread to use in request to stop worker
* @param totalWork the size of the work to do
*/
- protected Job(String description, URI predicturl, Thread worker, int totalWork)
+ protected Job(String description, URI predictURI, Thread worker, int totalWork)
{
- this.predictURI = predicturl;
+ this.predictURI = predictURI;
this.workerThread = worker;
this.listeners = new ArrayList();
this.start = -1;
Modified: trunk/common/src/main/java/org/crosswire/common/progress/JobManager.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/progress/JobManager.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/progress/JobManager.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -40,8 +40,8 @@
* {
* public void run()
* {
- * URL predicturl = Project.instance().getWritablePropertiesURL("save-name");
- * Progress job = JobManager.createJob("Job Title", predicturl, this, true);
+ * URL predictURI = Project.instance().getWritablePropertiesURI("save-name");
+ * Progress job = JobManager.createJob("Job Title", predictURI, this, true);
*
* try
* {
Modified: trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/ClassUtil.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -256,15 +256,15 @@
}
/**
- * Get and instansiate the preferred implementor of some interface or abstract class.
+ * Get and instantiate the preferred implementor of some interface or abstract class.
* @param clazz The class or interface to find an implementation of.
* @return The configured implementing class.
* @throws MalformedURLException if the properties file can not be found
* @throws IOException if there is a problem reading the found file
* @throws ClassNotFoundException if the read contents are not found
* @throws ClassCastException if the read contents are not valid
- * @throws InstantiationException if the new object can not be instansiated
- * @throws IllegalAccessException if the new object can not be instansiated
+ * @throws InstantiationException if the new object can not be instantiated
+ * @throws IllegalAccessException if the new object can not be instantiated
* @see ClassUtil#getImplementors(Class)
*/
public static Object getImplementation(Class clazz) throws MalformedURLException, ClassCastException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException
Modified: trunk/common/src/main/java/org/crosswire/common/util/Msg.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Msg.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/Msg.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -40,7 +40,7 @@
static final Msg IS_DIR = new Msg("NetUtil.IsDir"); //$NON-NLS-1$
static final Msg IS_FILE = new Msg("NetUtil.IsFile"); //$NON-NLS-1$
static final Msg NOT_DIR = new Msg("NetUtil.NotDir"); //$NON-NLS-1$
- static final Msg NOT_FILE_URL = new Msg("NetUtil.NotFileURL"); //$NON-NLS-1$
+ static final Msg NOT_FILE_URI = new Msg("NetUtil.NotFileURI"); //$NON-NLS-1$
static final Msg NO_RESOURCE = new Msg("ResourceUtil.NoResource"); //$NON-NLS-1$
static final Msg NOT_ASSIGNABLE = new Msg("ResourceUtil.NotAssignable"); //$NON-NLS-1$
static final Msg UNAVILABLE = new Msg("ThreadUtil.Unavailable"); //$NON-NLS-1$
Modified: trunk/common/src/main/java/org/crosswire/common/util/Msg.properties
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Msg.properties 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/Msg.properties 2007-06-01 11:13:18 UTC (rev 1364)
@@ -14,7 +14,7 @@
NetUtil.IsDir=The given URL {0} is a directory.
NetUtil.IsFile=The given URL {0} is a file.
NetUtil.NotDir=URL {0} is not a directory
-NetUtil.NotFileURL=The given URL {0} is not a file: URL.
+NetUtil.NotFileURI=The given URL {0} is not a file: URL.
ResourceUtil.NoResource=Can''t find resource: {0}
ResourceUtil.NotAssignable=Class {0} does not implement {1}
ThreadUtil.Unavailable=<Unavailable>
Modified: trunk/common/src/main/java/org/crosswire/common/util/Msg_de.properties
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Msg_de.properties 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/Msg_de.properties 2007-06-01 11:13:18 UTC (rev 1364)
@@ -14,7 +14,7 @@
NetUtil.IsDir=Die angegebene URL {0} ist ein Verzeichnis.
NetUtil.IsFile=Die angegegebene URL {0} ist eine Datei.
NetUtil.NotDir=URL {0} is not a directory
-NetUtil.NotFileURL=The given URL {0} is not a file: URL.
+NetUtil.NotFileURI=The given URL {0} is not a file: URL.
ResourceUtil.NoResource=Can''t find resource: {0}
ResourceUtil.NotAssignable=Class {0} does not implement {1}
ThreadUtil.Unavailable=<Unavailable>
Modified: trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/NetUtil.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -111,7 +111,7 @@
{
try
{
- return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
+ return new URI(uri.toString());
}
catch (URISyntaxException e)
{
@@ -183,7 +183,6 @@
/**
* If there is a file at the other end of this URI return true.
- * Note this currently only works with file: type URIs
* @param uri The URI to check
* @return true if the URI points at a file
*/
@@ -434,17 +433,14 @@
}
/**
- * Attempt to obtain an InputStream from a URI. The simple case will
- * just call uri.toURL().openConnection().getInputStream(), however in some
- * JVMs (MS at least this fails where new FileOutputStream(url) works.
- * So if openConnection().getOutputStream() fails and the protocol is
- * file, then the alternate version is used.
- * @param uri The URI to attempt to write to
- * @return An OutputStream connection
+ * Attempt to obtain an InputStream from a URI. If the URI is a file
+ * scheme then just open it directly. Otherwise, call uri.toURL().openStream().
+ * @param uri The URI to attempt to read from
+ * @return An InputStream connection
*/
public static InputStream getInputStream(URI uri) throws IOException
{
- // We favour the FileOutputStream
+ // We favor the FileOutputStream
if (uri.getScheme().equals(PROTOCOL_FILE))
{
return new FileInputStream(uri.getPath());
@@ -454,10 +450,8 @@
/**
* Attempt to obtain an OutputStream from a URI. The simple case will
- * just call url.openConnection().getOutputStream(), however in some
+ * open it if it is local. Otherwise, it will call uri.toURL().openConnection().getOutputStream(), however in some
* JVMs (MS at least this fails where new FileOutputStream(url) works.
- * So if openConnection().getOutputStream() fails and the protocol is
- * file, then the alternate version is used.
* @param uri The URI to attempt to write to
* @return An OutputStream connection
*/
@@ -468,17 +462,15 @@
/**
* Attempt to obtain an OutputStream from a URI. The simple case will
- * just call uri.toURL().openConnection().getOutputStream(), however in some
+ * open it if it is local. Otherwise, it will call uri.toURL().openConnection().getOutputStream(), however in some
* JVMs (MS at least this fails where new FileOutputStream(url) works.
- * So if openConnection().getOutputStream() fails and the protocol is
- * file, then the alternate version is used.
* @param uri The URI to attempt to write to
* @param append Do we write to the end of the file instead of the beginning
* @return An OutputStream connection
*/
public static OutputStream getOutputStream(URI uri, boolean append) throws IOException
{
- // We favour the FileOutputStream method here because append
+ // We favor the FileOutputStream method here because append
// is not well defined for the openConnection method
if (uri.getScheme().equals(PROTOCOL_FILE))
{
@@ -499,7 +491,7 @@
* there is a difference, but returning the values from the index.txt
* method.
*/
- public static String[] list(URI uri, URLFilter filter) throws MalformedURLException, IOException
+ public static String[] list(URI uri, URIFilter filter) throws MalformedURLException, IOException
{
// We should probably cache this in some way? This is going
// to get very slow calling this often across a network
@@ -552,15 +544,15 @@
* List all the files specified by the index file passed in.
* @return String[] Matching results.
*/
- public static String[] listByFile(URI url, URLFilter filter) throws MalformedURLException
+ public static String[] listByFile(URI uri, URIFilter filter) throws MalformedURLException
{
- File fdir = new File(url.getPath());
+ File fdir = new File(uri.getPath());
if (!fdir.isDirectory())
{
- throw new MalformedURLException(Msg.NOT_DIR.toString(url.toString()));
+ throw new MalformedURLException(Msg.NOT_DIR.toString(uri.toString()));
}
- return fdir.list(new URLFilterFilenameFilter(filter));
+ return fdir.list(new URIFilterFilenameFilter(filter));
}
/**
@@ -568,7 +560,7 @@
* @return String[] Matching results.
* @throws FileNotFoundException
*/
- public static String[] listByIndexFile(URI index, URLFilter filter) throws IOException
+ public static String[] listByIndexFile(URI index, URIFilter filter) throws IOException
{
InputStream in = null;
try
@@ -633,7 +625,7 @@
}
/**
- * When was the given URL last modified. If no modification time is
+ * When was the given URI last modified. If no modification time is
* available then this method return the current time.
*/
public static long getLastModified(URI uri)
@@ -697,14 +689,14 @@
}
/**
- * Quick implementation of FilenameFilter that uses a URLFilter
+ * Quick implementation of FilenameFilter that uses a URIFilter
*/
- public static class URLFilterFilenameFilter implements FilenameFilter
+ public static class URIFilterFilenameFilter implements FilenameFilter
{
/**
* Simple ctor
*/
- public URLFilterFilenameFilter(URLFilter filter)
+ public URIFilterFilenameFilter(URIFilter filter)
{
this.filter = filter;
}
@@ -717,19 +709,19 @@
return filter.accept(name);
}
- private URLFilter filter;
+ private URIFilter filter;
}
/**
* Throw if the given URI does not use the 'file:' protocol
- * @param url The URL to check
+ * @param uri The URI to check
* @throws MalformedURLException If the protocol is not file:
*/
- private static void checkFileURI(URI url) throws MalformedURLException
+ private static void checkFileURI(URI uri) throws MalformedURLException
{
- if (!url.getScheme().equals(PROTOCOL_FILE))
+ if (!uri.getScheme().equals(PROTOCOL_FILE))
{
- throw new MalformedURLException(Msg.NOT_FILE_URL.toString(url));
+ throw new MalformedURLException(Msg.NOT_FILE_URI.toString(uri));
}
}
@@ -752,28 +744,13 @@
}
/**
- * Get a URL version of the given file.
- * @param file The File to turn into a URL
- * @return a URL for the given file
+ * Get a URI version of the given file.
+ * @param file The File to turn into a URI
+ * @return a URI for the given file
*/
public static URI getURI(File file)
{
- try
- {
- return new URI(PROTOCOL_FILE, null, null, -1, file.getCanonicalPath(), null, null);
- }
- catch (IOException ex)
- {
- log.error("Failed to create URL", ex); //$NON-NLS-1$
- assert false;
- throw new IllegalArgumentException(ex.toString());
- }
- catch (URISyntaxException ex)
- {
- log.error("Failed to create URI", ex); //$NON-NLS-1$
- assert false;
- throw new IllegalArgumentException(ex.toString());
- }
+ return file.toURI();
}
/**
@@ -825,7 +802,7 @@
* Check that the directories in the version directory really
* represent versions.
*/
- public static class IsDirectoryURIFilter implements URLFilter
+ public static class IsDirectoryURIFilter implements URIFilter
{
/**
* Simple ctor
Modified: trunk/common/src/main/java/org/crosswire/common/util/OSType.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/OSType.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/OSType.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -21,6 +21,7 @@
*/
package org.crosswire.common.util;
+import java.io.File;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
@@ -144,15 +145,8 @@
{
if (userHome == null)
{
- try
- {
- userHome = new URI(NetUtil.PROTOCOL_FILE, null, System.getProperty("user.home"), null); //$NON-NLS-1$
- }
- catch (URISyntaxException e)
- {
- log.fatal("Failed to find user's home folder", e); //$NON-NLS-1$
- assert false : e;
- }
+ File home = new File(System.getProperty("user.home")); //$NON-NLS-1$
+ userHome = NetUtil.getURI(home);
}
return userHome;
}
Modified: trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/ResourceUtil.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -28,7 +28,7 @@
import java.util.Properties;
/**
- * Better implemenetations of the getResource methods with less ambiguity and
+ * Better implementations of the getResource methods with less ambiguity and
* that are less dependent on the specific classloader situation.
*
* @see gnu.lgpl.License for license details.<br>
@@ -39,7 +39,7 @@
public final class ResourceUtil
{
/**
- * Prevent Instansiation
+ * Prevent Instantiation
*/
private ResourceUtil()
{
Copied: trunk/common/src/main/java/org/crosswire/common/util/URIFilter.java (from rev 1361, trunk/common/src/main/java/org/crosswire/common/util/URLFilter.java)
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/URIFilter.java (rev 0)
+++ trunk/common/src/main/java/org/crosswire/common/util/URIFilter.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -0,0 +1,40 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. This program 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 Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ * The copyright to this program is held by it's authors.
+ *
+ * ID: $Id$
+ */
+package org.crosswire.common.util;
+
+/**
+ * This is the URI equivalent of FilenameFilter in the java.io package.
+ *
+ * @see gnu.lgpl.License for license details.<br>
+ * The copyright to this program is held by it's authors.
+ * @author Joe Walker [joe at eireneh dot com]
+ * @see java.io.FilenameFilter
+ */
+public interface URIFilter
+{
+ /**
+ * Tests if a specified file should be included in a file list.
+ * @param name the name of the file.
+ * @return <code>true</code> if and only if the name should be included in the file list; <code>false</code> otherwise.
+ */
+ boolean accept(String name);
+}
Deleted: trunk/common/src/main/java/org/crosswire/common/util/URLFilter.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/URLFilter.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/util/URLFilter.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -1,40 +0,0 @@
-/**
- * Distribution License:
- * JSword is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License, version 2.1 as published by
- * the Free Software Foundation. This program 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 Lesser General Public License for more details.
- *
- * The License is available on the internet at:
- * http://www.gnu.org/copyleft/lgpl.html
- * or by writing to:
- * Free Software Foundation, Inc.
- * 59 Temple Place - Suite 330
- * Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- * The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.common.util;
-
-/**
- * This is the URL equivalent of FilenameFilter in the java.io package.
- *
- * @see gnu.lgpl.License for license details.<br>
- * The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- * @see java.io.FilenameFilter
- */
-public interface URLFilter
-{
- /**
- * Tests if a specified file should be included in a file list.
- * @param name the name of the file.
- * @return <code>true</code> if and only if the name should be included in the file list; <code>false</code> otherwise.
- */
- boolean accept(String name);
-}
Modified: trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java 2007-06-01 11:13:08 UTC (rev 1363)
+++ trunk/common/src/main/java/org/crosswire/common/xml/TransformingSAXEventProviderConverter.java 2007-06-01 11:13:18 UTC (rev 1364)
@@ -35,7 +35,7 @@
{
/**
* Simple ctor
- * @param xsluri The url of the stylesheet
+ * @param xsluri The uri of the stylesheet
*/
public TransformingSAXEventProviderConverter(URI xsluri)
{
@@ -51,7 +51,7 @@
}
/**
- * The URL of the stylesheet
+ * The URI of the stylesheet
*/
private URI xsluri;
}
More information about the jsword-svn
mailing list