This commit is contained in:
Lana Steuck 2014-09-11 14:28:19 -07:00
commit addd94063e
27 changed files with 1504 additions and 1533 deletions

View File

@ -2,6 +2,6 @@
^dist/
^drop/
^drop_included/
^webrev/
^webrev
/nbproject/private/
^.hgtip

View File

@ -973,6 +973,7 @@ public abstract class XMLScanner
fStringBuffer2.append('\n');
}
} else if (c != -1 && XMLChar.isHighSurrogate(c)) {
fStringBuffer3.clear();
if (scanSurrogates(fStringBuffer3)) {
stringBuffer.append(fStringBuffer3);
if (entityDepth == fEntityDepth && fNeedNonNormalizedValue) {

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// Catalog.java - Represents OASIS Open Catalog files.
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -25,28 +19,24 @@ package com.sun.org.apache.xml.internal.resolver;
import com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl;
import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
import java.io.IOException;
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 com.sun.org.apache.xml.internal.resolver.CatalogManager;
import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader;
import com.sun.org.apache.xml.internal.resolver.readers.SAXCatalogReader;
import com.sun.org.apache.xml.internal.resolver.readers.TR9401CatalogReader;
import com.sun.org.apache.xml.internal.resolver.readers.OASISXMLCatalogReader;
import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
import java.io.DataInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Locale;
import java.util.Vector;
import javax.xml.parsers.SAXParserFactory;
/**
* Represents OASIS Open Catalog files.
@ -154,8 +144,6 @@ import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
*
* <p>Additional catalogs may also be loaded with the
* {@link #parseCatalog} method.</p>
* </dd>
* </dl>
*
* <p><b>Change Log:</b></p>
* <dl>
@ -823,7 +811,7 @@ public class Catalog {
catalogCwd = FileURL.makeURL("basename");
} catch (MalformedURLException e) {
String userdir = SecuritySupport.getSystemProperty("user.dir");
userdir.replace('\\', '/');
userdir = userdir.replace('\\', '/');
catalogManager.debug.message(1, "Malformed URL on cwd", userdir);
catalogCwd = null;
}
@ -2113,66 +2101,113 @@ public class Catalog {
}
}
/**
* Perform character normalization on a URI reference.
*
* @param uriref The URI reference
* @return The normalized URI reference.
*/
protected String normalizeURI(String uriref) {
if (uriref == null) {
return null;
/**
* Perform character normalization on a URI reference.
*
* @param uriref The URI reference
* @return The normalized URI reference.
*/
protected String normalizeURI(String uriref) {
if (uriref == null) {
return null;
}
final int length = uriref.length();
for (int i = 0; i < length; ++i) {
char c = uriref.charAt(i);
if ((c <= 0x20) // ctrl
|| (c > 0x7F) // high ascii
|| (c == 0x22) // "
|| (c == 0x3C) // <
|| (c == 0x3E) // >
|| (c == 0x5C) // \
|| (c == 0x5E) // ^
|| (c == 0x60) // `
|| (c == 0x7B) // {
|| (c == 0x7C) // |
|| (c == 0x7D) // }
|| (c == 0x7F)) {
return normalizeURI(uriref, i);
}
}
return uriref;
}
byte[] bytes;
try {
bytes = uriref.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
// this can't happen
catalogManager.debug.message(1, "UTF-8 is an unsupported encoding!?");
return uriref;
/**
* Perform character normalization on a URI reference.
*
* @param uriref The URI reference
* @param index The index of the first character which requires escaping.
* @return The normalized URI reference.
*/
private String normalizeURI(String uriref, int index) {
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < index; ++i) {
buffer.append(uriref.charAt(i));
}
final byte[] bytes;
try {
bytes = uriref.substring(index).getBytes("UTF-8");
}
catch (UnsupportedEncodingException uee) {
// this can't happen
catalogManager.debug.message(1, "UTF-8 is an unsupported encoding!?");
return uriref;
}
for (int count = 0; count < bytes.length; ++count) {
int ch = bytes[count] & 0xFF;
if ((ch <= 0x20) // ctrl
|| (ch > 0x7F) // high ascii
|| (ch == 0x22) // "
|| (ch == 0x3C) // <
|| (ch == 0x3E) // >
|| (ch == 0x5C) // \
|| (ch == 0x5E) // ^
|| (ch == 0x60) // `
|| (ch == 0x7B) // {
|| (ch == 0x7C) // |
|| (ch == 0x7D) // }
|| (ch == 0x7F)) {
writeEncodedByte(ch, buffer);
}
else {
buffer.append((char) bytes[count]);
}
}
return buffer.toString();
}
StringBuilder newRef = new StringBuilder(bytes.length);
for (int count = 0; count < bytes.length; count++) {
int ch = bytes[count] & 0xFF;
if ((ch <= 0x20) // ctrl
|| (ch > 0x7F) // high ascii
|| (ch == 0x22) // "
|| (ch == 0x3C) // <
|| (ch == 0x3E) // >
|| (ch == 0x5C) // \
|| (ch == 0x5E) // ^
|| (ch == 0x60) // `
|| (ch == 0x7B) // {
|| (ch == 0x7C) // |
|| (ch == 0x7D) // }
|| (ch == 0x7F)) {
newRef.append(encodedByte(ch));
} else {
newRef.append((char) bytes[count]);
}
/**
* Perform %-encoding on a single byte.
*
* @param b The 8-bit integer that represents the byte. (Bytes are signed
* but encoding needs to look at the bytes unsigned.)
* @return The %-encoded string for the byte in question.
*/
protected String encodedByte(int b) {
StringBuilder buffer = new StringBuilder(3);
writeEncodedByte(b, buffer);
return buffer.toString();
}
return newRef.toString();
}
/**
* Perform %-encoding on a single byte.
*
* @param b The 8-bit integer that represents th byte. (Bytes are signed
but encoding needs to look at the bytes unsigned.)
* @return The %-encoded string for the byte in question.
*/
protected String encodedByte (int b) {
String hex = Integer.toHexString(b).toUpperCase();
if (hex.length() < 2) {
return "%0" + hex;
} else {
return "%" + hex;
/**
* Perform %-encoding on a single byte.
*
* @param b The 8-bit integer that represents the byte. (Bytes are signed
* but encoding needs to look at the bytes unsigned.)
* @param buffer The target for the %-encoded string for the byte in question.
*/
private void writeEncodedByte(int b, StringBuilder buffer) {
String hex = Integer.toHexString(b).toUpperCase(Locale.ENGLISH);
if (hex.length() < 2) {
buffer.append("%0");
buffer.append(hex);
}
else {
buffer.append('%');
buffer.append(hex);
}
}
}
// -----------------------------------------------------------------

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// CatalogEntry.java - Represents Catalog entries
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -53,18 +47,18 @@ import java.util.Vector;
*/
public class CatalogEntry {
/** The nextEntry is the ordinal number of the next entry type. */
protected static int nextEntry = 0;
static int nextEntry = 0;
/**
* The entryTypes vector maps catalog entry names
* (e.g., 'BASE' or 'SYSTEM') to their type (1, 2, etc.).
* Names are case sensitive.
*/
protected static Hashtable entryTypes = new Hashtable();
static final Hashtable entryTypes = new Hashtable();
/** The entryTypes vector maps catalog entry types to the
number of arguments they're required to have. */
protected static Vector entryArgs = new Vector();
static final Vector entryArgs = new Vector();
/**
* Adds a new catalog entry type.

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// CatalogException.java - Catalog exception
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -36,6 +30,9 @@ package com.sun.org.apache.xml.internal.resolver;
*
*/
public class CatalogException extends Exception {
private static final long serialVersionUID = 4007157171817798450L;
/** A wrapper around another exception */
public static final int WRAPPER = 1;
/** An invalid entry */
@ -56,8 +53,8 @@ public class CatalogException extends Exception {
/**
* The embedded exception if tunnelling, or null.
*/
private Exception exception = null;
private int exceptionType = 0;
private final Exception exception;
private final int exceptionType;
/**
* Create a new CatalogException.

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// Resolver.java - Represents an extension of OASIS Open Catalog files.
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -94,7 +88,7 @@ public class Resolver extends Catalog {
SAXCatalogReader saxReader = new SAXCatalogReader(spf);
saxReader.setCatalogParser(null, "XMLCatalog",
saxReader.setCatalogParser(null, "XCatalog",
"com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader");
saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// BootstrapResolver.java - Resolve entities and URIs internally
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -65,14 +59,17 @@ public class BootstrapResolver implements EntityResolver, URIResolver {
/** System identifier for OASIS XML Catalog files. */
public static final String xmlCatalogSysId = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd";
/** Public identifier for legacy Apache XCatalog files. There is no official system identifier for XCatalog files. */
public static final String xCatalogPubId = "-//DTD XCatalog//EN";
/** Private hash used for public identifiers. */
private Hashtable publicMap = new Hashtable();
private final Hashtable publicMap = new Hashtable();
/** Private hash used for system identifiers. */
private Hashtable systemMap = new Hashtable();
private final Hashtable systemMap = new Hashtable();
/** Private hash used for URIs. */
private Hashtable uriMap = new Hashtable();
private final Hashtable uriMap = new Hashtable();
/** Constructor. */
public BootstrapResolver() {
@ -91,6 +88,11 @@ public class BootstrapResolver implements EntityResolver, URIResolver {
if (url != null) {
uriMap.put(xmlCatalogXSD, url.toString());
}
url = this.getClass().getResource("/com/sun/org/apache/xml/internal/resolver/etc/xcatalog.dtd");
if (url != null) {
publicMap.put(xCatalogPubId, url.toString());
}
}
/** SAX resolveEntity API. */

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// Debug.java - Print debug messages
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// FileURL.java - Construct a file: scheme URL
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// Namespaces.java - Analyze namespace nodes in a DOM tree
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -47,8 +41,9 @@ public class Namespaces {
String name = element.getTagName();
String prefix = "";
if (name.indexOf(':') > 0) {
prefix = name.substring(0, name.indexOf(':'));
final int indexOfColon = name.indexOf(':');
if (indexOfColon > 0) {
prefix = name.substring(0, indexOfColon);
}
return prefix;
@ -64,8 +59,9 @@ public class Namespaces {
public static String getLocalName(Element element) {
String name = element.getTagName();
if (name.indexOf(':') > 0) {
name = name.substring(name.indexOf(':')+1);
final int indexOfColon = name.indexOf(':');
if (indexOfColon > 0) {
name = name.substring(indexOfColon + 1);
}
return name;
@ -85,7 +81,7 @@ public class Namespaces {
return null;
}
if (prefix.equals("")) {
if (prefix.length() == 0) {
if (((Element) node).hasAttribute("xmlns")) {
return ((Element) node).getAttribute("xmlns");
}

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// PublicId.java - Information about public identifiers
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -34,7 +28,8 @@ package com.sun.org.apache.xml.internal.resolver.helpers;
*
*/
public abstract class PublicId {
protected PublicId() { }
protected PublicId() {}
/**
* Normalize a public identifier.
@ -58,18 +53,17 @@ public abstract class PublicId {
* @return The normalized identifier.
*/
public static String normalize(String publicId) {
String normal = publicId.replace('\t', ' ');
normal = normal.replace('\r', ' ');
normal = normal.replace('\n', ' ');
normal = normal.trim();
String normal = publicId.replace('\t', ' ');
normal = normal.replace('\r', ' ');
normal = normal.replace('\n', ' ');
normal = normal.trim();
int pos;
int pos;
while ((pos = normal.indexOf(" ")) >= 0) {
normal = normal.substring(0, pos) + normal.substring(pos+1);
}
return normal;
while ((pos = normal.indexOf(" ")) >= 0) {
normal = normal.substring(0, pos) + normal.substring(pos+1);
}
return normal;
}
/**
@ -83,21 +77,24 @@ public abstract class PublicId {
* @return The normalized identifier.
*/
public static String encodeURN(String publicId) {
String urn = PublicId.normalize(publicId);
String urn = PublicId.normalize(publicId);
urn = PublicId.stringReplace(urn, "%", "%25");
urn = PublicId.stringReplace(urn, ";", "%3B");
urn = PublicId.stringReplace(urn, "'", "%27");
urn = PublicId.stringReplace(urn, "?", "%3F");
urn = PublicId.stringReplace(urn, "#", "%23");
urn = PublicId.stringReplace(urn, "+", "%2B");
urn = PublicId.stringReplace(urn, " ", "+");
urn = PublicId.stringReplace(urn, "::", ";");
urn = PublicId.stringReplace(urn, ":", "%3A");
urn = PublicId.stringReplace(urn, "//", ":");
urn = PublicId.stringReplace(urn, "/", "%2F");
urn = PublicId.stringReplace(urn, "%", "%25");
urn = PublicId.stringReplace(urn, ";", "%3B");
urn = PublicId.stringReplace(urn, "'", "%27");
urn = PublicId.stringReplace(urn, "?", "%3F");
urn = PublicId.stringReplace(urn, "#", "%23");
urn = PublicId.stringReplace(urn, "+", "%2B");
urn = PublicId.stringReplace(urn, " ", "+");
urn = PublicId.stringReplace(urn, "::", ";");
urn = PublicId.stringReplace(urn, ":", "%3A");
urn = PublicId.stringReplace(urn, "//", ":");
urn = PublicId.stringReplace(urn, "/", "%2F");
return "urn:publicid:" + urn;
StringBuilder buffer = new StringBuilder(13 + urn.length());
buffer.append("urn:publicid:");
buffer.append(urn);
return buffer.toString();
}
/**
@ -111,51 +108,62 @@ public abstract class PublicId {
* @return The normalized identifier.
*/
public static String decodeURN(String urn) {
String publicId = "";
String publicId;
if (urn.startsWith("urn:publicid:")) {
publicId = urn.substring(13);
}
else {
return urn;
}
if (urn.startsWith("urn:publicid:")) {
publicId = urn.substring(13);
} else {
return urn;
}
final boolean hasEscape = (publicId.indexOf('%') >= 0);
if (hasEscape) {
publicId = PublicId.stringReplace(publicId, "%2F", "/");
}
publicId = PublicId.stringReplace(publicId, ":", "//");
if (hasEscape) {
publicId = PublicId.stringReplace(publicId, "%3A", ":");
}
publicId = PublicId.stringReplace(publicId, ";", "::");
publicId = PublicId.stringReplace(publicId, "+", " ");
if (hasEscape) {
publicId = PublicId.stringReplace(publicId, "%2B", "+");
publicId = PublicId.stringReplace(publicId, "%23", "#");
publicId = PublicId.stringReplace(publicId, "%3F", "?");
publicId = PublicId.stringReplace(publicId, "%27", "'");
publicId = PublicId.stringReplace(publicId, "%3B", ";");
publicId = PublicId.stringReplace(publicId, "%25", "%");
}
publicId = PublicId.stringReplace(publicId, "%2F", "/");
publicId = PublicId.stringReplace(publicId, ":", "//");
publicId = PublicId.stringReplace(publicId, "%3A", ":");
publicId = PublicId.stringReplace(publicId, ";", "::");
publicId = PublicId.stringReplace(publicId, "+", " ");
publicId = PublicId.stringReplace(publicId, "%2B", "+");
publicId = PublicId.stringReplace(publicId, "%23", "#");
publicId = PublicId.stringReplace(publicId, "%3F", "?");
publicId = PublicId.stringReplace(publicId, "%27", "'");
publicId = PublicId.stringReplace(publicId, "%3B", ";");
publicId = PublicId.stringReplace(publicId, "%25", "%");
return publicId;
}
return publicId;
}
/**
* Replace one string with another.
*
*/
private static String stringReplace(String str,
String oldStr,
String newStr) {
String result = "";
int pos = str.indexOf(oldStr);
// System.out.println(str + ": " + oldStr + " => " + newStr);
while (pos >= 0) {
// System.out.println(str + " (" + pos + ")");
result += str.substring(0, pos);
result += newStr;
str = str.substring(pos+1);
pos = str.indexOf(oldStr);
}
return result + str;
String oldStr,
String newStr) {
int pos = str.indexOf(oldStr);
if (pos >= 0) {
final StringBuilder buffer = new StringBuilder();
final int oldStrLength = oldStr.length();
int start = 0;
do {
for (int i = start; i < pos; ++i) {
buffer.append(str.charAt(i));
}
buffer.append(newStr);
start = pos + oldStrLength;
pos = str.indexOf(oldStr, start);
}
while (pos >= 0);
final int strLength = str.length();
for (int i = start; i < strLength; ++i) {
buffer.append(str.charAt(i));
}
return buffer.toString();
}
return str;
}
}

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// CatalogReader.java - An interface for reading catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// DOMCatalogParser.java - An interface for reading catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// DOMCatalogReader.java - Read XML Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// ExtendedXMLCatalogReader.java - Read XML Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -166,7 +160,7 @@ public class ExtendedXMLCatalogReader extends OASISXMLCatalogReader {
String baseURI = (String) baseURIStack.peek();
if (!baseURI.equals(popURI)) {
entryType = catalog.BASE;
entryType = Catalog.BASE;
entryArgs.add(baseURI);
debug.message(4, "(reset) xml:base", baseURI);

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// OASISXMLCatalogReader.java - Read XML Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -23,16 +17,16 @@
package com.sun.org.apache.xml.internal.resolver.readers;
import java.util.Stack;
import java.util.Vector;
import java.util.Enumeration;
import com.sun.org.apache.xml.internal.resolver.Catalog;
import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
import com.sun.org.apache.xml.internal.resolver.CatalogException;
import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
import org.xml.sax.*;
import java.util.Enumeration;
import java.util.Stack;
import java.util.Vector;
import javax.xml.parsers.SAXParserFactory;
import org.w3c.dom.*;
import org.xml.sax.*;
/**
* Parse OASIS Entity Resolution Technical Committee
@ -71,6 +65,17 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
return catalog;
}
/** Default constructor */
public OASISXMLCatalogReader() {
super();
}
/** Constructor allowing for providing custom SAX parser factory */
public OASISXMLCatalogReader(SAXParserFactory parserFactory, Catalog catalog) {
super(parserFactory);
setCatalog(catalog);
}
/**
* Are we in an extension namespace?
*
@ -102,7 +107,7 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
return;
}
/** The SAX <code>startDocument</code> method does nothing. */
/** The SAX <code>startDocument</code> */
public void startDocument ()
throws SAXException {
baseURIStack.push(catalog.getCurrentBase());
@ -371,14 +376,14 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
}
if (localName.equals("doctype")) {
entryType = catalog.DOCTYPE;
entryType = Catalog.DOCTYPE;
entryArgs.add(atts.getValue("name"));
entryArgs.add(atts.getValue("uri"));
} else if (localName.equals("document")) {
entryType = catalog.DOCUMENT;
entryType = Catalog.DOCUMENT;
entryArgs.add(atts.getValue("uri"));
} else if (localName.equals("dtddecl")) {
entryType = catalog.DTDDECL;
entryType = Catalog.DTDDECL;
entryArgs.add(atts.getValue("publicId"));
entryArgs.add(atts.getValue("uri"));
} else if (localName.equals("entity")) {
@ -432,7 +437,7 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
&& checkAttributes(atts, attName2);
}
/** The SAX <code>endElement</code> method does nothing. */
/** The SAX <code>endElement</code> */
public void endElement (String namespaceURI,
String localName,
String qName)
@ -452,7 +457,7 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
String baseURI = (String) baseURIStack.peek();
if (!baseURI.equals(popURI)) {
entryType = catalog.BASE;
entryType = Catalog.BASE;
entryArgs.add(baseURI);
debug.message(4, "(reset) xml:base", baseURI);
@ -477,7 +482,7 @@ public class OASISXMLCatalogReader extends SAXCatalogReader implements SAXCatalo
String override = (String) overrideStack.peek();
if (!override.equals(popOverride)) {
entryType = catalog.OVERRIDE;
entryType = Catalog.OVERRIDE;
entryArgs.add(override);
overrideStack.push(override);

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// SAXCatalogParser.java - An interface for reading catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// SAXCatalogReader.java - Read XML Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -77,427 +71,423 @@ import sun.reflect.misc.ReflectUtil;
*
*/
public class SAXCatalogReader implements CatalogReader, ContentHandler, DocumentHandler {
/** The SAX Parser Factory */
protected SAXParserFactory parserFactory = null;
/** The SAX Parser Factory */
protected SAXParserFactory parserFactory = null;
/** The SAX Parser Class */
protected String parserClass = null;
/** The SAX Parser Class */
protected String parserClass = null;
/**
/**
* Mapping table from QNames to CatalogParser classes.
*
* <p>Each key in this hash table has the form "elementname"
* or "{namespaceuri}elementname". The former is used if the
* namespace URI is null.</p>
*/
protected Hashtable namespaceMap = new Hashtable();
protected Hashtable namespaceMap = new Hashtable();
/** The parser in use for the current catalog. */
private SAXCatalogParser saxParser = null;
/** The parser in use for the current catalog. */
private SAXCatalogParser saxParser = null;
/** Set if something goes horribly wrong. It allows the class to
/** Set if something goes horribly wrong. It allows the class to
* ignore the rest of the events that are received.
*/
private boolean abandonHope = false;
private boolean abandonHope = false;
/** The Catalog that we're working for. */
private Catalog catalog;
/** The Catalog that we're working for. */
private Catalog catalog;
/** Set the XML SAX Parser Factory.
*/
public void setParserFactory(SAXParserFactory parserFactory) {
this.parserFactory = parserFactory;
}
/** Set the XML SAX Parser Factory.
*/
public void setParserFactory(SAXParserFactory parserFactory) {
this.parserFactory = parserFactory;
}
/** Set the XML SAX Parser Class
*/
public void setParserClass(String parserClass) {
this.parserClass = parserClass;
}
/** Set the XML SAX Parser Class
*/
public void setParserClass(String parserClass) {
this.parserClass = parserClass;
}
/** Get the parser factory currently in use. */
public SAXParserFactory getParserFactory() {
return parserFactory;
}
/** Get the parser factory currently in use. */
public SAXParserFactory getParserFactory() {
return parserFactory;
}
/** Get the parser class currently in use. */
public String getParserClass() {
return parserClass;
}
/** Get the parser class currently in use. */
public String getParserClass() {
return parserClass;
}
/** The debug class to use for this reader.
*
* This is a bit of a hack. Anyway, whenever we read for a catalog,
* we extract the debug object
* from the catalog's manager so that we can use it to print messages.
*
* In production, we don't really expect any messages so it doesn't
* really matter. But it's still a bit of a hack.
*/
protected Debug debug = CatalogManager.getStaticManager().debug;
/** The debug class to use for this reader.
*
* This is a bit of a hack. Anyway, whenever we read for a catalog,
* we extract the debug object
* from the catalog's manager so that we can use it to print messages.
*
* In production, we don't really expect any messages so it doesn't
* really matter. But it's still a bit of a hack.
*/
protected Debug debug = CatalogManager.getStaticManager().debug;
/** The constructor */
public SAXCatalogReader() {
parserFactory = null;
parserClass = null;
}
/** The constructor */
public SAXCatalogReader() {
parserFactory = null;
parserClass = null;
}
/** The constructor */
public SAXCatalogReader(SAXParserFactory parserFactory) {
this.parserFactory = parserFactory;
}
/** The constructor */
public SAXCatalogReader(SAXParserFactory parserFactory) {
this.parserFactory = parserFactory;
}
/** The constructor */
public SAXCatalogReader(String parserClass) {
this.parserClass = parserClass;
}
/** The constructor */
public SAXCatalogReader(String parserClass) {
this.parserClass = parserClass;
}
/** Set the SAXCatalogParser class for the given namespace/root
/**
* Set the SAXCatalogParser class for the given namespace/root
* element type.
*/
public void setCatalogParser(String namespaceURI,
String rootElement,
String parserClass) {
if (namespaceURI == null) {
namespaceMap.put(rootElement, parserClass);
} else {
namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
public void setCatalogParser(String namespaceURI,
String rootElement,
String parserClass) {
namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
namespaceMap.put("{"+namespaceURI+"}"+rootElement, parserClass);
}
}
/** Get the SAXCatalogParser class for the given namespace/root
/**
* Get the SAXCatalogParser class for the given namespace/root
* element type.
*/
public String getCatalogParser(String namespaceURI,
String rootElement) {
if (namespaceURI == null) {
return (String) namespaceMap.get(rootElement);
} else {
return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
}
}
/**
* Parse an XML Catalog file.
*
* @param catalog The catalog to which this catalog file belongs
* @param fileUrl The URL or filename of the catalog file to process
*
* @throws MalformedURLException Improper fileUrl
* @throws IOException Error reading catalog file
*/
public void readCatalog(Catalog catalog, String fileUrl)
throws MalformedURLException, IOException,
CatalogException {
URL url = null;
try {
url = new URL(fileUrl);
} catch (MalformedURLException e) {
url = new URL("file:///" + fileUrl);
public String getCatalogParser(String namespaceURI,
String rootElement) {
namespaceURI = namespaceURI != null ? namespaceURI.trim() : "";
return (String) namespaceMap.get("{"+namespaceURI+"}"+rootElement);
}
debug = catalog.getCatalogManager().debug;
/**
* Parse an XML Catalog file.
*
* @param catalog The catalog to which this catalog file belongs
* @param fileUrl The URL or filename of the catalog file to process
*
* @throws MalformedURLException Improper fileUrl
* @throws IOException Error reading catalog file
*/
public void readCatalog(Catalog catalog, String fileUrl)
throws MalformedURLException, IOException,
CatalogException {
try {
URLConnection urlCon = url.openConnection();
readCatalog(catalog, urlCon.getInputStream());
} catch (FileNotFoundException e) {
catalog.getCatalogManager().debug.message(1, "Failed to load catalog, file not found",
URL url = null;
try {
url = new URL(fileUrl);
} catch (MalformedURLException e) {
url = new URL("file:///" + fileUrl);
}
debug = catalog.getCatalogManager().debug;
try {
URLConnection urlCon = url.openConnection();
readCatalog(catalog, urlCon.getInputStream());
} catch (FileNotFoundException e) {
catalog.getCatalogManager().debug.message(1, "Failed to load catalog, file not found",
url.toString());
}
}
/**
* Parse an XML Catalog stream.
*
* @param catalog The catalog to which this catalog file belongs
* @param is The input stream from which the catalog will be read
*
* @throws MalformedURLException Improper fileUrl
* @throws IOException Error reading catalog file
* @throws CatalogException A Catalog exception
*/
public void readCatalog(Catalog catalog, InputStream is)
throws IOException, CatalogException {
// Create an instance of the parser
if (parserFactory == null && parserClass == null) {
debug.message(1, "Cannot read SAX catalog without a parser");
throw new CatalogException(CatalogException.UNPARSEABLE);
}
debug = catalog.getCatalogManager().debug;
EntityResolver bResolver = catalog.getCatalogManager().getBootstrapResolver();
this.catalog = catalog;
try {
if (parserFactory != null) {
SAXParser parser = parserFactory.newSAXParser();
SAXParserHandler spHandler = new SAXParserHandler();
spHandler.setContentHandler(this);
if (bResolver != null) {
spHandler.setEntityResolver(bResolver);
}
parser.parse(new InputSource(is), spHandler);
} else {
Parser parser = (Parser) ReflectUtil.forName(parserClass).newInstance();
parser.setDocumentHandler(this);
if (bResolver != null) {
parser.setEntityResolver(bResolver);
}
/**
* Parse an XML Catalog stream.
*
* @param catalog The catalog to which this catalog file belongs
* @param is The input stream from which the catalog will be read
*
* @throws MalformedURLException Improper fileUrl
* @throws IOException Error reading catalog file
* @throws CatalogException A Catalog exception
*/
public void readCatalog(Catalog catalog, InputStream is)
throws IOException, CatalogException {
// Create an instance of the parser
if (parserFactory == null && parserClass == null) {
debug.message(1, "Cannot read SAX catalog without a parser");
throw new CatalogException(CatalogException.UNPARSEABLE);
}
parser.parse(new InputSource(is));
}
} catch (ClassNotFoundException cnfe) {
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (IllegalAccessException iae) {
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (InstantiationException ie) {
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (ParserConfigurationException pce) {
throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
} catch (SAXException se) {
Exception e = se.getException();
// FIXME: there must be a better way
UnknownHostException uhe = new UnknownHostException();
FileNotFoundException fnfe = new FileNotFoundException();
if (e != null) {
if (e.getClass() == uhe.getClass()) {
throw new CatalogException(CatalogException.PARSE_FAILED,
e.toString());
} else if (e.getClass() == fnfe.getClass()) {
throw new CatalogException(CatalogException.PARSE_FAILED,
e.toString());
debug = catalog.getCatalogManager().debug;
EntityResolver bResolver = catalog.getCatalogManager().getBootstrapResolver();
this.catalog = catalog;
try {
if (parserFactory != null) {
SAXParser parser = parserFactory.newSAXParser();
SAXParserHandler spHandler = new SAXParserHandler();
spHandler.setContentHandler(this);
if (bResolver != null) {
spHandler.setEntityResolver(bResolver);
}
parser.parse(new InputSource(is), spHandler);
} else {
Parser parser = (Parser) ReflectUtil.forName(parserClass).newInstance();
parser.setDocumentHandler(this);
if (bResolver != null) {
parser.setEntityResolver(bResolver);
}
parser.parse(new InputSource(is));
}
} catch (ClassNotFoundException cnfe) {
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (IllegalAccessException iae) {
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (InstantiationException ie) {
throw new CatalogException(CatalogException.UNPARSEABLE);
} catch (ParserConfigurationException pce) {
throw new CatalogException(CatalogException.UNKNOWN_FORMAT);
} catch (SAXException se) {
Exception e = se.getException();
// FIXME: there must be a better way
UnknownHostException uhe = new UnknownHostException();
FileNotFoundException fnfe = new FileNotFoundException();
if (e != null) {
if (e.getClass() == uhe.getClass()) {
throw new CatalogException(CatalogException.PARSE_FAILED,
e.toString());
} else if (e.getClass() == fnfe.getClass()) {
throw new CatalogException(CatalogException.PARSE_FAILED,
e.toString());
}
}
throw new CatalogException(se);
}
}
throw new CatalogException(se);
}
}
// ----------------------------------------------------------------------
// Implement the SAX ContentHandler interface
/** The SAX <code>setDocumentLocator</code> method. Does nothing. */
public void setDocumentLocator (Locator locator) {
if (saxParser != null) {
saxParser.setDocumentLocator(locator);
}
}
/** The SAX <code>startDocument</code> method. Does nothing. */
public void startDocument () throws SAXException {
saxParser = null;
abandonHope = false;
return;
}
/** The SAX <code>endDocument</code> method. Does nothing. */
public void endDocument ()throws SAXException {
if (saxParser != null) {
saxParser.endDocument();
}
}
/**
* The SAX <code>startElement</code> method.
*
* <p>The catalog parser is selected based on the namespace of the
* first element encountered in the catalog.</p>
*/
public void startElement (String name,
AttributeList atts)
throws SAXException {
if (abandonHope) {
return;
}
if (saxParser == null) {
String prefix = "";
if (name.indexOf(':') > 0) {
prefix = name.substring(0, name.indexOf(':'));
}
// ----------------------------------------------------------------------
// Implement the SAX ContentHandler interface
String localName = name;
if (localName.indexOf(':') > 0) {
localName = localName.substring(localName.indexOf(':')+1);
}
String namespaceURI = null;
if (prefix.equals("")) {
namespaceURI = atts.getValue("xmlns");
} else {
namespaceURI = atts.getValue("xmlns:" + prefix);
}
String saxParserClass = getCatalogParser(namespaceURI,
localName);
if (saxParserClass == null) {
abandonHope = true;
if (namespaceURI == null) {
debug.message(2, "No Catalog parser for " + name);
} else {
debug.message(2, "No Catalog parser for "
+ "{" + namespaceURI + "}"
+ name);
/** The SAX <code>setDocumentLocator</code> method. Does nothing. */
public void setDocumentLocator (Locator locator) {
if (saxParser != null) {
saxParser.setDocumentLocator(locator);
}
}
/** The SAX <code>startDocument</code> method. Does nothing. */
public void startDocument () throws SAXException {
saxParser = null;
abandonHope = false;
return;
}
try {
saxParser = (SAXCatalogParser)
ReflectUtil.forName(saxParserClass).newInstance();
saxParser.setCatalog(catalog);
saxParser.startDocument();
saxParser.startElement(name, atts);
} catch (ClassNotFoundException cnfe) {
saxParser = null;
abandonHope = true;
debug.message(2, cnfe.toString());
} catch (InstantiationException ie) {
saxParser = null;
abandonHope = true;
debug.message(2, ie.toString());
} catch (IllegalAccessException iae) {
saxParser = null;
abandonHope = true;
debug.message(2, iae.toString());
} catch (ClassCastException cce ) {
saxParser = null;
abandonHope = true;
debug.message(2, cce.toString());
}
} else {
saxParser.startElement(name, atts);
}
}
/**
* The SAX2 <code>startElement</code> method.
*
* <p>The catalog parser is selected based on the namespace of the
* first element encountered in the catalog.</p>
*/
public void startElement (String namespaceURI,
String localName,
String qName,
Attributes atts)
throws SAXException {
if (abandonHope) {
return;
}
if (saxParser == null) {
String saxParserClass = getCatalogParser(namespaceURI,
localName);
if (saxParserClass == null) {
abandonHope = true;
if (namespaceURI == null) {
debug.message(2, "No Catalog parser for " + localName);
} else {
debug.message(2, "No Catalog parser for "
+ "{" + namespaceURI + "}"
+ localName);
/** The SAX <code>endDocument</code> method. Does nothing. */
public void endDocument ()throws SAXException {
if (saxParser != null) {
saxParser.endDocument();
}
return;
}
try {
saxParser = (SAXCatalogParser)
ReflectUtil.forName(saxParserClass).newInstance();
saxParser.setCatalog(catalog);
saxParser.startDocument();
saxParser.startElement(namespaceURI, localName, qName, atts);
} catch (ClassNotFoundException cnfe) {
saxParser = null;
abandonHope = true;
debug.message(2, cnfe.toString());
} catch (InstantiationException ie) {
saxParser = null;
abandonHope = true;
debug.message(2, ie.toString());
} catch (IllegalAccessException iae) {
saxParser = null;
abandonHope = true;
debug.message(2, iae.toString());
} catch (ClassCastException cce ) {
saxParser = null;
abandonHope = true;
debug.message(2, cce.toString());
}
} else {
saxParser.startElement(namespaceURI, localName, qName, atts);
}
}
/** The SAX <code>endElement</code> method. Does nothing. */
public void endElement (String name) throws SAXException {
if (saxParser != null) {
saxParser.endElement(name);
}
}
/**
* The SAX <code>startElement</code> method.
*
* <p>The catalog parser is selected based on the namespace of the
* first element encountered in the catalog.</p>
*/
public void startElement (String name,
AttributeList atts)
throws SAXException {
/** The SAX2 <code>endElement</code> method. Does nothing. */
public void endElement (String namespaceURI,
String localName,
String qName) throws SAXException {
if (saxParser != null) {
saxParser.endElement(namespaceURI, localName, qName);
}
}
if (abandonHope) {
return;
}
/** The SAX <code>characters</code> method. Does nothing. */
public void characters (char ch[], int start, int length)
throws SAXException {
if (saxParser != null) {
saxParser.characters(ch, start, length);
}
}
if (saxParser == null) {
String prefix = "";
if (name.indexOf(':') > 0) {
prefix = name.substring(0, name.indexOf(':'));
}
/** The SAX <code>ignorableWhitespace</code> method. Does nothing. */
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException {
if (saxParser != null) {
saxParser.ignorableWhitespace(ch, start, length);
}
}
String localName = name;
if (localName.indexOf(':') > 0) {
localName = localName.substring(localName.indexOf(':')+1);
}
/** The SAX <code>processingInstruction</code> method. Does nothing. */
public void processingInstruction (String target, String data)
throws SAXException {
if (saxParser != null) {
saxParser.processingInstruction(target, data);
}
}
String namespaceURI = null;
if (prefix.length() == 0) {
namespaceURI = atts.getValue("xmlns");
} else {
namespaceURI = atts.getValue("xmlns:" + prefix);
}
/** The SAX <code>startPrefixMapping</code> method. Does nothing. */
public void startPrefixMapping (String prefix, String uri)
throws SAXException {
if (saxParser != null) {
saxParser.startPrefixMapping (prefix, uri);
}
}
String saxParserClass = getCatalogParser(namespaceURI,
localName);
/** The SAX <code>endPrefixMapping</code> method. Does nothing. */
public void endPrefixMapping (String prefix)
throws SAXException {
if (saxParser != null) {
saxParser.endPrefixMapping (prefix);
}
}
if (saxParserClass == null) {
abandonHope = true;
if (namespaceURI == null) {
debug.message(2, "No Catalog parser for " + name);
} else {
debug.message(2, "No Catalog parser for "
+ "{" + namespaceURI + "}"
+ name);
}
return;
}
/** The SAX <code>skippedentity</code> method. Does nothing. */
public void skippedEntity (String name)
throws SAXException {
if (saxParser != null) {
saxParser.skippedEntity(name);
try {
saxParser = (SAXCatalogParser)
ReflectUtil.forName(saxParserClass).newInstance();
saxParser.setCatalog(catalog);
saxParser.startDocument();
saxParser.startElement(name, atts);
} catch (ClassNotFoundException cnfe) {
saxParser = null;
abandonHope = true;
debug.message(2, cnfe.toString());
} catch (InstantiationException ie) {
saxParser = null;
abandonHope = true;
debug.message(2, ie.toString());
} catch (IllegalAccessException iae) {
saxParser = null;
abandonHope = true;
debug.message(2, iae.toString());
} catch (ClassCastException cce ) {
saxParser = null;
abandonHope = true;
debug.message(2, cce.toString());
}
} else {
saxParser.startElement(name, atts);
}
}
/**
* The SAX2 <code>startElement</code> method.
*
* <p>The catalog parser is selected based on the namespace of the
* first element encountered in the catalog.</p>
*/
public void startElement (String namespaceURI,
String localName,
String qName,
Attributes atts)
throws SAXException {
if (abandonHope) {
return;
}
if (saxParser == null) {
String saxParserClass = getCatalogParser(namespaceURI,
localName);
if (saxParserClass == null) {
abandonHope = true;
if (namespaceURI == null) {
debug.message(2, "No Catalog parser for " + localName);
} else {
debug.message(2, "No Catalog parser for "
+ "{" + namespaceURI + "}"
+ localName);
}
return;
}
try {
saxParser = (SAXCatalogParser)
ReflectUtil.forName(saxParserClass).newInstance();
saxParser.setCatalog(catalog);
saxParser.startDocument();
saxParser.startElement(namespaceURI, localName, qName, atts);
} catch (ClassNotFoundException cnfe) {
saxParser = null;
abandonHope = true;
debug.message(2, cnfe.toString());
} catch (InstantiationException ie) {
saxParser = null;
abandonHope = true;
debug.message(2, ie.toString());
} catch (IllegalAccessException iae) {
saxParser = null;
abandonHope = true;
debug.message(2, iae.toString());
} catch (ClassCastException cce ) {
saxParser = null;
abandonHope = true;
debug.message(2, cce.toString());
}
} else {
saxParser.startElement(namespaceURI, localName, qName, atts);
}
}
/** The SAX <code>endElement</code> method. Does nothing. */
public void endElement (String name) throws SAXException {
if (saxParser != null) {
saxParser.endElement(name);
}
}
/** The SAX2 <code>endElement</code> method. Does nothing. */
public void endElement (String namespaceURI,
String localName,
String qName) throws SAXException {
if (saxParser != null) {
saxParser.endElement(namespaceURI, localName, qName);
}
}
/** The SAX <code>characters</code> method. Does nothing. */
public void characters (char ch[], int start, int length)
throws SAXException {
if (saxParser != null) {
saxParser.characters(ch, start, length);
}
}
/** The SAX <code>ignorableWhitespace</code> method. Does nothing. */
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException {
if (saxParser != null) {
saxParser.ignorableWhitespace(ch, start, length);
}
}
/** The SAX <code>processingInstruction</code> method. Does nothing. */
public void processingInstruction (String target, String data)
throws SAXException {
if (saxParser != null) {
saxParser.processingInstruction(target, data);
}
}
/** The SAX <code>startPrefixMapping</code> method. Does nothing. */
public void startPrefixMapping (String prefix, String uri)
throws SAXException {
if (saxParser != null) {
saxParser.startPrefixMapping (prefix, uri);
}
}
/** The SAX <code>endPrefixMapping</code> method. Does nothing. */
public void endPrefixMapping (String prefix)
throws SAXException {
if (saxParser != null) {
saxParser.endPrefixMapping (prefix);
}
}
/** The SAX <code>skippedentity</code> method. Does nothing. */
public void skippedEntity (String name)
throws SAXException {
if (saxParser != null) {
saxParser.skippedEntity(name);
}
}
}
}

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// SAXParserHandler.java - An entity-resolving DefaultHandler
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// TR9401CatalogReader.java - Read OASIS Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -23,13 +17,14 @@
package com.sun.org.apache.xml.internal.resolver.readers;
import java.io.InputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Vector;
import com.sun.org.apache.xml.internal.resolver.Catalog;
import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
import com.sun.org.apache.xml.internal.resolver.CatalogException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Locale;
import java.util.Vector;
/**
* Parses OASIS Open Catalog files.
@ -97,7 +92,7 @@ public class TR9401CatalogReader extends TextCatalogReader {
if (caseSensitive) {
entryToken = token;
} else {
entryToken = token.toUpperCase();
entryToken = token.toUpperCase(Locale.ENGLISH);
}
if (entryToken.equals("DELEGATE")) {

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// TextCatalogReader.java - Read text/plain Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -23,18 +17,19 @@
package com.sun.org.apache.xml.internal.resolver.readers;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.util.Vector;
import java.util.Stack;
import com.sun.org.apache.xml.internal.resolver.Catalog;
import com.sun.org.apache.xml.internal.resolver.CatalogEntry;
import com.sun.org.apache.xml.internal.resolver.CatalogException;
import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Locale;
import java.util.Stack;
import java.util.Vector;
/**
* Parses plain text Catalog files.
@ -140,7 +135,7 @@ public class TextCatalogReader implements CatalogReader {
if (caseSensitive) {
entryToken = token;
} else {
entryToken = token.toUpperCase();
entryToken = token.toUpperCase(Locale.ENGLISH);
}
try {

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// XCatalogReader.java - Read XML Catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -34,7 +28,7 @@ import org.xml.sax.*;
import javax.xml.parsers.*;
/**
* Parse "xcatalog" XML Catalog files, this is the XML Catalog format
* Parse "XCatalog" XML Catalog files, this is the XML Catalog format
* developed by John Cowan and supported by Apache.
*
* @see Catalog
@ -52,6 +46,7 @@ public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser
/** Set the current catalog. */
public void setCatalog (Catalog catalog) {
this.catalog = catalog;
debug = catalog.getCatalogManager().debug;
}
/** Get the current catalog. */
@ -59,13 +54,19 @@ public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser
return catalog;
}
/** The constructor */
public XCatalogReader(SAXParserFactory parserFactory) {
/** Default constructor */
public XCatalogReader() {
super();
}
/** Constructor allowing for providing custom SAX parser factory */
public XCatalogReader(SAXParserFactory parserFactory, Catalog catalog) {
super(parserFactory);
setCatalog(catalog);
}
// ----------------------------------------------------------------------
// Implement the SAX DocumentHandler interface
// Implement the SAX ContentHandler interface
/** The SAX <code>setDocumentLocator</code> method does nothing. */
public void setDocumentLocator (Locator locator) {
@ -106,44 +107,44 @@ public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser
Vector entryArgs = new Vector();
if (localName.equals("Base")) {
entryType = catalog.BASE;
entryType = Catalog.BASE;
entryArgs.add(atts.getValue("HRef"));
catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef"));
debug.message(4, "Base", atts.getValue("HRef"));
} else if (localName.equals("Delegate")) {
entryType = catalog.DELEGATE_PUBLIC;
entryArgs.add(atts.getValue("PublicId"));
entryType = Catalog.DELEGATE_PUBLIC;
entryArgs.add(atts.getValue("PublicID"));
entryArgs.add(atts.getValue("HRef"));
catalog.getCatalogManager().debug.message(4, "Delegate",
PublicId.normalize(atts.getValue("PublicId")),
debug.message(4, "Delegate",
PublicId.normalize(atts.getValue("PublicID")),
atts.getValue("HRef"));
} else if (localName.equals("Extend")) {
entryType = catalog.CATALOG;
entryType = Catalog.CATALOG;
entryArgs.add(atts.getValue("HRef"));
catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef"));
debug.message(4, "Extend", atts.getValue("HRef"));
} else if (localName.equals("Map")) {
entryType = catalog.PUBLIC;
entryArgs.add(atts.getValue("PublicId"));
entryType = Catalog.PUBLIC;
entryArgs.add(atts.getValue("PublicID"));
entryArgs.add(atts.getValue("HRef"));
catalog.getCatalogManager().debug.message(4, "Map",
PublicId.normalize(atts.getValue("PublicId")),
debug.message(4, "Map",
PublicId.normalize(atts.getValue("PublicID")),
atts.getValue("HRef"));
} else if (localName.equals("Remap")) {
entryType = catalog.SYSTEM;
entryArgs.add(atts.getValue("SystemId"));
entryType = Catalog.SYSTEM;
entryArgs.add(atts.getValue("SystemID"));
entryArgs.add(atts.getValue("HRef"));
catalog.getCatalogManager().debug.message(4, "Remap",
atts.getValue("SystemId"),
debug.message(4, "Remap",
atts.getValue("SystemID"),
atts.getValue("HRef"));
} else if (localName.equals("XMLCatalog")) {
} else if (localName.equals("XCatalog")) {
// nop, start of catalog
} else {
// This is equivalent to an invalid catalog entry type
catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
debug.message(1, "Invalid catalog entry type", localName);
}
if (entryType >= 0) {
@ -152,21 +153,21 @@ public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser
catalog.addEntry(ce);
} catch (CatalogException cex) {
if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) {
catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName);
debug.message(1, "Invalid catalog entry type", localName);
} else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) {
catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName);
debug.message(1, "Invalid catalog entry", localName);
}
}
}
}
}
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
String localName,
String qName)
throws SAXException {
return;
}
/** The SAX <code>endElement</code> method does nothing. */
public void endElement (String namespaceURI,
String localName,
String qName)
throws SAXException {
return;
}
/** The SAX <code>characters</code> method does nothing. */
public void characters (char ch[], int start, int length)
@ -185,4 +186,23 @@ public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser
throws SAXException {
return;
}
/** The SAX <code>skippedEntity</code> method does nothing. */
public void skippedEntity (String name)
throws SAXException {
return;
}
/** The SAX <code>startPrefixMapping</code> method does nothing. */
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
return;
}
/** The SAX <code>endPrefixMapping</code> method does nothing. */
public void endPrefixMapping(String prefix)
throws SAXException {
return;
}
}

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// CatalogResolver.java - A SAX EntityResolver/JAXP URI Resolver
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -218,7 +212,10 @@ public class CatalogResolver implements EntityResolver, URIResolver {
return iSource;
} catch (Exception e) {
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
catalogManager.debug.message(1,
"Failed to create InputSource ("
+ e.toString()
+ ")", resolved);
return null;
}
}

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// ResolvingParser.java - An interface for reading catalog files
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -67,17 +61,12 @@ import com.sun.org.apache.xml.internal.resolver.helpers.FileURL;
*/
public class ResolvingParser
implements Parser, DTDHandler, DocumentHandler, EntityResolver {
/** Make the parser Namespace aware? */
public static boolean namespaceAware = true;
/** Make the parser validating? */
public static boolean validating = false;
/** Suppress explanatory message?
*
* @see #parse(InputSource)
*/
public static boolean suppressExplanation = false;
private static final boolean suppressExplanation = false;
/** The underlying parser. */
private SAXParser saxParser = null;
@ -103,9 +92,6 @@ public class ResolvingParser
/** Are we in the prolog? Is an oasis-xml-catalog PI valid now? */
private boolean allowXMLCatalogPI = false;
/** Has an oasis-xml-catalog PI been seen? */
private boolean oasisXMLCatalogPI = false;
/** The base URI of the input document, if known. */
private URL baseURL = null;
@ -125,8 +111,8 @@ public class ResolvingParser
catalogResolver = new CatalogResolver(catalogManager);
SAXParserFactory spf = catalogManager.useServicesMechanism() ?
SAXParserFactory.newInstance() : new SAXParserFactoryImpl();
spf.setNamespaceAware(namespaceAware);
spf.setValidating(validating);
spf.setNamespaceAware(true);
spf.setValidating(false);
try {
saxParser = spf.newSAXParser();
@ -289,7 +275,6 @@ public class ResolvingParser
if (catalog != null) {
try {
catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString());
oasisXMLCatalogPI = true;
if (piCatalogResolver == null) {
piCatalogResolver = new CatalogResolver(true);
@ -396,7 +381,10 @@ public class ResolvingParser
return iSource;
} catch (Exception e) {
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
catalogManager.debug.message(1,
"Failed to create InputSource ("
+ e.toString()
+ ")", resolved);
return null;
}
} else {

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// ResolvingXMLFilter.java - An XMLFilter that performs catalog resolution
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -61,7 +55,7 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
*
* @see #parse(InputSource)
*/
public static boolean suppressExplanation = false;
private static boolean suppressExplanation = false;
/** The manager for the underlying resolver. */
CatalogManager catalogManager = CatalogManager.getStaticManager();
@ -75,9 +69,6 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
/** Are we in the prolog? Is an oasis-xml-catalog PI valid now? */
private boolean allowXMLCatalogPI = false;
/** Has an oasis-xml-catalog PI been seen? */
private boolean oasisXMLCatalogPI = false;
/** The base URI of the input document, if known. */
private URL baseURL = null;
@ -202,7 +193,10 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
return iSource;
} catch (Exception e) {
catalogManager.debug.message(1, "Failed to create InputSource", resolved);
catalogManager.debug.message(1,
"Failed to create InputSource ("
+ e.toString()
+ ")", resolved);
return null;
}
} else {
@ -289,7 +283,6 @@ public class ResolvingXMLFilter extends XMLFilterImpl {
if (catalog != null) {
try {
catalogManager.debug.message(4,"oasis-xml-catalog", catalog.toString());
oasisXMLCatalogPI = true;
if (piCatalogResolver == null) {
piCatalogResolver = new CatalogResolver(true);

View File

@ -1,16 +1,10 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
// ResolvingXMLReader.java - An XMLReader that performs catalog resolution
/*
* Copyright 2001-2004 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -23,7 +17,6 @@
package com.sun.org.apache.xml.internal.resolver.tools;
import org.xml.sax.*;
import javax.xml.parsers.*;
@ -48,10 +41,10 @@ import com.sun.org.apache.xml.internal.resolver.*;
*/
public class ResolvingXMLReader extends ResolvingXMLFilter {
/** Make the parser Namespace aware? */
public static boolean namespaceAware = true;
private static final boolean namespaceAware = true;
/** Make the parser validating? */
public static boolean validating = false;
private static final boolean validating = false;
/**
* Construct a new reader from the JAXP factory.