View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /**
6    * Licensed to the Apache Software Foundation (ASF) under one
7    * or more contributor license agreements. See the NOTICE file
8    * distributed with this work for additional information
9    * regarding copyright ownership. The ASF licenses this file
10   * to you under the Apache License, Version 2.0 (the
11   * "License"); you may not use this file except in compliance
12   * with the License. You may obtain a copy of the License at
13   *
14   * http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing,
17   * software distributed under the License is distributed on an
18   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19   * KIND, either express or implied. See the License for the
20   * specific language governing permissions and limitations
21   * under the License.
22   */
23  package com.sun.org.apache.xml.internal.security.signature;
24  
25  import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
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.Element;
30  import org.w3c.dom.Node;
31  
32  /**
33   * Handles <code>&lt;ds:SignatureProperty&gt;</code> elements
34   * Additional information item concerning the generation of the signature(s) can
35   * be placed in this Element
36   *
37   * @author Christian Geuer-Pollmann
38   */
39  public class SignatureProperty extends SignatureElementProxy {
40  
41      /**
42       * Constructs{@link SignatureProperty} using specified <code>target</code> attribute
43       *
44       * @param doc the {@link Document} in which <code>XMLsignature</code> is placed
45       * @param target the <code>target</code> attribute references the <code>Signature</code>
46       * element to which the property applies SignatureProperty
47       */
48      public SignatureProperty(Document doc, String target) {
49          this(doc, target, null);
50      }
51  
52      /**
53       * Constructs {@link SignatureProperty} using sepcified <code>target</code> attribute and
54       * <code>id</code> attribute
55       *
56       * @param doc the {@link Document} in which <code>XMLsignature</code> is placed
57       * @param target the <code>target</code> attribute references the <code>Signature</code>
58       *  element to which the property applies
59       * @param id the <code>id</code> will be specified by {@link Reference#getURI} in validation
60       */
61      public SignatureProperty(Document doc, String target, String id) {
62          super(doc);
63  
64          this.setTarget(target);
65          this.setId(id);
66      }
67  
68      /**
69       * Constructs a {@link SignatureProperty} from an {@link Element}
70       * @param element <code>SignatureProperty</code> element
71       * @param BaseURI the URI of the resource where the XML instance was stored
72       * @throws XMLSecurityException
73       */
74      public SignatureProperty(Element element, String BaseURI) throws XMLSecurityException {
75          super(element, BaseURI);
76      }
77  
78      /**
79       *   Sets the <code>id</code> attribute
80       *
81       *   @param id the <code>id</code> attribute
82       */
83      public void setId(String id) {
84          if (id != null) {
85              this.constructionElement.setAttributeNS(null, Constants._ATT_ID, id);
86              this.constructionElement.setIdAttributeNS(null, Constants._ATT_ID, true);
87          }
88      }
89  
90      /**
91       * Returns the <code>id</code> attribute
92       *
93       * @return the <code>id</code> attribute
94       */
95      public String getId() {
96          return this.constructionElement.getAttributeNS(null, Constants._ATT_ID);
97      }
98  
99      /**
100      * Sets the <code>target</code> attribute
101      *
102      * @param target the <code>target</code> attribute
103      */
104     public void setTarget(String target) {
105         if (target != null) {
106             this.constructionElement.setAttributeNS(null, Constants._ATT_TARGET, target);
107         }
108     }
109 
110     /**
111      * Returns the <code>target</code> attribute
112      *
113      * @return the <code>target</code> attribute
114      */
115     public String getTarget() {
116         return this.constructionElement.getAttributeNS(null, Constants._ATT_TARGET);
117     }
118 
119     /**
120      * Method appendChild
121      *
122      * @param node
123      * @return the node in this element.
124      */
125     public Node appendChild(Node node) {
126         return this.constructionElement.appendChild(node);
127     }
128 
129     /** @inheritDoc */
130     public String getBaseLocalName() {
131         return Constants._TAG_SIGNATUREPROPERTY;
132     }
133 }