You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by nd...@apache.org on 2005/04/13 15:30:58 UTC
cvs commit: xml-commons/java/src/org/apache/xml/resolver/tools CatalogResolver.java ResolvingParser.java ResolvingXMLFilter.java
ndw 2005/04/13 06:30:58
Modified: java/src/org/apache/xml/resolver Catalog.java
CatalogManager.java
java/src/org/apache/xml/resolver/apps XParseError.java
resolver.java
java/src/org/apache/xml/resolver/helpers
BootstrapResolver.java
java/src/org/apache/xml/resolver/tools CatalogResolver.java
ResolvingParser.java ResolvingXMLFilter.java
Added: java/src/org/apache/xml/resolver/helpers FileURL.java
Log:
Fix bug #28719 and a little general cleanup
Revision Changes Path
1.12 +9 -4 xml-commons/java/src/org/apache/xml/resolver/Catalog.java
Index: Catalog.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/Catalog.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Catalog.java 12 Apr 2005 22:56:51 -0000 1.11
+++ Catalog.java 13 Apr 2005 13:30:58 -0000 1.12
@@ -61,18 +61,23 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.io.DataInputStream;
+
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
+
import java.net.URL;
import java.net.MalformedURLException;
+
+import javax.xml.parsers.SAXParserFactory;
+
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.helpers.PublicId;
import org.apache.xml.resolver.readers.CatalogReader;
import org.apache.xml.resolver.readers.SAXCatalogReader;
import org.apache.xml.resolver.readers.TR9401CatalogReader;
import org.apache.xml.resolver.readers.OASISXMLCatalogReader;
-import javax.xml.parsers.SAXParserFactory;
+import org.apache.xml.resolver.helpers.FileURL;
/**
* Represents OASIS Open Catalog files.
@@ -836,10 +841,10 @@
// properly...
try {
// tack on a basename because URLs point to files not dirs
- String userdir = fixSlashes(System.getProperty("user.dir"));
- catalogCwd = new URL("file:" + userdir + "/basename");
+ catalogCwd = FileURL.makeURL("basename");
} catch (MalformedURLException e) {
- String userdir = fixSlashes(System.getProperty("user.dir"));
+ String userdir = System.getProperty("user.dir");
+ userdir.replace('\\', '/');
catalogManager.debug.message(1, "Malformed URL on cwd", userdir);
catalogCwd = null;
}
1.9 +23 -8 xml-commons/java/src/org/apache/xml/resolver/CatalogManager.java
Index: CatalogManager.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/CatalogManager.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- CatalogManager.java 13 Apr 2005 10:01:50 -0000 1.8
+++ CatalogManager.java 13 Apr 2005 13:30:58 -0000 1.9
@@ -363,25 +363,40 @@
* defaultVerbosity.
*/
private int queryVerbosity () {
+ String defaultVerbStr = Integer.toString(defaultVerbosity);
+
String verbStr = System.getProperty(pVerbosity);
if (verbStr == null) {
if (resources==null) readProperties();
- if (resources==null) return defaultVerbosity;
- try {
- verbStr = resources.getString("verbosity");
- } catch (MissingResourceException e) {
- return defaultVerbosity;
+ if (resources != null) {
+ try {
+ verbStr = resources.getString("verbosity");
+ } catch (MissingResourceException e) {
+ verbStr = defaultVerbStr;
+ }
+ } else {
+ verbStr = defaultVerbStr;
}
}
+ int verb = defaultVerbosity;
+
try {
- int verb = Integer.parseInt(verbStr.trim());
- return verb;
+ verb = Integer.parseInt(verbStr.trim());
} catch (Exception e) {
System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
- return defaultVerbosity;
}
+
+ // This is a bit of a hack. After we've successfully got the verbosity,
+ // we have to use it to set the default debug level,
+ // if the user hasn't already set the default debug level.
+ if (verbosity == null) {
+ debug.setDebug(verb);
+ verbosity = new Integer(verb);
+ }
+
+ return verb;
}
/**
1.5 +5 -12 xml-commons/java/src/org/apache/xml/resolver/apps/XParseError.java
Index: XParseError.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/apps/XParseError.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XParseError.java 2 Sep 2003 07:05:07 -0000 1.4
+++ XParseError.java 13 Apr 2005 13:30:58 -0000 1.5
@@ -59,8 +59,10 @@
import java.net.URL;
import java.net.MalformedURLException;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.ErrorHandler;
+
+import org.apache.xml.resolver.helpers.FileURL;
/**
* An ErrorHandler for xparse.
@@ -101,17 +103,8 @@
showErrors = errors;
showWarnings = warnings;
- String dir = System.getProperty("user.dir");
- String file = "";
-
- if (dir.endsWith("/")) {
- file = "file:" + dir + "file";
- } else {
- file = "file:" + dir + "/" + file;
- }
-
try {
- URL url = new URL(file);
+ URL url = FileURL.makeURL("basename");
baseURI = url.toString();
} catch (MalformedURLException mue) {
// nop;
1.6 +2 -9 xml-commons/java/src/org/apache/xml/resolver/apps/resolver.java
Index: resolver.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/apps/resolver.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- resolver.java 2 Sep 2003 07:05:07 -0000 1.5
+++ resolver.java 13 Apr 2005 13:30:58 -0000 1.6
@@ -62,15 +62,10 @@
import java.net.MalformedURLException;
import java.util.Vector;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-
-import javax.xml.parsers.*;
-import javax.xml.transform.*;
-
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.helpers.Debug;
+import org.apache.xml.resolver.helpers.FileURL;
import org.apache.xml.resolver.tools.CatalogResolver;
/**
@@ -237,9 +232,7 @@
// Calculate the appropriate BASE URI
try {
// tack on a basename because URLs point to files not dirs
- String userdir = System.getProperty("user.dir");
- userdir.replace('\\', '/');
- base = new URL("file:///" + userdir + "/basename");
+ base = FileURL.makeURL("basename");
} catch (MalformedURLException e) {
String userdir = System.getProperty("user.dir");
userdir.replace('\\', '/');
1.4 +1 -10 xml-commons/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java
Index: BootstrapResolver.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/helpers/BootstrapResolver.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BootstrapResolver.java 25 Sep 2003 17:39:59 -0000 1.3
+++ BootstrapResolver.java 13 Apr 2005 13:30:58 -0000 1.4
@@ -225,17 +225,8 @@
URL url = new URL(uri);
return url.toString();
} catch (MalformedURLException mue) {
- String dir = System.getProperty("user.dir");
- String file = "";
-
- if (dir.endsWith("/")) {
- file = "file://" + dir + uri;
- } else {
- file = "file://" + dir + "/" + uri;
- }
-
try {
- URL fileURL = new URL(file);
+ URL fileURL = FileURL.makeURL(uri);
return fileURL.toString();
} catch (MalformedURLException mue2) {
// bail
1.1 xml-commons/java/src/org/apache/xml/resolver/helpers/FileURL.java
Index: FileURL.java
===================================================================
// FileURL.java - Construct a file: scheme URL
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xml.resolver.helpers;
import java.net.URL;
import java.net.MalformedURLException;
/**
* Static method for dealing with file: URLs.
*
* <p>This class defines a static method that can be used to construct
* an appropriate file: URL from parts. It's defined here so that it
* can be reused throught the resolver.</p>
*
* <p>(Yes, I'd rather have called this class FileUR<b>I</b>, but
* given that a jave.net.URL is returned, it seemed...even more
* confusing.)</p>
*
* @author Norman Walsh
* <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
*
* @version 1.0
*/
public abstract class FileURL {
protected FileURL() { }
/**
* Construct a file: URL for a path name.
*
* <p>URLs in the file: scheme can be constructed for paths on
* the local file system. Several possibilities need to be considered:
* </p>
*
* <ul>
* <li>If the path does not begin with a slash, then it is assumed
* to reside in the users current working directory
* (System.getProperty("user.dir")).</li>
* <li>On Windows machines, the current working directory uses
* backslashes (\\, instead of /).</li>
* <li>If the current working directory is "/", don't add an extra
* slash before the base name.</li>
* </ul>
*
* <p>This method is declared static so that other classes
* can use it directly.</p>
*
* @param pathname The path name component for which to construct a URL.
*
* @return The appropriate file: URL.
*
* @throws MalformedURLException if the pathname can't be turned into
* a proper URL.
*/
public static URL makeURL(String pathname) throws MalformedURLException {
if (pathname.startsWith("/")) {
return new URL("file://" + pathname);
}
String userdir = System.getProperty("user.dir");
userdir.replace('\\', '/');
if (userdir.endsWith("/")) {
return new URL("file://" + userdir + pathname);
} else {
return new URL("file://" + userdir + "/" + pathname);
}
}
}
1.7 +11 -14 xml-commons/java/src/org/apache/xml/resolver/tools/CatalogResolver.java
Index: CatalogResolver.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/tools/CatalogResolver.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CatalogResolver.java 12 Apr 2005 21:02:54 -0000 1.6
+++ CatalogResolver.java 13 Apr 2005 13:30:58 -0000 1.7
@@ -61,15 +61,21 @@
import java.net.URL;
import java.net.MalformedURLException;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.EntityResolver;
-import javax.xml.parsers.*;
-import javax.xml.transform.*;
import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.Source;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.TransformerException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.helpers.FileURL;
/**
* A SAX EntityResolver/JAXP URIResolver that uses catalogs.
@@ -356,17 +362,8 @@
URL url = new URL(uri);
return url.toString();
} catch (MalformedURLException mue) {
- String dir = System.getProperty("user.dir");
- String file = "";
-
- if (dir.endsWith("/")) {
- file = "file://" + dir + uri;
- } else {
- file = "file://" + dir + "/" + uri;
- }
-
try {
- URL fileURL = new URL(file);
+ URL fileURL = FileURL.makeURL(uri);
return fileURL.toString();
} catch (MalformedURLException mue2) {
// bail
1.6 +14 -6 xml-commons/java/src/org/apache/xml/resolver/tools/ResolvingParser.java
Index: ResolvingParser.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/tools/ResolvingParser.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResolvingParser.java 2 Sep 2003 07:05:08 -0000 1.5
+++ ResolvingParser.java 13 Apr 2005 13:30:58 -0000 1.6
@@ -62,12 +62,22 @@
import java.net.MalformedURLException;
import java.util.Locale;
-import org.xml.sax.*;
+import org.xml.sax.Parser;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.DTDHandler;
+import org.xml.sax.DocumentHandler;
+import org.xml.sax.AttributeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.SAXException;
-import javax.xml.parsers.*;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.SAXParser;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.helpers.FileURL;
/**
* A SAX Parser that performs catalog-based entity resolution.
@@ -305,7 +315,7 @@
}
if (allowXMLCatalogPI) {
- if (catalogManager.allowOasisXMLCatalogPI()) {
+ if (catalogManager.getAllowOasisXMLCatalogPI()) {
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
if (catalog != null) {
@@ -433,12 +443,10 @@
parser.setDocumentHandler(this);
parser.setDTDHandler(this);
- String userdir = System.getProperty("user.dir");
URL cwd = null;
- userdir.replace('\\', '/');
try {
- cwd = new URL("file:///" + userdir + "/basename");
+ cwd = FileURL.makeURL("basename");
} catch (MalformedURLException mue) {
cwd = null;
}
1.6 +8 -7 xml-commons/java/src/org/apache/xml/resolver/tools/ResolvingXMLFilter.java
Index: ResolvingXMLFilter.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/tools/ResolvingXMLFilter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResolvingXMLFilter.java 2 Sep 2003 07:05:08 -0000 1.5
+++ ResolvingXMLFilter.java 13 Apr 2005 13:30:58 -0000 1.6
@@ -61,14 +61,17 @@
import java.net.MalformedURLException;
import java.net.URL;
-import org.xml.sax.*;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.Attributes;
import org.xml.sax.helpers.XMLFilterImpl;
-import javax.xml.parsers.*;
-
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
+import org.apache.xml.resolver.helpers.FileURL;
+
/**
* A SAX XMLFilter that performs catalog-based entity resolution.
*
@@ -313,7 +316,7 @@
}
if (allowXMLCatalogPI) {
- if (catalogManager.allowOasisXMLCatalogPI()) {
+ if (catalogManager.getAllowOasisXMLCatalogPI()) {
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
if (catalog != null) {
@@ -347,12 +350,10 @@
/** Save the base URI of the document being parsed. */
private void setupBaseURI(String systemId) {
- String userdir = System.getProperty("user.dir");
URL cwd = null;
- userdir.replace('\\', '/');
try {
- cwd = new URL("file:///" + userdir + "/basename");
+ cwd = FileURL.makeURL("basename");
} catch (MalformedURLException mue) {
cwd = null;
}