< prev index next >

src/jdk.xml.bind/share/classes/com/sun/xml/internal/dtdparser/Resolver.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -33,56 +33,57 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Hashtable;
+import java.util.Locale;
 
 /**
  * This entity resolver class provides a number of utilities which can help
  * managment of external parsed entities in XML.  These are commonly used
  * to hold markup declarations that are to be used as part of a Document
  * Type Declaration (DTD), or to hold text marked up with XML.
- * <p/>
+ * <p>
  * <P> Features include: <UL>
- * <p/>
+ *
  * <LI> Static factory methods are provided for constructing SAX InputSource
  * objects from Files, URLs, or MIME objects.  This eliminates a class of
- * error-prone coding in applications.
- * <p/>
- * <LI> Character encodings for XML documents are correctly supported: <UL>
- * <p/>
+ * error-prone coding in applications.</LI>
+ *
+ * <LI> Character encodings for XML documents are correctly supported:<UL>
+ *
  * <LI> The encodings defined in the RFCs for MIME content types
  * (2046 for general MIME, and 2376 for XML in particular), are
  * supported, handling <em>charset=...</em> attributes and accepting
- * content types which are known to be safe for use with XML;
- * <p/>
+ * content types which are known to be safe for use with XML;</LI>
+ *
  * <LI> The character encoding autodetection algorithm identified
  * in the XML specification is used, and leverages all of
- * the JDK 1.1 (and later) character encoding support.
- * <p/>
+ * the JDK 1.1 (and later) character encoding support.</LI>
+ *
  * <LI> The use of MIME typing may optionally be disabled, forcing the
  * use of autodetection, to support web servers which don't correctly
  * report MIME types for XML.  For example, they may report text that
  * is encoded in EUC-JP as being US-ASCII text, leading to fatal
- * errors during parsing.
- * <p/>
+ * errors during parsing.</LI>
+ *
  * <LI> The InputSource objects returned by this class always
  * have a <code>java.io.Reader</code> available as the "character
- * stream" property.
- * <p/>
- * </UL>
- * <p/>
+ * stream" property.</LI>
+ *
+ * </UL></LI>
+ *
  * <LI> Catalog entries can map public identifiers to Java resources or
  * to local URLs.  These are used to reduce network dependencies and loads,
  * and will often be used for external DTD components.  For example, packages
  * shipping DTD files as resources in JAR files can eliminate network traffic
  * when accessing them, and sites may provide local caches of common DTDs.
  * Note that no particular catalog syntax is supported by this class, only
- * the notion of a set of entries.
- * <p/>
+ * the notion of a set of entries.</LI>
+ *
  * </UL>
- * <p/>
+ * <p>
  * <P> Subclasses can perform tasks such as supporting new URI schemes for
  * URIs which are not URLs, such as URNs (see RFC 2396) or for accessing
  * MIME entities which are part of a <em>multipart/related</em> group
  * (see RFC 2387).  They may also be used to support particular catalog
  * syntaxes, such as the <a href="http://www.oasis-open.org/html/a401.htm">

@@ -124,30 +125,30 @@
      */
     public Resolver() {
     }
 
     /**
-     * Returns an input source, using the MIME type information and URL
+     * <p>Returns an input source, using the MIME type information and URL
      * scheme to statically determine the correct character encoding if
      * possible and otherwise autodetecting it.  MIME carefully specifies
      * the character encoding defaults, and how attributes of the content
      * type can change it.  XML further specifies two mandatory encodings
      * (UTF-8 and UTF-16), and includes an XML declaration which can be
      * used to internally label most documents encoded using US-ASCII
      * supersets (such as Shift_JIS, EUC-JP, ISO-2022-*, ISO-8859-*, and
-     * more).
-     * <p/>
-     * <P> This method can be used to access XML documents which do not
+     * more).</p>
+     *
+     * <p> This method can be used to access XML documents which do not
      * have URIs (such as servlet input streams, or most JavaMail message
      * entities) and to support access methods such as HTTP POST or PUT.
-     * (URLs normally return content using the GET method.)
-     * <p/>
-     * <P> <em> The caller should set the system ID in order for relative URIs
+     * (URLs normally return content using the GET method.)</p>
+     *
+     * <p> <em> The caller should set the system ID in order for relative URIs
      * found in this document to be interpreted correctly.</em> In some cases,
      * a custom resolver will need to be used; for example, documents
      * may be grouped in a single MIME "multipart/related" bundle, and
-     * relative URLs would refer to other documents in that bundle.
+     * relative URLs would refer to other documents in that bundle.</p>
      *
      * @param contentType The MIME content type for the source for which
      *                    an InputSource is desired, such as <em>text/xml;charset=utf-8</em>.
      * @param stream      The input byte stream for the input source.
      * @param checkType   If true, this verifies that the content type is known

@@ -164,11 +165,11 @@
         String charset = null;
 
         if (contentType != null) {
             int index;
 
-            contentType = contentType.toLowerCase();
+            contentType = contentType.toLowerCase(Locale.ENGLISH);
             index = contentType.indexOf(';');
             if (index != -1) {
                 String attributes;
 
                 attributes = contentType.substring(index + 1);

@@ -293,28 +294,29 @@
      * be mapped to a preferred form of the entity, the URI is used.  To
      * resolve the entity, first a local catalog mapping names to URIs is
      * consulted.  If no mapping is found there, a catalog mapping names
      * to java resources is consulted.  Finally, if neither mapping found
      * a copy of the entity, the specified URI is used.
-     * <p/>
+     * <p>
      * <P> When a URI is used, <a href="#createInputSource">
      * createInputSource</a> is used to correctly deduce the character
      * encoding used by this entity.  No MIME type checking is done.
      *
      * @param name Used to find alternate copies of the entity, when
      *             this value is non-null; this is the XML "public ID".
      * @param uri  Used when no alternate copy of the entity is found;
      *             this is the XML "system ID", normally a URI.
      */
+    @Override
     public InputSource resolveEntity(String name, String uri)
             throws IOException {
         InputSource retval;
         String mappedURI = name2uri(name);
         InputStream stream;
 
         // prefer explicit URI mappings, then bundled resources...
-        if (mappedURI == null && (stream = mapResource(name)) != null) {
+        if (mappedURI == null && (stream = mapResource(name)) != null && id2resource != null) {
             uri = "java:resource:" + (String) id2resource.get(name);
             retval = new InputSource(XmlReader.createReader(stream));
 
             // ...and treat all URIs the same (as URLs for now).
         } else {

@@ -421,11 +423,11 @@
      * resource in a given class loader, typically distributed with a
      * software package.  This resource will be preferred over system IDs
      * included in XML documents.  This mechanism should most typically be
      * used for Document Type Definitions (DTDs), where the public IDs are
      * formally managed and versioned.
-     * <p/>
+     * <p>
      * <P> If a mapping to a URI has been provided, that mapping takes
      * precedence over this one.
      *
      * @param publicId     The managed public ID being mapped
      * @param resourceName The name of the Java resource
< prev index next >