33542
|
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.net.URI;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Represents a delegateURI entry.
|
|
31 |
*
|
|
32 |
* @since 9
|
|
33 |
*/
|
|
34 |
final class DelegateUri extends AltCatalog {
|
|
35 |
String uriStartString;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Construct a delegateURI entry.
|
|
39 |
* @param uriStartString The uriStartString attribute.
|
|
40 |
* @param catalog The catalog attribute.
|
|
41 |
*/
|
|
42 |
public DelegateUri(String base, String uriStartString, String catalog) {
|
|
43 |
super(CatalogEntryType.DELEGATEURI, base);
|
|
44 |
setURIStartString (uriStartString);
|
|
45 |
setCatalog(catalog);
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Set the uriStartString attribute.
|
|
50 |
*
|
|
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 |
setMatchId(this.uriStartString);
|
|
57 |
}
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Get the uriStartString attribute.
|
|
61 |
* @return The uriStartString
|
|
62 |
*/
|
|
63 |
public String getURIStartString () {
|
|
64 |
return uriStartString;
|
|
65 |
}
|
|
66 |
|
|
67 |
/**
|
|
68 |
* Try to match the specified systemId with the entry.
|
|
69 |
*
|
|
70 |
* @param systemId The systemId to be matched.
|
|
71 |
* @return The URI of the catalog.
|
|
72 |
*/
|
|
73 |
@Override
|
|
74 |
public String match(String systemId) {
|
|
75 |
return match(systemId, 0);
|
|
76 |
}
|
|
77 |
|
|
78 |
/**
|
|
79 |
* Matches the specified systemId with the entry. Return the match if it
|
|
80 |
* is successful and the length of the uriStartString is longer than the
|
|
81 |
* longest of any previous match.
|
|
82 |
*
|
|
83 |
* @param systemId The systemId to be matched.
|
|
84 |
* @param currentMatch The length of uriStartString of previous match if any.
|
|
85 |
* @return The replacement URI if the match is successful, null if not.
|
|
86 |
*/
|
|
87 |
@Override
|
|
88 |
public URI matchURI(String systemId, int currentMatch) {
|
|
89 |
if (uriStartString.length() <= systemId.length() &&
|
|
90 |
uriStartString.equals(systemId.substring(0, uriStartString.length()))) {
|
|
91 |
if (currentMatch < uriStartString.length()) {
|
|
92 |
return catalogURI;
|
|
93 |
}
|
|
94 |
}
|
|
95 |
return null;
|
|
96 |
}
|
|
97 |
}
|