1 /*
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
27 import java.io.File;
28 import java.net.MalformedURLException;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31 import java.net.URL;
32 import java.util.Objects;
33 import jdk.xml.internal.SecuritySupport;
34
35 /**
36 * Represents a general Catalog entry.
37 *
38 * @since 9
39 */
40 abstract class BaseEntry {
41 final String SLASH = "/";
42
43 CatalogEntryType type;
44
45 //The id attribute
46 String id;
47
48 //The attribute to be matched, e.g. systemId
49 String matchId;
50
51 //The baseURI attribute
52 URL baseURI;
53
221 if (uri == null) {
222 CatalogMessages.reportIAE(new Object[]{uri, arg}, null);
223 }
224
225 URL url = null;
226 uri = Normalizer.normalizeURI(uri);
227
228 try {
229 if (base != null) {
230 url = new URL(base, uri);
231 } else {
232 url = new URL(uri);
233 }
234 } catch (MalformedURLException e) {
235 CatalogMessages.reportIAE(new Object[]{uri, arg}, e);
236 }
237 return url;
238 }
239
240 /**
241 * Replace backslashes with forward slashes. (URLs always use forward
242 * slashes.)
243 *
244 * @param sysid The input system identifier.
245 * @return The same system identifier with backslashes turned into forward
246 * slashes.
247 */
248 protected String fixSlashes(String sysid) {
249 return sysid.replace('\\', '/');
250 }
251
252 /**
253 * Construct an absolute URI from a relative one, using the current base
254 * URI.
255 *
256 * @param sysid The (possibly relative) system identifier
257 * @return The system identifier made absolute with respect to the current
258 * {@link #base}.
259 */
260 protected String makeAbsolute(String sysid) {
261 URL local = null;
262
263 sysid = fixSlashes(sysid);
264 /**
265 * try { local = new URL(base, sysid); } catch (MalformedURLException e)
266 * { catalogManager.debug.message(1, "Malformed URL on system
267 * identifier", sysid); }
268 */
269 if (local != null) {
270 return local.toString();
271 } else {
272 return sysid;
273 }
274 }
275 }
|
1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
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
27 import java.net.MalformedURLException;
28 import java.net.URL;
29 import java.util.Objects;
30
31 /**
32 * Represents a general Catalog entry.
33 *
34 * @since 9
35 */
36 abstract class BaseEntry {
37 final String SLASH = "/";
38
39 CatalogEntryType type;
40
41 //The id attribute
42 String id;
43
44 //The attribute to be matched, e.g. systemId
45 String matchId;
46
47 //The baseURI attribute
48 URL baseURI;
49
217 if (uri == null) {
218 CatalogMessages.reportIAE(new Object[]{uri, arg}, null);
219 }
220
221 URL url = null;
222 uri = Normalizer.normalizeURI(uri);
223
224 try {
225 if (base != null) {
226 url = new URL(base, uri);
227 } else {
228 url = new URL(uri);
229 }
230 } catch (MalformedURLException e) {
231 CatalogMessages.reportIAE(new Object[]{uri, arg}, e);
232 }
233 return url;
234 }
235
236 /**
237 * Construct an absolute URI from a relative one, using the current base
238 * URI.
239 *
240 * @param sysid The (possibly relative) system identifier
241 * @return The system identifier made absolute with respect to the current
242 * {@link #base}.
243 */
244 protected String makeAbsolute(String sysid) {
245 URL local = null;
246
247 sysid = Util.fixSlashes(sysid);
248 /**
249 * try { local = new URL(base, sysid); } catch (MalformedURLException e)
250 * { catalogManager.debug.message(1, "Malformed URL on system
251 * identifier", sysid); }
252 */
253 if (local != null) {
254 return local.toString();
255 } else {
256 return sysid;
257 }
258 }
259 }
|