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.transforms.Transforms; 24 import com.sun.org.apache.xml.internal.security.utils.ElementProxy; 25 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 30 31 37 public class XPathFilterCHGPContainer extends ElementProxy 38 implements TransformParam { 39 40 41 private static final String _TAG_INCLUDE_BUT_SEARCH = "IncludeButSearch"; 42 43 44 private static final String _TAG_EXCLUDE_BUT_SEARCH = "ExcludeButSearch"; 45 46 47 private static final String _TAG_EXCLUDE = "Exclude"; 48 49 50 public static final String _TAG_XPATHCHGP = "XPathAlternative"; 51 52 53 public static final String _ATT_INCLUDESLASH = "IncludeSlashPolicy"; 54 55 56 public static final boolean IncludeSlash = true; 57 58 59 public static final boolean ExcludeSlash = false; 60 61 65 private XPathFilterCHGPContainer() { 66 67 } 69 70 79 private XPathFilterCHGPContainer(Document doc, boolean includeSlashPolicy, 80 String includeButSearch, 81 String excludeButSearch, String exclude) { 82 83 super(doc); 84 85 if (includeSlashPolicy) { 86 this._constructionElement 87 .setAttributeNS(null, XPathFilterCHGPContainer._ATT_INCLUDESLASH, "true"); 88 } else { 89 this._constructionElement 90 .setAttributeNS(null, XPathFilterCHGPContainer._ATT_INCLUDESLASH, "false"); 91 } 92 93 if ((includeButSearch != null) 94 && (includeButSearch.trim().length() > 0)) { 95 Element includeButSearchElem = 96 ElementProxy.createElementForFamily(doc, this.getBaseNamespace(), 97 XPathFilterCHGPContainer 98 ._TAG_INCLUDE_BUT_SEARCH); 99 100 includeButSearchElem 101 .appendChild(this._doc 102 .createTextNode(indentXPathText(includeButSearch))); 103 this._constructionElement.appendChild(doc.createTextNode("\n")); 104 this._constructionElement.appendChild(includeButSearchElem); 105 } 106 107 if ((excludeButSearch != null) 108 && (excludeButSearch.trim().length() > 0)) { 109 Element excludeButSearchElem = 110 ElementProxy.createElementForFamily(doc, this.getBaseNamespace(), 111 XPathFilterCHGPContainer 112 ._TAG_EXCLUDE_BUT_SEARCH); 113 114 excludeButSearchElem 115 .appendChild(this._doc 116 .createTextNode(indentXPathText(excludeButSearch))); 117 this._constructionElement.appendChild(doc.createTextNode("\n")); 118 this._constructionElement.appendChild(excludeButSearchElem); 119 } 120 121 if ((exclude != null) && (exclude.trim().length() > 0)) { 122 Element excludeElem = ElementProxy.createElementForFamily(doc, 123 this.getBaseNamespace(), 124 XPathFilterCHGPContainer._TAG_EXCLUDE); 125 126 excludeElem 127 .appendChild(this._doc.createTextNode(indentXPathText(exclude))); 128 this._constructionElement.appendChild(doc.createTextNode("\n")); 129 this._constructionElement.appendChild(excludeElem); 130 } 131 132 this._constructionElement.appendChild(doc.createTextNode("\n")); 133 } 134 135 141 static String indentXPathText(String xp) { 142 143 if ((xp.length() > 2) && (!Character.isWhitespace(xp.charAt(0)))) { 144 return "\n" + xp + "\n"; 145 } 146 return xp; 147 148 } 149 150 157 private XPathFilterCHGPContainer(Element element, String BaseURI) 158 throws XMLSecurityException { 159 super(element, BaseURI); 160 } 161 162 172 public static XPathFilterCHGPContainer getInstance(Document doc, 173 boolean includeSlashPolicy, String includeButSearch, 174 String excludeButSearch, String exclude) { 175 176 return new XPathFilterCHGPContainer(doc, includeSlashPolicy, 177 includeButSearch, excludeButSearch, 178 exclude); 179 } 180 181 190 public static XPathFilterCHGPContainer getInstance( 191 Element element, String BaseURI) throws XMLSecurityException { 192 return new XPathFilterCHGPContainer(element, BaseURI); 193 } 194 195 201 private String getXStr(String type) { 202 203 if (this.length(this.getBaseNamespace(), type) != 1) { 204 return ""; 205 } 206 207 Element xElem = XMLUtils.selectNode(this._constructionElement.getFirstChild(), this.getBaseNamespace(), 208 type,0); 209 210 return XMLUtils.getFullTextChildrenFromElement(xElem); 211 } 212 213 218 public String getIncludeButSearch() { 219 return this.getXStr(XPathFilterCHGPContainer._TAG_INCLUDE_BUT_SEARCH); 220 } 221 222 227 public String getExcludeButSearch() { 228 return this.getXStr(XPathFilterCHGPContainer._TAG_EXCLUDE_BUT_SEARCH); 229 } 230 231 236 public String getExclude() { 237 return this.getXStr(XPathFilterCHGPContainer._TAG_EXCLUDE); 238 } 239 240 245 public boolean getIncludeSlashPolicy() { 246 247 return this._constructionElement 248 .getAttributeNS(null, XPathFilterCHGPContainer._ATT_INCLUDESLASH) 249 .equals("true"); 250 } 251 252 261 private Node getHereContextNode(String type) { 262 263 if (this.length(this.getBaseNamespace(), type) != 1) { 264 return null; 265 } 266 267 return XMLUtils.selectNodeText(this._constructionElement.getFirstChild(), this.getBaseNamespace(), 268 type,0); 269 } 270 271 276 public Node getHereContextNodeIncludeButSearch() { 277 return this 278 .getHereContextNode(XPathFilterCHGPContainer._TAG_INCLUDE_BUT_SEARCH); 279 } 280 281 286 public Node getHereContextNodeExcludeButSearch() { 287 return this 288 .getHereContextNode(XPathFilterCHGPContainer._TAG_EXCLUDE_BUT_SEARCH); 289 } 290 291 296 public Node getHereContextNodeExclude() { 297 return this.getHereContextNode(XPathFilterCHGPContainer._TAG_EXCLUDE); 298 } 299 300 305 public final String getBaseLocalName() { 306 return XPathFilterCHGPContainer._TAG_XPATHCHGP; 307 } 308 309 314 public final String getBaseNamespace() { 315 return Transforms.TRANSFORM_XPATHFILTERCHGP; 316 } 317 } 318 | Popular Tags |