author | thartmann |
Fri, 24 Aug 2018 08:17:23 +0200 | |
changeset 51514 | 1e332d63bd96 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
33542 | 1 |
/* |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
2 |
* Copyright (c) 2016, 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 |
||
27 |
import java.net.URL; |
|
28 |
||
29 |
/** |
|
30 |
* Represents a rewriteURI entry. |
|
31 |
* |
|
32 |
* @since 9 |
|
33 |
*/ |
|
34 |
final class RewriteUri extends BaseEntry { |
|
35 |
String uriStartString; |
|
36 |
URL rewritePrefix; |
|
37 |
||
38 |
/** |
|
39 |
* Construct a rewriteURI entry. |
|
40 |
* @param uriStartString The uriStartString attribute. |
|
41 |
* @param rewritePrefix The rewritePrefix attribute. |
|
42 |
*/ |
|
43 |
public RewriteUri(String base, String uriStartString, String rewritePrefix) { |
|
44 |
super(CatalogEntryType.REWRITEURI, base); |
|
45 |
setURIStartString (uriStartString); |
|
46 |
setRewritePrefix(rewritePrefix); |
|
47 |
} |
|
48 |
||
49 |
/** |
|
50 |
* Set the uriStartString attribute. |
|
51 |
* @param uriStartString The uriStartString attribute value. |
|
52 |
*/ |
|
53 |
public void setURIStartString (String uriStartString) { |
|
54 |
CatalogMessages.reportNPEOnNull("uriStartString", uriStartString); |
|
55 |
this.uriStartString = Normalizer.normalizeURI(uriStartString); |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* Set the rewritePrefix attribute. If the value of the rewritePrefix attribute |
|
60 |
* is relative, it must be made absolute with respect to the base URI currently in effect. |
|
61 |
* |
|
62 |
* @param rewritePrefix The rewritePrefix attribute value. |
|
63 |
*/ |
|
64 |
public void setRewritePrefix(String rewritePrefix) { |
|
65 |
this.rewritePrefix = verifyURI("setRewritePrefix", baseURI, rewritePrefix); |
|
66 |
} |
|
67 |
||
68 |
/** |
|
69 |
* Get the uriStartString attribute. |
|
70 |
* @return The uriStartString |
|
71 |
*/ |
|
72 |
public String getURIStartString () { |
|
73 |
return uriStartString; |
|
74 |
} |
|
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
75 |
|
33542 | 76 |
/** |
77 |
* Get the rewritePrefix attribute. |
|
78 |
* @return The rewritePrefix attribute value. |
|
79 |
*/ |
|
80 |
public URL getRewritePrefix() { |
|
81 |
return rewritePrefix; |
|
82 |
} |
|
83 |
||
84 |
/** |
|
85 |
* Try to match the specified systemId with the entry. Return the match if it |
|
86 |
* is successful and the length of the systemIdStartString is longer than the |
|
87 |
* longest of any previous match. |
|
88 |
* |
|
89 |
* @param systemId The systemId to be matched. |
|
90 |
* @param currentMatch The length of uriStartString of previous match if any. |
|
91 |
* @return The replacement URI if the match is successful, null if not. |
|
92 |
*/ |
|
93 |
@Override |
|
94 |
public String match(String systemId, int currentMatch) { |
|
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
95 |
if (uriStartString.length() < systemId.length() && |
33542 | 96 |
uriStartString.equals(systemId.substring(0, uriStartString.length()))) { |
97 |
if (currentMatch < uriStartString.length()) { |
|
98 |
String prefix = rewritePrefix.toExternalForm(); |
|
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
99 |
String sysId; |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
100 |
if (uriStartString.endsWith(SLASH)) { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
101 |
sysId = systemId.substring(uriStartString.length()); |
33542 | 102 |
} else { |
34985
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
103 |
sysId = systemId.substring(uriStartString.length() + 1); |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
104 |
} |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
105 |
if (prefix.endsWith(SLASH)) { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
106 |
return prefix + sysId; |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
107 |
} else { |
512ebcf54647
8146606: Catalog.matchSystem() appends an extra '/' to the matched result
joehw
parents:
33542
diff
changeset
|
108 |
return prefix + SLASH + sysId; |
33542 | 109 |
} |
110 |
} |
|
111 |
} |
|
112 |
return null; |
|
113 |
} |
|
114 |
||
115 |
@Override |
|
116 |
public String match(String systemId) { |
|
117 |
return match(systemId, 0); |
|
118 |
} |
|
119 |
||
120 |
} |