author | mullan |
Mon, 26 Sep 2011 17:20:45 -0700 | |
changeset 10694 | cf59e2badd14 |
parent 1337 | e8d6cef36199 |
child 18240 | cda839ac048f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
6 |
* Copyright 1999-2004 The Apache Software Foundation. |
|
7 |
* |
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 |
* you may not use this file except in compliance with the License. |
|
10 |
* You may obtain a copy of the License at |
|
11 |
* |
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
* |
|
20 |
*/ |
|
21 |
package com.sun.org.apache.xml.internal.security.utils.resolver; |
|
22 |
||
23 |
||
1337 | 24 |
import java.util.HashMap; |
2 | 25 |
import java.util.Map; |
26 |
||
27 |
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput; |
|
28 |
import org.w3c.dom.Attr; |
|
29 |
||
30 |
||
31 |
/** |
|
32 |
* During reference validation, we have to retrieve resources from somewhere. |
|
33 |
* |
|
1337 | 34 |
* @author $Author: mullan $ |
2 | 35 |
*/ |
36 |
public abstract class ResourceResolverSpi { |
|
37 |
||
38 |
/** {@link java.util.logging} logging facility */ |
|
39 |
static java.util.logging.Logger log = |
|
40 |
java.util.logging.Logger.getLogger( |
|
41 |
ResourceResolverSpi.class.getName()); |
|
42 |
||
43 |
/** Field _properties */ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
44 |
protected java.util.Map<String,String> _properties = null; |
2 | 45 |
|
46 |
/** |
|
47 |
* This is the workhorse method used to resolve resources. |
|
48 |
* |
|
49 |
* @param uri |
|
50 |
* @param BaseURI |
|
51 |
* @return the resource wrapped arround a XMLSignatureInput |
|
52 |
* |
|
53 |
* @throws ResourceResolverException |
|
54 |
*/ |
|
55 |
public abstract XMLSignatureInput engineResolve(Attr uri, String BaseURI) |
|
56 |
throws ResourceResolverException; |
|
57 |
||
58 |
/** |
|
59 |
* Method engineSetProperty |
|
60 |
* |
|
61 |
* @param key |
|
62 |
* @param value |
|
63 |
*/ |
|
64 |
public void engineSetProperty(String key, String value) { |
|
1337 | 65 |
if (_properties==null) { |
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
66 |
_properties=new HashMap<String,String>(); |
1337 | 67 |
} |
2 | 68 |
this._properties.put(key, value); |
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Method engineGetProperty |
|
73 |
* |
|
74 |
* @param key |
|
75 |
* @return the value of the property |
|
76 |
*/ |
|
77 |
public String engineGetProperty(String key) { |
|
1337 | 78 |
if (_properties==null) { |
79 |
return null; |
|
80 |
} |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
81 |
return this._properties.get(key); |
2 | 82 |
} |
83 |
||
84 |
/** |
|
85 |
* |
|
86 |
* @param properties |
|
87 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
88 |
public void engineAddProperies(Map<String,String> properties) { |
1337 | 89 |
if (properties!=null) { |
90 |
if (_properties==null) { |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
91 |
_properties=new HashMap<String,String>(); |
1337 | 92 |
} |
93 |
this._properties.putAll(properties); |
|
94 |
} |
|
2 | 95 |
} |
1337 | 96 |
/** |
97 |
* Tells if the implementation does can be reused by several threads safely. |
|
98 |
* It normally means that the implemantation does not have any member, or there is |
|
99 |
* member change betwen engineCanResolve & engineResolve invocations. Or it mantians all |
|
100 |
* member info in ThreadLocal methods. |
|
101 |
*/ |
|
102 |
public boolean engineIsThreadSafe() { |
|
103 |
return false; |
|
104 |
} |
|
2 | 105 |
/** |
106 |
* This method helps the {@link ResourceResolver} to decide whether a |
|
107 |
* {@link ResourceResolverSpi} is able to perform the requested action. |
|
108 |
* |
|
109 |
* @param uri |
|
110 |
* @param BaseURI |
|
111 |
* @return true if the engine can resolve the uri |
|
112 |
*/ |
|
113 |
public abstract boolean engineCanResolve(Attr uri, String BaseURI); |
|
114 |
||
115 |
/** |
|
116 |
* Method engineGetPropertyKeys |
|
117 |
* |
|
118 |
* @return the property keys |
|
119 |
*/ |
|
120 |
public String[] engineGetPropertyKeys() { |
|
121 |
return new String[0]; |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Method understandsProperty |
|
126 |
* |
|
127 |
* @param propertyToTest |
|
128 |
* @return true if understands the property |
|
129 |
*/ |
|
130 |
public boolean understandsProperty(String propertyToTest) { |
|
131 |
||
132 |
String[] understood = this.engineGetPropertyKeys(); |
|
133 |
||
134 |
if (understood != null) { |
|
135 |
for (int i = 0; i < understood.length; i++) { |
|
136 |
if (understood[i].equals(propertyToTest)) { |
|
137 |
return true; |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
return false; |
|
143 |
} |
|
144 |
||
145 |
||
146 |
/** |
|
147 |
* Fixes a platform dependent filename to standard URI form. |
|
148 |
* |
|
149 |
* @param str The string to fix. |
|
150 |
* |
|
151 |
* @return Returns the fixed URI string. |
|
152 |
*/ |
|
153 |
public static String fixURI(String str) { |
|
154 |
||
155 |
// handle platform dependent strings |
|
156 |
str = str.replace(java.io.File.separatorChar, '/'); |
|
157 |
||
158 |
if (str.length() >= 4) { |
|
159 |
||
160 |
// str =~ /^\W:\/([^/])/ # to speak perl ;-)) |
|
161 |
char ch0 = Character.toUpperCase(str.charAt(0)); |
|
162 |
char ch1 = str.charAt(1); |
|
163 |
char ch2 = str.charAt(2); |
|
164 |
char ch3 = str.charAt(3); |
|
165 |
boolean isDosFilename = ((('A' <= ch0) && (ch0 <= 'Z')) |
|
166 |
&& (ch1 == ':') && (ch2 == '/') |
|
167 |
&& (ch3 != '/')); |
|
168 |
||
169 |
if (isDosFilename) { |
|
1337 | 170 |
if (log.isLoggable(java.util.logging.Level.FINE)) |
171 |
log.log(java.util.logging.Level.FINE, "Found DOS filename: " + str); |
|
2 | 172 |
} |
173 |
} |
|
174 |
||
175 |
// Windows fix |
|
176 |
if (str.length() >= 2) { |
|
177 |
char ch1 = str.charAt(1); |
|
178 |
||
179 |
if (ch1 == ':') { |
|
180 |
char ch0 = Character.toUpperCase(str.charAt(0)); |
|
181 |
||
182 |
if (('A' <= ch0) && (ch0 <= 'Z')) { |
|
183 |
str = "/" + str; |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
// done |
|
189 |
return str; |
|
190 |
} |
|
191 |
} |