KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
22 import com.sun.org.apache.xml.internal.security.transforms.TransformParam;
23 import com.sun.org.apache.xml.internal.security.utils.ElementProxy;
24 import org.w3c.dom.Document JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26 import org.w3c.dom.Node JavaDoc;
27 import org.w3c.dom.NodeList JavaDoc;
28
29
30 /**
31  * Implements the parameters for the <A
32  * HREF="http://www.w3.org/TR/xmldsig-filter2/">XPath Filter v2.0</A>.
33  *
34  * @author $Author: raul $
35  * @see <A HREF="http://www.w3.org/TR/xmldsig-filter2/">XPath Filter v2.0 (TR)</A>
36  * @see <A HREF="http://www.w3.org/Signature/Drafts/xmldsig-xfilter2/">XPath Filter v2.0 (editors copy)</A>
37  */

38 public class XPath2FilterContainer04 extends ElementProxy
39         implements TransformParam {
40
41    /** Field _ATT_FILTER */
42    private static final String JavaDoc _ATT_FILTER = "Filter";
43
44    /** Field _ATT_FILTER_VALUE_INTERSECT */
45    private static final String JavaDoc _ATT_FILTER_VALUE_INTERSECT = "intersect";
46
47    /** Field _ATT_FILTER_VALUE_SUBTRACT */
48    private static final String JavaDoc _ATT_FILTER_VALUE_SUBTRACT = "subtract";
49
50    /** Field _ATT_FILTER_VALUE_UNION */
51    private static final String JavaDoc _ATT_FILTER_VALUE_UNION = "union";
52
53    /** Field _TAG_XPATH2 */
54    public static final String JavaDoc _TAG_XPATH2 = "XPath";
55
56    /** Field XPathFiler2NS */
57    public static final String JavaDoc XPathFilter2NS =
58       "http://www.w3.org/2002/04/xmldsig-filter2";
59
60    /**
61     * Constructor XPath2FilterContainer04
62     *
63     */

64    private XPath2FilterContainer04() {
65
66       // no instantiation
67
}
68
69    /**
70     * Constructor XPath2FilterContainer04
71     *
72     * @param doc
73     * @param xpath2filter
74     * @param filterType
75     */

76    private XPath2FilterContainer04(Document JavaDoc doc, String JavaDoc xpath2filter,
77                                  String JavaDoc filterType) {
78
79       super(doc);
80
81       this._constructionElement.setAttributeNS(null, XPath2FilterContainer04._ATT_FILTER,
82                                              filterType);
83
84       if ((xpath2filter.length() > 2)
85               && (!Character.isWhitespace(xpath2filter.charAt(0)))) {
86          this._constructionElement.appendChild(doc.createTextNode("\n"
87                  + xpath2filter + "\n"));
88       } else {
89          this._constructionElement
90             .appendChild(doc.createTextNode(xpath2filter));
91       }
92    }
93
94    /**
95     * Constructor XPath2FilterContainer04
96     *
97     * @param element
98     * @param BaseURI
99     * @throws XMLSecurityException
100     */

101    private XPath2FilterContainer04(Element JavaDoc element, String JavaDoc BaseURI)
102            throws XMLSecurityException {
103
104       super(element, BaseURI);
105
106       String JavaDoc filterStr =
107          this._constructionElement
108             .getAttributeNS(null, XPath2FilterContainer04._ATT_FILTER);
109
110       if (!filterStr
111               .equals(XPath2FilterContainer04
112               ._ATT_FILTER_VALUE_INTERSECT) &&!filterStr
113                  .equals(XPath2FilterContainer04
114                  ._ATT_FILTER_VALUE_SUBTRACT) &&!filterStr
115                     .equals(XPath2FilterContainer04._ATT_FILTER_VALUE_UNION)) {
116          Object JavaDoc exArgs[] = { XPath2FilterContainer04._ATT_FILTER, filterStr,
117                              XPath2FilterContainer04._ATT_FILTER_VALUE_INTERSECT
118                              + ", "
119                              + XPath2FilterContainer04._ATT_FILTER_VALUE_SUBTRACT
120                              + " or "
121                              + XPath2FilterContainer04._ATT_FILTER_VALUE_UNION };
122
123          throw new XMLSecurityException("attributeValueIllegal", exArgs);
124       }
125    }
126
127    /**
128     * Creates a new XPath2FilterContainer04 with the filter type "intersect".
129     *
130     * @param doc
131     * @param xpath2filter
132     * @return the instance
133     */

134    public static XPath2FilterContainer04 newInstanceIntersect(Document JavaDoc doc,
135            String JavaDoc xpath2filter) {
136
137       return new XPath2FilterContainer04(doc, xpath2filter,
138                                        XPath2FilterContainer04
139                                           ._ATT_FILTER_VALUE_INTERSECT);
140    }
141
142    /**
143     * Creates a new XPath2FilterContainer04 with the filter type "subtract".
144     *
145     * @param doc
146     * @param xpath2filter
147     * @return the instance
148     */

149    public static XPath2FilterContainer04 newInstanceSubtract(Document JavaDoc doc,
150            String JavaDoc xpath2filter) {
151
152       return new XPath2FilterContainer04(doc, xpath2filter,
153                                        XPath2FilterContainer04
154                                           ._ATT_FILTER_VALUE_SUBTRACT);
155    }
156
157    /**
158     * Creates a new XPath2FilterContainer04 with the filter type "union".
159     *
160     * @param doc
161     * @param xpath2filter
162     * @return the instance
163     */

164    public static XPath2FilterContainer04 newInstanceUnion(Document JavaDoc doc,
165            String JavaDoc xpath2filter) {
166
167       return new XPath2FilterContainer04(doc, xpath2filter,
168                                        XPath2FilterContainer04
169                                           ._ATT_FILTER_VALUE_UNION);
170    }
171
172    /**
173     * Creates a XPath2FilterContainer04 from an existing Element; needed for verification.
174     *
175     * @param element
176     * @param BaseURI
177     * @return the instance
178     *
179     * @throws XMLSecurityException
180     */

181    public static XPath2FilterContainer04 newInstance(
182            Element JavaDoc element, String JavaDoc BaseURI) throws XMLSecurityException {
183       return new XPath2FilterContainer04(element, BaseURI);
184    }
185
186    /**
187     * Returns <code>true</code> if the <code>Filter</code> attribute has value "intersect".
188     *
189     * @return <code>true</code> if the <code>Filter</code> attribute has value "intersect".
190     */

191    public boolean isIntersect() {
192
193       return this._constructionElement
194          .getAttributeNS(null, XPath2FilterContainer04._ATT_FILTER)
195          .equals(XPath2FilterContainer04._ATT_FILTER_VALUE_INTERSECT);
196    }
197
198    /**
199     * Returns <code>true</code> if the <code>Filter</code> attribute has value "subtract".
200     *
201     * @return <code>true</code> if the <code>Filter</code> attribute has value "subtract".
202     */

203    public boolean isSubtract() {
204
205       return this._constructionElement
206          .getAttributeNS(null, XPath2FilterContainer04._ATT_FILTER)
207          .equals(XPath2FilterContainer04._ATT_FILTER_VALUE_SUBTRACT);
208    }
209
210    /**
211     * Returns <code>true</code> if the <code>Filter</code> attribute has value "union".
212     *
213     * @return <code>true</code> if the <code>Filter</code> attribute has value "union".
214     */

215    public boolean isUnion() {
216
217       return this._constructionElement
218          .getAttributeNS(null, XPath2FilterContainer04._ATT_FILTER)
219          .equals(XPath2FilterContainer04._ATT_FILTER_VALUE_UNION);
220    }
221
222    /**
223     * Returns the XPath 2 Filter String
224     *
225     * @return the XPath 2 Filter String
226     */

227    public String JavaDoc getXPathFilterStr() {
228       return this.getTextFromTextChild();
229    }
230
231    /**
232     * Returns the first Text node which contains information from the XPath 2
233     * Filter String. We must use this stupid hook to enable the here() function
234     * to work.
235     *
236     * $todo$ I dunno whether this crashes: <XPath> here()<!-- comment -->/ds:Signature[1]</XPath>
237     * @return the first Text node which contains information from the XPath 2 Filter String
238     */

239    public Node JavaDoc getXPathFilterTextNode() {
240       NodeList JavaDoc children = this._constructionElement.getChildNodes();
241       int length = children.getLength();
242
243       for (int i = 0; i < length; i++) {
244          if (children.item(i).getNodeType() == Node.TEXT_NODE) {
245             return children.item(i);
246          }
247       }
248
249       return null;
250    }
251
252    /** @inheritDoc */
253    public final String JavaDoc getBaseLocalName() {
254       return XPath2FilterContainer04._TAG_XPATH2;
255    }
256
257    /** @inheritDoc */
258    public final String JavaDoc getBaseNamespace() {
259       return XPath2FilterContainer04.XPathFilter2NS;
260    }
261 }
262
Popular Tags