1 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 com.sun.org.apache.xml.internal.security.utils.HelperNodeList; 25 import org.w3c.dom.Document ; 26 import org.w3c.dom.Element ; 27 import org.w3c.dom.Node ; 28 import org.w3c.dom.NodeList ; 29 30 31 39 public class XPath2FilterContainer extends ElementProxy 40 implements TransformParam { 41 42 43 private static final String _ATT_FILTER = "Filter"; 44 45 46 private static final String _ATT_FILTER_VALUE_INTERSECT = "intersect"; 47 48 49 private static final String _ATT_FILTER_VALUE_SUBTRACT = "subtract"; 50 51 52 private static final String _ATT_FILTER_VALUE_UNION = "union"; 53 54 55 public static final String INTERSECT = 56 XPath2FilterContainer._ATT_FILTER_VALUE_INTERSECT; 57 58 59 public static final String SUBTRACT = 60 XPath2FilterContainer._ATT_FILTER_VALUE_SUBTRACT; 61 62 63 public static final String UNION = 64 XPath2FilterContainer._ATT_FILTER_VALUE_UNION; 65 66 67 public static final String _TAG_XPATH2 = "XPath"; 68 69 70 public static final String XPathFilter2NS = 71 "http://www.w3.org/2002/06/xmldsig-filter2"; 72 73 77 private XPath2FilterContainer() { 78 79 } 81 82 89 private XPath2FilterContainer(Document doc, String xpath2filter, 90 String filterType) { 91 92 super(doc); 93 94 this._constructionElement 95 .setAttributeNS(null, XPath2FilterContainer._ATT_FILTER, filterType); 96 this._constructionElement.appendChild(doc.createTextNode(xpath2filter)); 97 } 98 99 106 private XPath2FilterContainer(Element element, String BaseURI) 107 throws XMLSecurityException { 108 109 super(element, BaseURI); 110 111 String filterStr = this._constructionElement.getAttributeNS(null, 112 XPath2FilterContainer._ATT_FILTER); 113 114 if (!filterStr 115 .equals(XPath2FilterContainer 116 ._ATT_FILTER_VALUE_INTERSECT) &&!filterStr 117 .equals(XPath2FilterContainer 118 ._ATT_FILTER_VALUE_SUBTRACT) &&!filterStr 119 .equals(XPath2FilterContainer._ATT_FILTER_VALUE_UNION)) { 120 Object exArgs[] = { XPath2FilterContainer._ATT_FILTER, filterStr, 121 XPath2FilterContainer._ATT_FILTER_VALUE_INTERSECT 122 + ", " 123 + XPath2FilterContainer._ATT_FILTER_VALUE_SUBTRACT 124 + " or " 125 + XPath2FilterContainer._ATT_FILTER_VALUE_UNION }; 126 127 throw new XMLSecurityException("attributeValueIllegal", exArgs); 128 } 129 } 130 131 138 public static XPath2FilterContainer newInstanceIntersect(Document doc, 139 String xpath2filter) { 140 141 return new XPath2FilterContainer(doc, xpath2filter, 142 XPath2FilterContainer 143 ._ATT_FILTER_VALUE_INTERSECT); 144 } 145 146 153 public static XPath2FilterContainer newInstanceSubtract(Document doc, 154 String xpath2filter) { 155 156 return new XPath2FilterContainer(doc, xpath2filter, 157 XPath2FilterContainer 158 ._ATT_FILTER_VALUE_SUBTRACT); 159 } 160 161 168 public static XPath2FilterContainer newInstanceUnion(Document doc, 169 String xpath2filter) { 170 171 return new XPath2FilterContainer(doc, xpath2filter, 172 XPath2FilterContainer 173 ._ATT_FILTER_VALUE_UNION); 174 } 175 176 183 public static NodeList newInstances(Document doc, String [][] params) { 184 185 HelperNodeList nl = new HelperNodeList(); 186 187 nl.appendChild(doc.createTextNode("\n")); 188 189 for (int i = 0; i < params.length; i++) { 190 String type = params[i][0]; 191 String xpath = params[i][1]; 192 193 if (!(type.equals(XPath2FilterContainer 194 ._ATT_FILTER_VALUE_INTERSECT) || type 195 .equals(XPath2FilterContainer 196 ._ATT_FILTER_VALUE_SUBTRACT) || type 197 .equals(XPath2FilterContainer 198 ._ATT_FILTER_VALUE_UNION))) { 199 throw new IllegalArgumentException ("The type(" + i + ")=\"" + type 200 + "\" is illegal"); 201 } 202 203 XPath2FilterContainer c = new XPath2FilterContainer(doc, xpath, type); 204 205 nl.appendChild(c.getElement()); 206 nl.appendChild(doc.createTextNode("\n")); 207 } 208 209 return nl; 210 } 211 212 221 public static XPath2FilterContainer newInstance( 222 Element element, String BaseURI) throws XMLSecurityException { 223 return new XPath2FilterContainer(element, BaseURI); 224 } 225 226 231 public boolean isIntersect() { 232 233 return this._constructionElement 234 .getAttributeNS(null, XPath2FilterContainer._ATT_FILTER) 235 .equals(XPath2FilterContainer._ATT_FILTER_VALUE_INTERSECT); 236 } 237 238 243 public boolean isSubtract() { 244 245 return this._constructionElement 246 .getAttributeNS(null, XPath2FilterContainer._ATT_FILTER) 247 .equals(XPath2FilterContainer._ATT_FILTER_VALUE_SUBTRACT); 248 } 249 250 255 public boolean isUnion() { 256 257 return this._constructionElement 258 .getAttributeNS(null, XPath2FilterContainer._ATT_FILTER) 259 .equals(XPath2FilterContainer._ATT_FILTER_VALUE_UNION); 260 } 261 262 267 public String getXPathFilterStr() { 268 return this.getTextFromTextChild(); 269 } 270 271 279 public Node getXPathFilterTextNode() { 280 281 NodeList children = this._constructionElement.getChildNodes(); 282 int length = children.getLength(); 283 284 for (int i = 0; i < length; i++) { 285 if (children.item(i).getNodeType() == Node.TEXT_NODE) { 286 return children.item(i); 287 } 288 } 289 290 return null; 291 } 292 293 298 public final String getBaseLocalName() { 299 return XPath2FilterContainer._TAG_XPATH2; 300 } 301 302 307 public final String getBaseNamespace() { 308 return XPath2FilterContainer.XPathFilter2NS; 309 } 310 } 311 | Popular Tags |