Fix bug #28719 and a little general cleanup

git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ndw
2005-04-13 13:30:58 +00:00
parent 166c71a317
commit 743cf92ca8
9 changed files with 195 additions and 70 deletions

View File

@@ -61,18 +61,23 @@ import java.io.FileNotFoundException;
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 @@ public class Catalog {
// 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;
}

View File

@@ -363,25 +363,40 @@ public class CatalogManager {
* 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;
}
/**

View File

@@ -59,8 +59,10 @@ package org.apache.xml.resolver.apps;
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 @@ public class XParseError implements ErrorHandler {
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;

View File

@@ -62,15 +62,10 @@ import java.net.URL;
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 @@ public class resolver {
// 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('\\', '/');

View File

@@ -225,17 +225,8 @@ public class BootstrapResolver implements EntityResolver, URIResolver {
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

View File

@@ -0,0 +1,122 @@
// 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);
}
}
}

View File

@@ -61,15 +61,21 @@ import java.io.InputStream;
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 @@ public class CatalogResolver implements EntityResolver, URIResolver {
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

View File

@@ -62,12 +62,22 @@ import java.net.URL;
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 @@ public class ResolvingParser
}
if (allowXMLCatalogPI) {
if (catalogManager.allowOasisXMLCatalogPI()) {
if (catalogManager.getAllowOasisXMLCatalogPI()) {
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
if (catalog != null) {
@@ -433,12 +443,10 @@ public class ResolvingParser
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;
}

View File

@@ -61,14 +61,17 @@ import java.io.InputStream;
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 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
}
if (allowXMLCatalogPI) {
if (catalogManager.allowOasisXMLCatalogPI()) {
if (catalogManager.getAllowOasisXMLCatalogPI()) {
catalogManager.debug.message(4,"oasis-xml-catalog PI", pidata);
if (catalog != null) {
@@ -347,12 +350,10 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
/** 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;
}