blob: c953869fb714169196c51cb87704b0e5da9f5fb7 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
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 */
21package com.sun.org.apache.xml.internal.security.transforms.params;
22
23
24
25import java.util.Iterator;
26import java.util.Set;
27import java.util.SortedSet;
28import java.util.StringTokenizer;
29import java.util.TreeSet;
30
31import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
32import com.sun.org.apache.xml.internal.security.transforms.TransformParam;
33import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
34import org.w3c.dom.Document;
35import 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 */
47public 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 */
77 public InclusiveNamespaces(Document doc, Set prefixes) {
78
79 super(doc);
80
81 StringBuffer sb = new StringBuffer();
82 SortedSet prefixList = new TreeSet(prefixes);
83
84
85 Iterator it = prefixList.iterator();
86
87 while (it.hasNext()) {
88 String prefix = (String) it.next();
89
90 if (prefix.equals("xmlns")) {
91 sb.append("#default ");
92 } else {
93 sb.append(prefix + " ");
94 }
95 }
96
97 this._constructionElement
98 .setAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST,
99 sb.toString().trim());
100 }
101
102 /**
103 * Method getInclusiveNamespaces
104 *
105 * @return The Inclusive Namespace string
106 */
107 public String getInclusiveNamespaces() {
108 return this._constructionElement
109 .getAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST);
110 }
111
112 /**
113 * Constructor InclusiveNamespaces
114 *
115 * @param element
116 * @param BaseURI
117 * @throws XMLSecurityException
118 */
119 public InclusiveNamespaces(Element element, String BaseURI)
120 throws XMLSecurityException {
121 super(element, BaseURI);
122 }
123
124 /**
125 * Decodes the <code>inclusiveNamespaces</code> String and returns all
126 * selected namespace prefixes as a Set. The <code>#default</code>
127 * namespace token is represented as an empty namespace prefix
128 * (<code>"xmlns"</code>).
129 * <BR/>
130 * The String <code>inclusiveNamespaces=" xenc ds #default"</code>
131 * is returned as a Set containing the following Strings:
132 * <UL>
133 * <LI><code>xmlns</code></LI>
134 * <LI><code>xenc</code></LI>
135 * <LI><code>ds</code></LI>
136 * </UL>
137 *
138 * @param inclusiveNamespaces
139 * @return A set to string
140 */
141 public static SortedSet prefixStr2Set(String inclusiveNamespaces) {
142
143 SortedSet prefixes = new TreeSet();
144
145 if ((inclusiveNamespaces == null)
146 || (inclusiveNamespaces.length() == 0)) {
147 return prefixes;
148 }
149
150 StringTokenizer st = new StringTokenizer(inclusiveNamespaces, " \t\r\n");
151
152 while (st.hasMoreTokens()) {
153 String prefix = st.nextToken();
154
155 if (prefix.equals("#default")) {
156 prefixes.add("xmlns" );
157 } else {
158 prefixes.add( prefix);
159 }
160 }
161
162 return prefixes;
163 }
164
165 /**
166 * Method getBaseNamespace
167 *
168 * @inheritDoc
169 */
170 public String getBaseNamespace() {
171 return InclusiveNamespaces.ExclusiveCanonicalizationNamespace;
172 }
173
174 /**
175 * Method getBaseLocalName
176 *
177 * @inheritDoc
178 */
179 public String getBaseLocalName() {
180 return InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES;
181 }
182}