KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > utils > resolver > ResourceResolverSpi


1
2 /*
3  * Copyright 1999-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package com.sun.org.apache.xml.internal.security.utils.resolver;
19
20
21 import java.util.Map JavaDoc;
22
23 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
24 import org.w3c.dom.Attr JavaDoc;
25
26
27 /**
28  * During reference validation, we have to retrieve resources from somewhere.
29  *
30  * @author $Author: raul $
31  */

32 public abstract class ResourceResolverSpi {
33
34    /** {@link java.util.logging} logging facility */
35     static java.util.logging.Logger JavaDoc log =
36         java.util.logging.Logger.getLogger(
37                     ResourceResolverSpi.class.getName());
38
39    /** Field _properties */
40    protected java.util.Map JavaDoc _properties = new java.util.HashMap JavaDoc(10);
41
42    /**
43     * This is the workhorse method used to resolve resources.
44     *
45     * @param uri
46     * @param BaseURI
47     * @return the resource wrapped arround a XMLSignatureInput
48     *
49     * @throws ResourceResolverException
50     */

51    public abstract XMLSignatureInput engineResolve(Attr JavaDoc uri, String JavaDoc BaseURI)
52       throws ResourceResolverException;
53
54    /**
55     * Method engineSetProperty
56     *
57     * @param key
58     * @param value
59     */

60    public void engineSetProperty(String JavaDoc key, String JavaDoc value) {
61
62       java.util.Iterator JavaDoc i = this._properties.keySet().iterator();
63
64       while (i.hasNext()) {
65          String JavaDoc c = (String JavaDoc) i.next();
66
67          if (c.equals(key)) {
68             key = c;
69
70             break;
71          }
72       }
73
74       this._properties.put(key, value);
75    }
76
77    /**
78     * Method engineGetProperty
79     *
80     * @param key
81     * @return the value of the property
82     */

83    public String JavaDoc engineGetProperty(String JavaDoc key) {
84
85       java.util.Iterator JavaDoc i = this._properties.keySet().iterator();
86
87       while (i.hasNext()) {
88          String JavaDoc c = (String JavaDoc) i.next();
89
90          if (c.equals(key)) {
91             key = c;
92
93             break;
94          }
95       }
96
97       return (String JavaDoc) this._properties.get(key);
98    }
99
100    /**
101     *
102     * @param properties
103     */

104    public void engineAddProperies(Map JavaDoc properties) {
105       this._properties.putAll(properties);
106    }
107
108    /**
109     * This method helps the {@link ResourceResolver} to decide whether a
110     * {@link ResourceResolverSpi} is able to perform the requested action.
111     *
112     * @param uri
113     * @param BaseURI
114     * @return true if the engine can resolve the uri
115     */

116    public abstract boolean engineCanResolve(Attr JavaDoc uri, String JavaDoc BaseURI);
117
118    /**
119     * Method engineGetPropertyKeys
120     *
121     * @return the property keys
122     */

123    public String JavaDoc[] engineGetPropertyKeys() {
124       return new String JavaDoc[0];
125    }
126
127    /**
128     * Method understandsProperty
129     *
130     * @param propertyToTest
131     * @return true if understands the property
132     */

133    public boolean understandsProperty(String JavaDoc propertyToTest) {
134
135       String JavaDoc[] understood = this.engineGetPropertyKeys();
136
137       if (understood != null) {
138          for (int i = 0; i < understood.length; i++) {
139             if (understood[i].equals(propertyToTest)) {
140                return true;
141             }
142          }
143       }
144
145       return false;
146    }
147
148
149    /**
150     * Fixes a platform dependent filename to standard URI form.
151     *
152     * @param str The string to fix.
153     *
154     * @return Returns the fixed URI string.
155     */

156    public static String JavaDoc fixURI(String JavaDoc str) {
157
158       // handle platform dependent strings
159
str = str.replace(java.io.File.separatorChar, '/');
160
161       if (str.length() >= 4) {
162
163          // str =~ /^\W:\/([^/])/ # to speak perl ;-))
164
char ch0 = Character.toUpperCase(str.charAt(0));
165          char ch1 = str.charAt(1);
166          char ch2 = str.charAt(2);
167          char ch3 = str.charAt(3);
168          boolean isDosFilename = ((('A' <= ch0) && (ch0 <= 'Z'))
169                                   && (ch1 == ':') && (ch2 == '/')
170                                   && (ch3 != '/'));
171
172          if (isDosFilename) {
173             if (true)
174                 if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Found DOS filename: " + str);
175          }
176       }
177
178       // Windows fix
179
if (str.length() >= 2) {
180          char ch1 = str.charAt(1);
181
182          if (ch1 == ':') {
183             char ch0 = Character.toUpperCase(str.charAt(0));
184
185             if (('A' <= ch0) && (ch0 <= 'Z')) {
186                str = "/" + str;
187             }
188          }
189       }
190
191       // done
192
return str;
193    }
194 }
195
Popular Tags