src/java.xml/share/classes/com/sun/org/apache/xml/internal/resolver/Catalog.java
Print this page
*** 1,19 ****
/*
! * 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
- *
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- 1,13 ----
/*
! * 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*** 23,55 ****
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.PublicId;
- import com.sun.org.apache.xml.internal.resolver.readers.CatalogReader;
- 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;
-
/**
* Represents OASIS Open Catalog files.
*
* <p>This class implements the semantics of OASIS Open Catalog files
* (defined by
--- 17,45 ----
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 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 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.
*
* <p>This class implements the semantics of OASIS Open Catalog files
* (defined by
*** 152,163 ****
* semantics to be implemented for TR9401 text-based catalogs, XML
* catalogs, or any number of other storage formats.</p>
*
* <p>Additional catalogs may also be loaded with the
* {@link #parseCatalog} method.</p>
- * </dd>
- * </dl>
*
* <p><b>Change Log:</b></p>
* <dl>
* <dt>2.0</dt>
* <dd><p>Rewrite to use CatalogReaders.</p></dd>
--- 142,151 ----
*** 821,831 ****
try {
// tack on a basename because URLs point to files not dirs
catalogCwd = FileURL.makeURL("basename");
} catch (MalformedURLException e) {
String userdir = SecuritySupport.getSystemProperty("user.dir");
! userdir.replace('\\', '/');
catalogManager.debug.message(1, "Malformed URL on cwd", userdir);
catalogCwd = null;
}
// The initial base URI is the location of the catalog file
--- 809,819 ----
try {
// tack on a basename because URLs point to files not dirs
catalogCwd = FileURL.makeURL("basename");
} catch (MalformedURLException e) {
String userdir = SecuritySupport.getSystemProperty("user.dir");
! userdir = userdir.replace('\\', '/');
catalogManager.debug.message(1, "Malformed URL on cwd", userdir);
catalogCwd = null;
}
// The initial base URI is the location of the catalog file
*** 2111,2120 ****
--- 2099,2109 ----
} else {
return sysid;
}
}
+
/**
* Perform character normalization on a URI reference.
*
* @param uriref The URI reference
* @return The normalized URI reference.
*** 2121,2144 ****
*/
protected String normalizeURI(String uriref) {
if (uriref == null) {
return null;
}
! 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;
}
!
! 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) // >
--- 2110,2163 ----
*/
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;
+ }
! /**
! * 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) // >
*** 2147,2180 ****
|| (ch == 0x60) // `
|| (ch == 0x7B) // {
|| (ch == 0x7C) // |
|| (ch == 0x7D) // }
|| (ch == 0x7F)) {
! newRef.append(encodedByte(ch));
! } else {
! newRef.append((char) bytes[count]);
}
}
-
- 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;
}
}
// -----------------------------------------------------------------
/**
* Add to the current list of delegated catalogs.
--- 2166,2215 ----
|| (ch == 0x60) // `
|| (ch == 0x7B) // {
|| (ch == 0x7C) // |
|| (ch == 0x7D) // }
|| (ch == 0x7F)) {
! writeEncodedByte(ch, buffer);
}
+ else {
+ buffer.append((char) bytes[count]);
}
}
+ return buffer.toString();
+ }
/**
* 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();
! }
!
! /**
! * 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);
}
+ }
// -----------------------------------------------------------------
/**
* Add to the current list of delegated catalogs.