author | mullan |
Mon, 26 Sep 2011 17:20:45 -0700 | |
changeset 10694 | cf59e2badd14 |
parent 2 | 90ce3da70b43 |
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.transforms.params; |
|
22 |
||
23 |
||
24 |
||
25 |
import java.util.Iterator; |
|
26 |
import java.util.Set; |
|
27 |
import java.util.SortedSet; |
|
28 |
import java.util.StringTokenizer; |
|
29 |
import java.util.TreeSet; |
|
30 |
||
31 |
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; |
|
32 |
import com.sun.org.apache.xml.internal.security.transforms.TransformParam; |
|
33 |
import com.sun.org.apache.xml.internal.security.utils.ElementProxy; |
|
34 |
import org.w3c.dom.Document; |
|
35 |
import org.w3c.dom.Element; |
|
36 |
||
37 |
||
38 |
/** |
|
39 |
* This Object serves as Content for the ds:Transforms for exclusive |
|
40 |
* Canonicalization. |
|
41 |
* <BR /> |
|
42 |
* It implements the {@link Element} interface |
|
43 |
* and can be used directly in a DOM tree. |
|
44 |
* |
|
45 |
* @author Christian Geuer-Pollmann |
|
46 |
*/ |
|
47 |
public class InclusiveNamespaces extends ElementProxy |
|
48 |
implements TransformParam { |
|
49 |
||
50 |
/** Field _TAG_EC_INCLUSIVENAMESPACES */ |
|
51 |
public static final String _TAG_EC_INCLUSIVENAMESPACES = |
|
52 |
"InclusiveNamespaces"; |
|
53 |
||
54 |
/** Field _ATT_EC_PREFIXLIST */ |
|
55 |
public static final String _ATT_EC_PREFIXLIST = "PrefixList"; |
|
56 |
||
57 |
/** Field ExclusiveCanonicalizationNamespace */ |
|
58 |
public static final String ExclusiveCanonicalizationNamespace = |
|
59 |
"http://www.w3.org/2001/10/xml-exc-c14n#"; |
|
60 |
||
61 |
/** |
|
62 |
* Constructor XPathContainer |
|
63 |
* |
|
64 |
* @param doc |
|
65 |
* @param prefixList |
|
66 |
*/ |
|
67 |
public InclusiveNamespaces(Document doc, String prefixList) { |
|
68 |
this(doc, InclusiveNamespaces.prefixStr2Set(prefixList)); |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Constructor InclusiveNamespaces |
|
73 |
* |
|
74 |
* @param doc |
|
75 |
* @param prefixes |
|
76 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
2
diff
changeset
|
77 |
public InclusiveNamespaces(Document doc, Set<String> prefixes) { |
2 | 78 |
|
79 |
super(doc); |
|
80 |
||
81 |
StringBuffer sb = new StringBuffer(); |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
2
diff
changeset
|
82 |
SortedSet<String> prefixList = new TreeSet<String>(prefixes); |
2 | 83 |
|
84 |
||
85 |
||
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
2
diff
changeset
|
86 |
for (String prefix : prefixList) { |
2 | 87 |
if (prefix.equals("xmlns")) { |
88 |
sb.append("#default "); |
|
89 |
} else { |
|
90 |
sb.append(prefix + " "); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
this._constructionElement |
|
95 |
.setAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST, |
|
96 |
sb.toString().trim()); |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Method getInclusiveNamespaces |
|
101 |
* |
|
102 |
* @return The Inclusive Namespace string |
|
103 |
*/ |
|
104 |
public String getInclusiveNamespaces() { |
|
105 |
return this._constructionElement |
|
106 |
.getAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST); |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* Constructor InclusiveNamespaces |
|
111 |
* |
|
112 |
* @param element |
|
113 |
* @param BaseURI |
|
114 |
* @throws XMLSecurityException |
|
115 |
*/ |
|
116 |
public InclusiveNamespaces(Element element, String BaseURI) |
|
117 |
throws XMLSecurityException { |
|
118 |
super(element, BaseURI); |
|
119 |
} |
|
120 |
||
121 |
/** |
|
122 |
* Decodes the <code>inclusiveNamespaces</code> String and returns all |
|
123 |
* selected namespace prefixes as a Set. The <code>#default</code> |
|
124 |
* namespace token is represented as an empty namespace prefix |
|
125 |
* (<code>"xmlns"</code>). |
|
126 |
* <BR/> |
|
127 |
* The String <code>inclusiveNamespaces=" xenc ds #default"</code> |
|
128 |
* is returned as a Set containing the following Strings: |
|
129 |
* <UL> |
|
130 |
* <LI><code>xmlns</code></LI> |
|
131 |
* <LI><code>xenc</code></LI> |
|
132 |
* <LI><code>ds</code></LI> |
|
133 |
* </UL> |
|
134 |
* |
|
135 |
* @param inclusiveNamespaces |
|
136 |
* @return A set to string |
|
137 |
*/ |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
2
diff
changeset
|
138 |
public static SortedSet<String> prefixStr2Set(String inclusiveNamespaces) { |
2 | 139 |
|
10694
cf59e2badd14
7088502: Security libraries don't build with javac -Werror
mullan
parents:
2
diff
changeset
|
140 |
SortedSet<String> prefixes = new TreeSet<String>(); |
2 | 141 |
|
142 |
if ((inclusiveNamespaces == null) |
|
143 |
|| (inclusiveNamespaces.length() == 0)) { |
|
144 |
return prefixes; |
|
145 |
} |
|
146 |
||
147 |
StringTokenizer st = new StringTokenizer(inclusiveNamespaces, " \t\r\n"); |
|
148 |
||
149 |
while (st.hasMoreTokens()) { |
|
150 |
String prefix = st.nextToken(); |
|
151 |
||
152 |
if (prefix.equals("#default")) { |
|
153 |
prefixes.add("xmlns" ); |
|
154 |
} else { |
|
155 |
prefixes.add( prefix); |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
return prefixes; |
|
160 |
} |
|
161 |
||
162 |
/** |
|
163 |
* Method getBaseNamespace |
|
164 |
* |
|
165 |
* @inheritDoc |
|
166 |
*/ |
|
167 |
public String getBaseNamespace() { |
|
168 |
return InclusiveNamespaces.ExclusiveCanonicalizationNamespace; |
|
169 |
} |
|
170 |
||
171 |
/** |
|
172 |
* Method getBaseLocalName |
|
173 |
* |
|
174 |
* @inheritDoc |
|
175 |
*/ |
|
176 |
public String getBaseLocalName() { |
|
177 |
return InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES; |
|
178 |
} |
|
179 |
} |