1 /*
   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  */
  21 package com.sun.org.apache.xml.internal.security.transforms.params;
  22 
  23 
  24 
  25 import com.sun.org.apache.xml.internal.security.transforms.TransformParam;
  26 import com.sun.org.apache.xml.internal.security.utils.Constants;
  27 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
  28 import org.w3c.dom.Document;
  29 import org.w3c.dom.NodeList;
  30 import org.w3c.dom.Text;
  31 
  32 
  33 /**
  34  * This Object serves both as namespace prefix resolver and as container for
  35  * the <CODE>ds:XPath</CODE> Element. It implements the {@link org.w3c.dom.Element} interface
  36  * and can be used directly in a DOM tree.
  37  *
  38  * @author Christian Geuer-Pollmann
  39  */
  40 public class XPathContainer extends SignatureElementProxy implements TransformParam {
  41 
  42    /**
  43     * Constructor XPathContainer
  44     *
  45     * @param doc
  46     */
  47    public XPathContainer(Document doc) {
  48       super(doc);
  49    }
  50 
  51    /**
  52     * Sets the TEXT value of the <CODE>ds:XPath</CODE> Element.
  53     *
  54     * @param xpath
  55     */
  56    public void setXPath(String xpath) {
  57 
  58       if (this._constructionElement.getChildNodes() != null) {
  59          NodeList nl = this._constructionElement.getChildNodes();
  60 
  61          for (int i = 0; i < nl.getLength(); i++) {
  62             this._constructionElement.removeChild(nl.item(i));
  63          }
  64       }
  65 
  66       Text xpathText = this._doc.createTextNode(xpath);
  67       this._constructionElement.appendChild(xpathText);
  68    }
  69 
  70    /**
  71     * Returns the TEXT value of the <CODE>ds:XPath</CODE> Element.
  72     *
  73     * @return the TEXT value of the <CODE>ds:XPath</CODE> Element.
  74     */
  75    public String getXPath() {
  76       return this.getTextFromTextChild();
  77    }
  78 
  79    /** @inheritDoc */
  80    public String getBaseLocalName() {
  81       return Constants._TAG_XPATH;
  82    }
  83 }