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.keys.content;
  22 
  23 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
  24 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
  25 import com.sun.org.apache.xml.internal.security.transforms.Transforms;
  26 import com.sun.org.apache.xml.internal.security.utils.Constants;
  27 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
  28 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
  29 import org.w3c.dom.Attr;
  30 import org.w3c.dom.Document;
  31 import org.w3c.dom.Element;
  32 
  33 /**
  34  *
  35  * @author $Author: mullan $
  36  */
  37 public class RetrievalMethod extends SignatureElementProxy
  38         implements KeyInfoContent {
  39 
  40    //J-
  41     /** DSA retrieval */
  42    public static final String TYPE_DSA     = Constants.SignatureSpecNS + "DSAKeyValue";
  43    /** RSA retrieval */
  44    public static final String TYPE_RSA     = Constants.SignatureSpecNS + "RSAKeyValue";
  45    /** PGP retrieval */
  46    public static final String TYPE_PGP     = Constants.SignatureSpecNS + "PGPData";
  47    /** SPKI retrieval */
  48    public static final String TYPE_SPKI    = Constants.SignatureSpecNS + "SPKIData";
  49    /** MGMT retrieval */
  50    public static final String TYPE_MGMT    = Constants.SignatureSpecNS + "MgmtData";
  51    /** X509 retrieval */
  52    public static final String TYPE_X509    = Constants.SignatureSpecNS + "X509Data";
  53    /** RAWX509 retrieval */
  54    public static final String TYPE_RAWX509 = Constants.SignatureSpecNS + "rawX509Certificate";
  55    //J+
  56 
  57    /**
  58     * Constructor RetrievalMethod
  59     *
  60     * @param element
  61     * @param BaseURI
  62     * @throws XMLSecurityException
  63     */
  64    public RetrievalMethod(Element element, String BaseURI)
  65            throws XMLSecurityException {
  66       super(element, BaseURI);
  67    }
  68 
  69    /**
  70     * Constructor RetrievalMethod
  71     *
  72     * @param doc
  73     * @param URI
  74     * @param transforms
  75     * @param Type
  76     */
  77    public RetrievalMethod(Document doc, String URI, Transforms transforms,
  78                           String Type) {
  79 
  80       super(doc);
  81 
  82       this._constructionElement.setAttributeNS(null, Constants._ATT_URI, URI);
  83 
  84       if (Type != null) {
  85          this._constructionElement.setAttributeNS(null, Constants._ATT_TYPE, Type);
  86       }
  87 
  88       if (transforms != null) {
  89          this._constructionElement.appendChild(transforms.getElement());
  90          XMLUtils.addReturnToElement(this._constructionElement);
  91       }
  92    }
  93 
  94    /**
  95     * Method getURIAttr
  96     *
  97     * @return the URI attribute
  98     */
  99    public Attr getURIAttr() {
 100       return this._constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
 101    }
 102 
 103    /**
 104     * Method getURI
 105     *
 106     *
 107     * @return URI string
 108     */
 109    public String getURI() {
 110       return this.getURIAttr().getNodeValue();
 111    }
 112 
 113    /** @return the type*/
 114    public String getType() {
 115       return this._constructionElement.getAttributeNS(null, Constants._ATT_TYPE);
 116    }
 117 
 118    /**
 119     * Method getTransforms
 120     *
 121     *
 122     * @throws XMLSecurityException
 123     * @return the transforamitons
 124     */
 125    public Transforms getTransforms() throws XMLSecurityException {
 126 
 127       try {
 128        Element transformsElem =
 129              XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
 130                                                 Constants
 131                                                    ._TAG_TRANSFORMS, 0);
 132 
 133          if (transformsElem != null) {
 134             return new Transforms(transformsElem, this._baseURI);
 135          }
 136 
 137          return null;
 138       } catch (XMLSignatureException ex) {
 139          throw new XMLSecurityException("empty", ex);
 140       }
 141    }
 142 
 143    /** @inheritDoc */
 144    public String getBaseLocalName() {
 145       return Constants._TAG_RETRIEVALMETHOD;
 146    }
 147 }