KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > transforms > params > InclusiveNamespaces


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

17 package com.sun.org.apache.xml.internal.security.transforms.params;
18
19
20
21 import java.util.Iterator JavaDoc;
22 import java.util.Set JavaDoc;
23 import java.util.SortedSet JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25 import java.util.TreeSet JavaDoc;
26
27 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
28 import com.sun.org.apache.xml.internal.security.transforms.TransformParam;
29 import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
30 import org.w3c.dom.Document JavaDoc;
31 import org.w3c.dom.Element JavaDoc;
32
33
34 /**
35  * This Object serves as Content for the ds:Transforms for exclusive
36  * Canonicalization.
37  * <BR />
38  * It implements the {@link Element} interface
39  * and can be used directly in a DOM tree.
40  *
41  * @author Christian Geuer-Pollmann
42  */

43 public class InclusiveNamespaces extends ElementProxy
44         implements TransformParam {
45
46    /** Field _TAG_EC_INCLUSIVENAMESPACES */
47    public static final String JavaDoc _TAG_EC_INCLUSIVENAMESPACES =
48       "InclusiveNamespaces";
49
50    /** Field _ATT_EC_PREFIXLIST */
51    public static final String JavaDoc _ATT_EC_PREFIXLIST = "PrefixList";
52
53    /** Field ExclusiveCanonicalizationNamespace */
54    public static final String JavaDoc ExclusiveCanonicalizationNamespace =
55       "http://www.w3.org/2001/10/xml-exc-c14n#";
56
57    /**
58     * Constructor XPathContainer
59     *
60     * @param doc
61     * @param prefixList
62     */

63    public InclusiveNamespaces(Document JavaDoc doc, String JavaDoc prefixList) {
64       this(doc, InclusiveNamespaces.prefixStr2Set(prefixList));
65    }
66
67    /**
68     * Constructor InclusiveNamespaces
69     *
70     * @param doc
71     * @param prefixes
72     */

73    public InclusiveNamespaces(Document JavaDoc doc, Set JavaDoc prefixes) {
74
75       super(doc);
76
77       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
78       SortedSet JavaDoc prefixList = new TreeSet JavaDoc(prefixes);
79
80
81       Iterator JavaDoc it = prefixList.iterator();
82
83       while (it.hasNext()) {
84          String JavaDoc prefix = (String JavaDoc) it.next();
85
86          if (prefix.equals("xmlns")) {
87             sb.append("#default ");
88          } else {
89             sb.append(prefix + " ");
90          }
91       }
92
93       this._constructionElement
94          .setAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST,
95                        sb.toString().trim());
96    }
97
98    /**
99     * Method getInclusiveNamespaces
100     *
101     * @return The Inclusive Namespace string
102     */

103    public String JavaDoc getInclusiveNamespaces() {
104       return this._constructionElement
105          .getAttributeNS(null, InclusiveNamespaces._ATT_EC_PREFIXLIST);
106    }
107
108    /**
109     * Constructor InclusiveNamespaces
110     *
111     * @param element
112     * @param BaseURI
113     * @throws XMLSecurityException
114     */

115    public InclusiveNamespaces(Element JavaDoc element, String JavaDoc BaseURI)
116            throws XMLSecurityException {
117       super(element, BaseURI);
118    }
119
120    /**
121     * Decodes the <code>inclusiveNamespaces</code> String and returns all
122     * selected namespace prefixes as a Set. The <code>#default</code>
123     * namespace token is represented as an empty namespace prefix
124     * (<code>"xmlns"</code>).
125     * <BR/>
126     * The String <code>inclusiveNamespaces=" xenc ds #default"</code>
127     * is returned as a Set containing the following Strings:
128     * <UL>
129     * <LI><code>xmlns</code></LI>
130     * <LI><code>xenc</code></LI>
131     * <LI><code>ds</code></LI>
132     * </UL>
133     *
134     * @param inclusiveNamespaces
135     * @return A set to string
136     */

137    public static SortedSet JavaDoc prefixStr2Set(String JavaDoc inclusiveNamespaces) {
138
139       SortedSet JavaDoc prefixes = new TreeSet JavaDoc();
140
141       if ((inclusiveNamespaces == null)
142               || (inclusiveNamespaces.length() == 0)) {
143          return prefixes;
144       }
145
146       StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(inclusiveNamespaces, " \t\r\n");
147
148       while (st.hasMoreTokens()) {
149          String JavaDoc prefix = st.nextToken();
150
151          if (prefix.equals("#default")) {
152             prefixes.add("xmlns" );
153          } else {
154             prefixes.add( prefix);
155          }
156       }
157
158       return prefixes;
159    }
160
161    /**
162     * Method getBaseNamespace
163     *
164     * @inheritDoc
165     */

166    public String JavaDoc getBaseNamespace() {
167       return InclusiveNamespaces.ExclusiveCanonicalizationNamespace;
168    }
169
170    /**
171     * Method getBaseLocalName
172     *
173     * @inheritDoc
174     */

175    public String JavaDoc getBaseLocalName() {
176       return InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES;
177    }
178 }
179
Popular Tags