author | mullan |
Mon, 22 Apr 2013 11:23:33 +0100 | |
changeset 18240 | cda839ac048f |
parent 10694 | cf59e2badd14 |
child 18780 | f47b920867e7 |
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 |
|
18240 | 46 |
protected boolean secureValidation; |
47 |
||
2 | 48 |
/** |
49 |
* This is the workhorse method used to resolve resources. |
|
50 |
* |
|
51 |
* @param uri |
|
52 |
* @param BaseURI |
|
53 |
* @return the resource wrapped arround a XMLSignatureInput |
|
54 |
* |
|
55 |
* @throws ResourceResolverException |
|
56 |
*/ |
|
57 |
public abstract XMLSignatureInput engineResolve(Attr uri, String BaseURI) |
|
58 |
throws ResourceResolverException; |
|
59 |
||
60 |
/** |
|
61 |
* Method engineSetProperty |
|
62 |
* |
|
63 |
* @param key |
|
64 |
* @param value |
|
65 |
*/ |
|
66 |
public void engineSetProperty(String key, String value) { |
|
1337 | 67 |
if (_properties==null) { |
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
68 |
_properties=new HashMap<String,String>(); |
1337 | 69 |
} |
2 | 70 |
this._properties.put(key, value); |
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Method engineGetProperty |
|
75 |
* |
|
76 |
* @param key |
|
77 |
* @return the value of the property |
|
78 |
*/ |
|
79 |
public String engineGetProperty(String key) { |
|
1337 | 80 |
if (_properties==null) { |
81 |
return null; |
|
82 |
} |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
83 |
return this._properties.get(key); |
2 | 84 |
} |
85 |
||
86 |
/** |
|
87 |
* |
|
88 |
* @param properties |
|
89 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
90 |
public void engineAddProperies(Map<String,String> properties) { |
1337 | 91 |
if (properties!=null) { |
92 |
if (_properties==null) { |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
1337
diff
changeset
|
93 |
_properties=new HashMap<String,String>(); |
1337 | 94 |
} |
95 |
this._properties.putAll(properties); |
|
96 |
} |
|
2 | 97 |
} |
1337 | 98 |
/** |
99 |
* Tells if the implementation does can be reused by several threads safely. |
|
100 |
* It normally means that the implemantation does not have any member, or there is |
|
101 |
* member change betwen engineCanResolve & engineResolve invocations. Or it mantians all |
|
102 |
* member info in ThreadLocal methods. |
|
103 |
*/ |
|
104 |
public boolean engineIsThreadSafe() { |
|
105 |
return false; |
|
106 |
} |
|
2 | 107 |
/** |
108 |
* This method helps the {@link ResourceResolver} to decide whether a |
|
109 |
* {@link ResourceResolverSpi} is able to perform the requested action. |
|
110 |
* |
|
111 |
* @param uri |
|
112 |
* @param BaseURI |
|
113 |
* @return true if the engine can resolve the uri |
|
114 |
*/ |
|
115 |
public abstract boolean engineCanResolve(Attr uri, String BaseURI); |
|
116 |
||
117 |
/** |
|
118 |
* Method engineGetPropertyKeys |
|
119 |
* |
|
120 |
* @return the property keys |
|
121 |
*/ |
|
122 |
public String[] engineGetPropertyKeys() { |
|
123 |
return new String[0]; |
|
124 |
} |
|
125 |
||
126 |
/** |
|
127 |
* Method understandsProperty |
|
128 |
* |
|
129 |
* @param propertyToTest |
|
130 |
* @return true if understands the property |
|
131 |
*/ |
|
132 |
public boolean understandsProperty(String propertyToTest) { |
|
133 |
||
134 |
String[] understood = this.engineGetPropertyKeys(); |
|
135 |
||
136 |
if (understood != null) { |
|
137 |
for (int i = 0; i < understood.length; i++) { |
|
138 |
if (understood[i].equals(propertyToTest)) { |
|
139 |
return true; |
|
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
return false; |
|
145 |
} |
|
146 |
||
147 |
||
148 |
/** |
|
149 |
* Fixes a platform dependent filename to standard URI form. |
|
150 |
* |
|
151 |
* @param str The string to fix. |
|
152 |
* |
|
153 |
* @return Returns the fixed URI string. |
|
154 |
*/ |
|
155 |
public static String fixURI(String str) { |
|
156 |
||
157 |
// handle platform dependent strings |
|
158 |
str = str.replace(java.io.File.separatorChar, '/'); |
|
159 |
||
160 |
if (str.length() >= 4) { |
|
161 |
||
162 |
// str =~ /^\W:\/([^/])/ # to speak perl ;-)) |
|
163 |
char ch0 = Character.toUpperCase(str.charAt(0)); |
|
164 |
char ch1 = str.charAt(1); |
|
165 |
char ch2 = str.charAt(2); |
|
166 |
char ch3 = str.charAt(3); |
|
167 |
boolean isDosFilename = ((('A' <= ch0) && (ch0 <= 'Z')) |
|
168 |
&& (ch1 == ':') && (ch2 == '/') |
|
169 |
&& (ch3 != '/')); |
|
170 |
||
171 |
if (isDosFilename) { |
|
1337 | 172 |
if (log.isLoggable(java.util.logging.Level.FINE)) |
173 |
log.log(java.util.logging.Level.FINE, "Found DOS filename: " + str); |
|
2 | 174 |
} |
175 |
} |
|
176 |
||
177 |
// Windows fix |
|
178 |
if (str.length() >= 2) { |
|
179 |
char ch1 = str.charAt(1); |
|
180 |
||
181 |
if (ch1 == ':') { |
|
182 |
char ch0 = Character.toUpperCase(str.charAt(0)); |
|
183 |
||
184 |
if (('A' <= ch0) && (ch0 <= 'Z')) { |
|
185 |
str = "/" + str; |
|
186 |
} |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
// done |
|
191 |
return str; |
|
192 |
} |
|
193 |
} |