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