J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 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.signature; |
| 22 | |
| 23 | |
| 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.IdResolver; |
| 28 | import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; |
| 29 | import com.sun.org.apache.xml.internal.security.utils.XMLUtils; |
| 30 | import org.w3c.dom.Document; |
| 31 | import org.w3c.dom.Element; |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * Handles <code><ds:SignatureProperties></code> elements |
| 36 | * This Element holds {@link SignatureProperty} that contian additional information items |
| 37 | * concerning the generation of the signature. |
| 38 | * for example, data-time stamp, serial number of cryptographic hardware. |
| 39 | * |
| 40 | * @author Christian Geuer-Pollmann |
| 41 | * |
| 42 | */ |
| 43 | public class SignatureProperties extends SignatureElementProxy { |
| 44 | |
| 45 | /** {@link java.util.logging} logging facility */ |
| 46 | static java.util.logging.Logger log = |
| 47 | java.util.logging.Logger.getLogger(SignatureProperties.class.getName()); |
| 48 | |
| 49 | /** |
| 50 | * Constructor SignatureProperties |
| 51 | * |
| 52 | * @param doc |
| 53 | */ |
| 54 | public SignatureProperties(Document doc) { |
| 55 | |
| 56 | super(doc); |
| 57 | |
| 58 | XMLUtils.addReturnToElement(this._constructionElement); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Constructs {@link SignatureProperties} from {@link Element} |
| 63 | * @param element <code>SignatureProperties</code> elementt |
| 64 | * @param BaseURI the URI of the resource where the XML instance was stored |
| 65 | * @throws XMLSecurityException |
| 66 | */ |
| 67 | public SignatureProperties(Element element, String BaseURI) |
| 68 | throws XMLSecurityException { |
| 69 | super(element, BaseURI); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Return the nonnegative number of added SignatureProperty elements. |
| 74 | * |
| 75 | * @return the number of SignatureProperty elements |
| 76 | */ |
| 77 | public int getLength() { |
| 78 | |
| 79 | Element[] propertyElems = |
| 80 | XMLUtils.selectDsNodes(this._constructionElement, |
| 81 | Constants._TAG_SIGNATUREPROPERTY |
| 82 | ); |
| 83 | |
| 84 | return propertyElems.length; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Return the <it>i</it><sup>th</sup> SignatureProperty. Valid <code>i</code> |
| 89 | * values are 0 to <code>{link@ getSize}-1</code>. |
| 90 | * |
| 91 | * @param i Index of the requested {@link SignatureProperty} |
| 92 | * @return the <it>i</it><sup>th</sup> SignatureProperty |
| 93 | * @throws XMLSignatureException |
| 94 | */ |
| 95 | public SignatureProperty item(int i) throws XMLSignatureException { |
| 96 | try { |
| 97 | Element propertyElem = |
| 98 | XMLUtils.selectDsNode(this._constructionElement, |
| 99 | Constants._TAG_SIGNATUREPROPERTY, |
| 100 | i ); |
| 101 | |
| 102 | if (propertyElem == null) { |
| 103 | return null; |
| 104 | } |
| 105 | return new SignatureProperty(propertyElem, this._baseURI); |
| 106 | } catch (XMLSecurityException ex) { |
| 107 | throw new XMLSignatureException("empty", ex); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Sets the <code>Id</code> attribute |
| 113 | * |
| 114 | * @param Id the <code>Id</code> attribute |
| 115 | */ |
| 116 | public void setId(String Id) { |
| 117 | |
| 118 | if ((this._state == MODE_SIGN) && (Id != null)) { |
| 119 | this._constructionElement.setAttributeNS(null, Constants._ATT_ID, Id); |
| 120 | IdResolver.registerElementById(this._constructionElement, Id); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Returns the <code>Id</code> attribute |
| 126 | * |
| 127 | * @return the <code>Id</code> attribute |
| 128 | */ |
| 129 | public String getId() { |
| 130 | return this._constructionElement.getAttributeNS(null, Constants._ATT_ID); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Method addSignatureProperty |
| 135 | * |
| 136 | * @param sp |
| 137 | */ |
| 138 | public void addSignatureProperty(SignatureProperty sp) { |
| 139 | this._constructionElement.appendChild(sp.getElement()); |
| 140 | XMLUtils.addReturnToElement(this._constructionElement); |
| 141 | } |
| 142 | |
| 143 | /** @inheritDoc */ |
| 144 | public String getBaseLocalName() { |
| 145 | return Constants._TAG_SIGNATUREPROPERTIES; |
| 146 | } |
| 147 | } |