jaxp/src/java.xml/share/classes/javax/xml/catalog/Util.java
author joehw
Tue, 17 May 2016 14:14:15 -0700
changeset 38497 06b1977d0f4f
parent 37382 c7d898d8da12
child 40582 1dddef49982c
permissions -rw-r--r--
8156845: Uri is getting incorrectly unwrapped Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     1
/*
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     4
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    10
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    15
 * accompanied this code).
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    16
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    20
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    23
 * questions.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    24
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    25
package javax.xml.catalog;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    26
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    27
import java.io.File;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    28
import java.net.MalformedURLException;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    29
import java.net.URI;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    30
import java.net.URISyntaxException;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    31
import java.net.URL;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    32
import java.nio.file.Path;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    33
import java.nio.file.Paths;
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    34
import java.util.Iterator;
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    35
import jdk.xml.internal.SecuritySupport;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    36
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    37
/**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    38
 *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    39
 * @since 9
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    40
 */
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
    41
class Util {
38497
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    42
    final static String URN = "urn:publicid:";
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    43
    final static String PUBLICID_PREFIX = "-//";
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    44
    final static String PUBLICID_PREFIX_ALT = "+//";
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    45
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    46
    /**
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    47
     * Finds an entry in the catalog that matches with the publicId or systemId.
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    48
     *
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    49
     * The resolution follows the following rules determined by the prefer setting:
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    50
     *
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    51
     * prefer "system": attempts to resolve with a system entry;
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    52
     *                  attempts to resolve with a public entry when only
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    53
     *                  publicId is specified.
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    54
     *
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    55
     * prefer "public": attempts to resolve with a system entry;
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    56
     *                  attempts to resolve with a public entry if no matching
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    57
     *                  system entry is found.
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    58
     * @param catalog the catalog
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    59
     * @param publicId the publicId
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    60
     * @param systemId the systemId
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    61
     * @return the resolved systemId if a match is found, null otherwise
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    62
     */
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    63
    static String resolve(CatalogImpl catalog, String publicId, String systemId) {
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    64
        String resolvedSystemId = null;
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    65
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    66
        //search the current catalog
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    67
        catalog.reset();
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    68
        if (systemId != null) {
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    69
            /*
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    70
               If a system identifier is specified, it is used no matter how
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    71
            prefer is set.
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    72
            */
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    73
            resolvedSystemId = catalog.matchSystem(systemId);
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    74
        }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    75
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    76
        if (resolvedSystemId == null && publicId != null) {
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    77
            resolvedSystemId = catalog.matchPublic(publicId);
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    78
        }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    79
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    80
        //mark the catalog as having been searched before trying alternatives
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    81
        catalog.markAsSearched();
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    82
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    83
        //search alternative catalogs
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    84
        if (resolvedSystemId == null) {
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    85
            Iterator<Catalog> iter = catalog.catalogs().iterator();
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    86
            while (iter.hasNext()) {
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    87
                resolvedSystemId = resolve((CatalogImpl)iter.next(), publicId, systemId);
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    88
                if (resolvedSystemId != null) {
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    89
                    break;
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    90
                }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    91
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    92
            }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    93
        }
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    94
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    95
        return resolvedSystemId;
06b1977d0f4f 8156845: Uri is getting incorrectly unwrapped
joehw
parents: 37382
diff changeset
    96
    }
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    97
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    98
    /**
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
    99
     * Resolves the specified file path to an absolute systemId. If it is
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   100
     * relative, it shall be resolved using the base or user.dir property if
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   101
     * base is not specified.
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   102
     *
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   103
     * @param file The specified file path
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   104
     * @param baseURI the base URI
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   105
     * @return The URI
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   106
     * @throws CatalogException if the specified file path can not be converted
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   107
     * to a system id
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   108
     */
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   109
    static URI verifyAndGetURI(String file, URL baseURI)
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   110
            throws MalformedURLException, URISyntaxException, IllegalArgumentException {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   111
        URL filepath;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   112
        URI temp;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   113
        if (file != null && file.length() > 0) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   114
            File f = new File(file);
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   115
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   116
            if (baseURI != null && !f.isAbsolute()) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   117
                filepath = new URL(baseURI, fixSlashes(file));
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   118
                temp = filepath.toURI();
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   119
            } else {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   120
                temp = resolveURI(file);
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   121
            }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   122
            //Paths.get may throw IllegalArgumentException
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   123
            Path path = Paths.get(temp);
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   124
            if (path.toFile().isFile()) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   125
                return temp;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   126
            }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   127
        }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   128
        return null;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   129
    }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   130
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   131
    /**
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   132
     * Resolves the specified uri. If the uri is relative, makes it absolute by
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   133
     * the user.dir directory.
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   134
     *
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   135
     * @param uri The specified URI.
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   136
     * @return The resolved URI
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   137
     */
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   138
    static URI resolveURI(String uri) throws MalformedURLException {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   139
        if (uri == null) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   140
            uri = "";
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   141
        }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   142
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   143
        URI temp = null;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   144
        try {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   145
            URL url = new URL(uri);
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   146
            temp = url.toURI();
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   147
        } catch (MalformedURLException | URISyntaxException mue) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   148
            File file = new File(uri);
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   149
            temp = file.toURI();
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   150
        }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   151
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   152
        return temp;
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   153
    }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   154
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   155
    /**
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   156
     * Replace backslashes with forward slashes. (URLs always use forward
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   157
     * slashes.)
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   158
     *
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   159
     * @param sysid The input system identifier.
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   160
     * @return The same system identifier with backslashes turned into forward
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   161
     * slashes.
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   162
     */
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   163
    static String fixSlashes(String sysid) {
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   164
        return sysid.replace('\\', '/');
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   165
    }
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   166
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   167
    /**
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   168
     * Find catalog file paths by reading the system property, and then
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   169
     * jaxp.properties if the system property is not specified.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   170
     *
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   171
     * @param sysPropertyName the name of system property
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   172
     * @return the catalog file paths, or null if not found.
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   173
     */
36700
3afcaff239f5 8151154: IllegalArgumentException not thrown when wrong syntax value is set for javax.xml.catalog.files
joehw
parents: 33542
diff changeset
   174
    static String[] getCatalogFiles(String sysPropertyName) {
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   175
        String value = SecuritySupport.getJAXPSystemProperty(sysPropertyName);
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   176
        if (value != null && !value.equals("")) {
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   177
            return value.split(";");
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   178
        }
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   179
        return null;
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   180
    }
37382
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   181
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   182
    /**
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   183
     * Checks whether the specified string is null or empty, returns the original
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   184
     * string with leading and trailing spaces removed if not.
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   185
     * @param test the string to be tested
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   186
     * @return the original string with leading and trailing spaces removed,
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   187
     * or null if it is null or empty
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   188
     *
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   189
     */
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   190
    static String getNotNullOrEmpty(String test) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   191
        if (test == null) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   192
            return test;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   193
        } else {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   194
            String temp = test.trim();
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   195
            if (temp.length() == 0) {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   196
                return null;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   197
            } else {
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   198
                return temp;
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   199
            }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   200
        }
c7d898d8da12 8151162: Public entries not searched when prefer='system'
joehw
parents: 36700
diff changeset
   201
    }
33542
9f0eef87e8c1 8081248: Implement JEP 268: XML Catalog API
joehw
parents:
diff changeset
   202
}