jdk/src/share/classes/com/sun/org/apache/xml/internal/security/transforms/Transforms.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1337 e8d6cef36199
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.security.c14n.InvalidCanonicalizerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.security.utils.Constants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import org.w3c.dom.DOMException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Holder of the {@link com.sun.org.apache.xml.internal.security.transforms.Transform} steps to be performed on the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The input to the first Transform is the result of dereferencing the <code>URI</code> attribute of the <code>Reference</code> element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The output from the last Transform is the input for the <code>DigestMethod algorithm</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see Transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see com.sun.org.apache.xml.internal.security.signature.Reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class Transforms extends SignatureElementProxy {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   /** {@link java.util.logging} logging facility */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        java.util.logging.Logger.getLogger(Transforms.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
   //J-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   /** Canonicalization - Required Canonical XML (omits comments) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   public static final String TRANSFORM_C14N_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   /** Canonicalization - Recommended Canonical XML with Comments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   public static final String TRANSFORM_C14N_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
   /** Canonicalization - Required Exclusive Canonicalization (omits comments) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
   public static final String TRANSFORM_C14N_EXCL_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   /** Canonicalization - Recommended Exclusive Canonicalization with Comments */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
   public static final String TRANSFORM_C14N_EXCL_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   /** Transform - Optional XSLT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
   public static final String TRANSFORM_XSLT = "http://www.w3.org/TR/1999/REC-xslt-19991116";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
   /** Transform - Required base64 decoding */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   public static final String TRANSFORM_BASE64_DECODE = Constants.SignatureSpecNS + "base64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
   /** Transform - Recommended XPath */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
   public static final String TRANSFORM_XPATH = "http://www.w3.org/TR/1999/REC-xpath-19991116";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
   /** Transform - Required Enveloped Signature */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   public static final String TRANSFORM_ENVELOPED_SIGNATURE = Constants.SignatureSpecNS + "enveloped-signature";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   /** Transform - XPointer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
   public static final String TRANSFORM_XPOINTER = "http://www.w3.org/TR/2001/WD-xptr-20010108";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
   /** Transform - XPath Filter v2.0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
   public static final String TRANSFORM_XPATH2FILTER04 = "http://www.w3.org/2002/04/xmldsig-filter2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
   /** Transform - XPath Filter */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
   public static final String TRANSFORM_XPATH2FILTER = "http://www.w3.org/2002/06/xmldsig-filter2";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
   /** Transform - XPath Filter  CHGP private*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
   public static final String TRANSFORM_XPATHFILTERCHGP = "http://www.nue.et-inf.uni-siegen.de/~geuer-pollmann/#xpathFilter";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   //J+
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
   Element []transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    * Consturcts {@link Transforms}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    * @param doc the {@link Document} in which <code>XMLsignature</code> will be placed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   public Transforms(Document doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      super(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      XMLUtils.addReturnToElement(this._constructionElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    * Consturcts {@link Transforms} from {@link Element} which is <code>Transforms</code> Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    * @param element  is <code>Transforms</code> element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    * @param BaseURI the URI where the XML instance was stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    * @throws DOMException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    * @throws InvalidTransformException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    * @throws XMLSecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    * @throws XMLSignatureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   public Transforms(Element element, String BaseURI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
           throws DOMException, XMLSignatureException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                  InvalidTransformException, TransformationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                  XMLSecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      super(element, BaseURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      int numberOfTransformElems = this.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      if (numberOfTransformElems == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         // At least ont Transform element must be present. Bad.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         Object exArgs[] = { Constants._TAG_TRANSFORM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                             Constants._TAG_TRANSFORMS };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         throw new TransformationException("xml.WrongContent", exArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    * Adds the <code>Transform</code> with the specified <code>Transform algorithm URI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    * @param transformURI the URI form of transform that indicates which transformation is applied to data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
   public void addTransform(String transformURI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
           throws TransformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         if (true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Transforms.addTransform(" + transformURI + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         Transform transform = Transform.getInstance(this._doc, transformURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         this.addTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      } catch (InvalidTransformException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    * Adds the <code>Transform</code> with the specified <code>Transform algorithm URI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    * @param transformURI the URI form of transform that indicates which transformation is applied to data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    * @param contextElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    * @see Transform#getInstance(Document doc, String algorithmURI, Element childElement)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   public void addTransform(String transformURI, Element contextElement)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
           throws TransformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         if (true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Transforms.addTransform(" + transformURI + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         Transform transform = Transform.getInstance(this._doc, transformURI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                                     contextElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         this.addTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
      } catch (InvalidTransformException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    * Adds the <code>Transform</code> with the specified <code>Transform algorithm URI</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    * @param transformURI the URI form of transform that indicates which transformation is applied to data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    * @param contextNodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    * @see Transform#getInstance(Document doc, String algorithmURI, NodeList contextNodes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
   public void addTransform(String transformURI, NodeList contextNodes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
           throws TransformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         Transform transform = Transform.getInstance(this._doc, transformURI,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                                     contextNodes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         this.addTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      } catch (InvalidTransformException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    * Adds a user-provided Transform step.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    * @param transform {@link Transform} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
   private void addTransform(Transform transform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
      if (true)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Transforms.addTransform(" + transform.getURI() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      Element transformElement = transform.getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      this._constructionElement.appendChild(transformElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      XMLUtils.addReturnToElement(this._constructionElement);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    * Applies all included <code>Transform</code>s to xmlSignatureInput and returns the result of these transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    * @param xmlSignatureInput the input for the <code>Transform</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    * @return the result of the <code>Transforms</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
   public XMLSignatureInput performTransforms(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
           XMLSignatureInput xmlSignatureInput) throws TransformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             return performTransforms(xmlSignatureInput,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    * Applies all included <code>Transform</code>s to xmlSignatureInput and returns the result of these transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    * @param xmlSignatureInput the input for the <code>Transform</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    * @param os where to output the last transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    * @return the result of the <code>Transforms</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public XMLSignatureInput performTransforms(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            XMLSignatureInput xmlSignatureInput,OutputStream os) throws TransformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        int last=this.getLength()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         for (int i = 0; i < last; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            Transform t = this.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "Preform the (" + i + ")th " + t.getURI() + " transform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                        xmlSignatureInput = t.performTransform(xmlSignatureInput);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         if (last>=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        Transform t = this.item(last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            xmlSignatureInput = t.performTransform(xmlSignatureInput, os);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         return xmlSignatureInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
      } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      // } catch (ParserConfigurationException ex) { throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      // } catch (SAXException ex) { throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      } catch (CanonicalizationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      } catch (InvalidCanonicalizerException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    * Return the nonnegative number of transformations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    * @return the number of transformations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
   public int getLength()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                /*Element nscontext = XMLUtils.createDSctx(this._doc, "ds",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                                      Constants.SignatureSpecNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
             NodeList transformElems =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                XPathAPI.selectNodeList(this._constructionElement,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                        "./ds:Transform", nscontext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
             return transformElems.getLength();*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
       if (transforms==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        transforms=XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
           "Transform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
       return transforms.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    * Return the <it>i</it><sup>th</sup> <code>{@link Transform}</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    * Valid <code>i</code> values are 0 to <code>{@link #getLength}-1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    * @param i index of {@link Transform} to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    * @return the <it>i</it><sup>th</sup> transforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    * @throws TransformationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
   public Transform item(int i) throws TransformationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        if (transforms==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                transforms=XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                "Transform");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        return new Transform(transforms[i], this._baseURI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                } catch (XMLSecurityException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        throw new TransformationException("empty", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
   /** @inheritDoc */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
   public String getBaseLocalName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      return Constants._TAG_TRANSFORMS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
}