author | thartmann |
Fri, 24 Aug 2018 08:17:23 +0200 | |
changeset 51514 | 1e332d63bd96 |
parent 50783 | 0ed32e0d98e1 |
permissions | -rw-r--r-- |
33542 | 1 |
/* |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
33542 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package javax.xml.catalog; |
|
26 |
||
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
27 |
import java.net.URI; |
33542 | 28 |
import java.util.Locale; |
29 |
import java.util.MissingResourceException; |
|
30 |
import java.util.ResourceBundle; |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
31 |
import jdk.xml.internal.SecuritySupport; |
33542 | 32 |
|
33 |
/** |
|
34 |
* Catalog Error messages |
|
35 |
* |
|
36 |
* @since 9 |
|
37 |
*/ |
|
38 |
final class CatalogMessages { |
|
39 |
||
40 |
public static final String ERR_INVALID_CATALOG = "InvalidCatalog"; |
|
41 |
public static final String ERR_INVALID_ENTRY_TYPE = "InvalidEntryType"; |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
42 |
public static final String ERR_URI_NOTABSOLUTE = "UriNotAbsolute"; |
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
43 |
public static final String ERR_URI_NOTVALIDURL = "UriNotValidUrl"; |
33542 | 44 |
public static final String ERR_INVALID_ARGUMENT = "InvalidArgument"; |
45 |
public static final String ERR_NULL_ARGUMENT = "NullArgument"; |
|
46 |
public static final String ERR_CIRCULAR_REFERENCE = "CircularReference"; |
|
47 |
public static final String ERR_INVALID_PATH = "InvalidPath"; |
|
48 |
public static final String ERR_PARSER_CONF = "ParserConf"; |
|
49 |
public static final String ERR_PARSING_FAILED = "ParsingFailed"; |
|
50 |
public static final String ERR_NO_CATALOG = "NoCatalogFound"; |
|
51 |
public static final String ERR_NO_MATCH = "NoMatchFound"; |
|
52 |
public static final String ERR_NO_URI_MATCH = "NoMatchURIFound"; |
|
53 |
public static final String ERR_CREATING_URI = "FailedCreatingURI"; |
|
54 |
public static final String ERR_OTHER = "OtherError"; |
|
55 |
||
50783
0ed32e0d98e1
8205623: Replace use of Class::getPackage with Class::getPackageName
mchung
parents:
47216
diff
changeset
|
56 |
static final String bundleName = CatalogMessages.class.getPackageName() + ".CatalogMessages"; |
33542 | 57 |
static ResourceBundle resourceBundle; |
58 |
||
59 |
/** |
|
60 |
* Reports an error. |
|
61 |
* @param key the message key |
|
62 |
*/ |
|
63 |
static void reportError(String key) { |
|
64 |
reportError(key, null); |
|
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Reports an error. |
|
69 |
* @param key the message key |
|
70 |
* @param arguments the message replacement text arguments. The order of the |
|
71 |
* arguments must match that of the placeholders in the actual message. |
|
72 |
*/ |
|
73 |
static void reportError(String key, Object[] arguments) { |
|
74 |
throw new CatalogException(formatMessage(key, arguments)); |
|
75 |
} |
|
76 |
||
77 |
/** |
|
78 |
* Reports a CatalogException. |
|
79 |
* @param key the message key |
|
80 |
* @param arguments the message replacement text arguments. The order of the |
|
81 |
* arguments must match that of the placeholders in the actual message. |
|
82 |
*/ |
|
83 |
static void reportRunTimeError(String key, Object[] arguments) { |
|
84 |
throw new CatalogException(formatMessage(key, arguments)); |
|
85 |
} |
|
86 |
||
87 |
/** |
|
88 |
* Reports a CatalogException. |
|
89 |
* @param key the message key |
|
90 |
* @param cause the cause if any |
|
91 |
*/ |
|
92 |
static void reportRunTimeError(String key, Throwable cause) { |
|
93 |
throw new CatalogException(formatMessage(key, null), cause); |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Reports a CatalogException. |
|
98 |
* @param key the message key |
|
99 |
* @param arguments the message replacement text arguments. The order of the |
|
100 |
* arguments must match that of the placeholders in the actual message. |
|
101 |
* @param cause the cause if any |
|
102 |
*/ |
|
103 |
static void reportRunTimeError(String key, Object[] arguments, Throwable cause) { |
|
104 |
throw new CatalogException(formatMessage(key, arguments), cause); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Reports IllegalArgumentException if the argument is null. |
|
109 |
* |
|
110 |
* @param name the name of the argument |
|
111 |
* @param value the value of the argument |
|
112 |
*/ |
|
113 |
static void reportIAEOnNull(String name, String value) { |
|
114 |
if (value == null) { |
|
115 |
throw new IllegalArgumentException( |
|
116 |
formatMessage(ERR_INVALID_ARGUMENT, new Object[]{null, name})); |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Reports NullPointerException if the argument is null. |
|
122 |
* |
|
123 |
* @param name the name of the argument |
|
124 |
* @param value the value of the argument |
|
125 |
*/ |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
126 |
static void reportNPEOnNull(String name, Object value) { |
33542 | 127 |
if (value == null) { |
128 |
throw new NullPointerException( |
|
129 |
formatMessage(ERR_NULL_ARGUMENT, new Object[]{name})); |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Reports IllegalArgumentException |
|
135 |
* @param arguments the arguments for formating the error message |
|
136 |
* @param cause the cause if any |
|
137 |
*/ |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
138 |
static void reportIAE(String key, Object[] arguments, Throwable cause) { |
33542 | 139 |
throw new IllegalArgumentException( |
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
140 |
formatMessage(key, arguments), cause); |
33542 | 141 |
} |
142 |
||
143 |
/** |
|
144 |
* Format a message with the specified arguments using the default locale |
|
145 |
* information. |
|
146 |
* |
|
147 |
* @param key the message key |
|
148 |
* @param arguments the message replacement text arguments. The order of the |
|
149 |
* arguments must match that of the placeholders in the actual message. |
|
150 |
* |
|
151 |
* @return the formatted message |
|
152 |
* |
|
153 |
* @throws MissingResourceException If the message with the specified key |
|
154 |
* cannot be found |
|
155 |
*/ |
|
156 |
static String formatMessage(String key, Object[] arguments) { |
|
157 |
return formatMessage(key, arguments, Locale.getDefault()); |
|
158 |
} |
|
159 |
||
160 |
/** |
|
161 |
* Format a message with the specified arguments using the given locale |
|
162 |
* information. |
|
163 |
* |
|
164 |
* @param key the message key |
|
165 |
* @param arguments the message replacement text arguments. The order of the |
|
166 |
* arguments must match that of the placeholders in the actual message. |
|
167 |
* @param locale the locale of the message |
|
168 |
* |
|
169 |
* @return the formatted message |
|
170 |
* |
|
171 |
* @throws MissingResourceException If the message with the specified key |
|
172 |
* cannot be found |
|
173 |
*/ |
|
174 |
static String formatMessage(String key, Object[] arguments, Locale locale) { |
|
175 |
return SecuritySupport.getErrorMessage(locale, bundleName, key, arguments); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Returns sanitized URI. |
|
43121
e73af7b6ce47
8171243: CatalogManager.catalogResolver throws FileSystemNotFoundException with jar
joehw
parents:
33542
diff
changeset
|
180 |
* @param uri a URI to be sanitized |
33542 | 181 |
*/ |
182 |
static String sanitize(String uri) { |
|
183 |
if (uri == null) { |
|
184 |
return null; |
|
185 |
} |
|
186 |
String temp; |
|
187 |
int p; |
|
188 |
p = uri.lastIndexOf("/"); |
|
189 |
if (p > 0 && p < uri.length()) { |
|
190 |
return uri.substring(p + 1); |
|
191 |
} |
|
192 |
return uri; |
|
193 |
} |
|
194 |
} |