jdk/src/share/classes/com/sun/org/apache/xml/internal/security/signature/XMLSignatureInput.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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xml.internal.security.signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.ByteArrayOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.xml.parsers.DocumentBuilder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.xml.parsers.DocumentBuilderFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.xml.parsers.ParserConfigurationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityRuntimeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xml.internal.security.utils.JavaUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Class XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * $todo$ check whether an XMLSignatureInput can be _both_, octet stream _and_ node set?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class XMLSignatureInput  implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
         static java.util.logging.Logger log =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                java.util.logging.Logger.getLogger(XMLSignatureInput.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * The XMLSignature Input can be either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *   A byteArray like with/or without InputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *   Or a  nodeSet like defined either:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *                     * as a collection of nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *                     * or as subnode excluding or not commets and excluding or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *                            not other nodes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    * Some InputStreams do not support the {@link java.io.InputStream#reset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    * method, so we read it in completely and work on our Proxy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
   InputStream _inputOctetStreamProxy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    * The original NodeSet for this XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
   Set _inputNodeSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    * The original Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
   Node _subNode=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    * Exclude Node *for enveloped transformations*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
   Node excludeNode=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   boolean excludeComments=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   boolean isNodeSet=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    * A cached bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   byte []bytes=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    * Some Transforms may require explicit MIME type, charset (IANA registered "character set"), or other such information concerning the data they are receiving from an earlier Transform or the source data, although no Transform algorithm specified in this document needs such explicit information. Such data characteristics are provided as parameters to the Transform algorithm and should be described in the specification for the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   private String _MIMEType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    * Field _SourceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   private String _SourceURI = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    * Node Filter list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
   List nodeFilters=new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
   boolean needsToBeExpanded=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    * Check if the structured is needed to be circumbented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    * @return true if so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   public boolean isNeedsToBeExpanded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
           return needsToBeExpanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    * Set if the structured is needed to be circumbented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    * @param needsToBeExpanded true if so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
   public void setNeedsToBeExpanded(boolean needsToBeExpanded) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        this.needsToBeExpanded = needsToBeExpanded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
   OutputStream outputStream=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    * Construct a XMLSignatureInput from an octet array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    * This is a comfort method, which internally converts the byte[] array into an InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    * <p>NOTE: no defensive copy</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    * @param inputOctets an octet array which including XML document or node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   public XMLSignatureInput(byte[] inputOctets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
      // NO  defensive copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      //this._inputOctetStreamProxy = new ByteArrayInputStream(inputOctets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      this.bytes=inputOctets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   }
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
    * Constructs a <code>XMLSignatureInput</code> from an octet stream. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    * stream is directly read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    * @param inputOctetStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
   public XMLSignatureInput(InputStream inputOctetStream)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
          this._inputOctetStreamProxy=inputOctetStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      //this(JavaUtils.getBytesFromStream(inputOctetStream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    * Construct a XMLSignatureInput from a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    * This is a comfort method, which internally converts the String into a byte[] array using the {@link java.lang.String#getBytes()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    * @param inputStr the input String which including XML document or node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
   public XMLSignatureInput(String inputStr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      this(inputStr.getBytes());
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
    * Construct a XMLSignatureInput from a String with a given encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    * This is a comfort method, which internally converts the String into a byte[] array using the {@link java.lang.String#getBytes()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    * @param inputStr the input String with encoding <code>encoding</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    * @param encoding the encoding of <code>inputStr</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    * @throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
   public XMLSignatureInput(String inputStr, String encoding)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
           throws UnsupportedEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      this(inputStr.getBytes(encoding));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    * Construct a XMLSignatureInput from a subtree rooted by rootNode. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    * method included the node and <I>all</I> his descendants in the output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    * @param rootNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
   public XMLSignatureInput(Node rootNode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      this._subNode = rootNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    * Constructor XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    * @param inputNodeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    * @param usedXPathAPI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
   public XMLSignatureInput(Set inputNodeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
       this._inputNodeSet = inputNodeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    * Returns the node set from input which was specified as the parameter of {@link XMLSignatureInput} constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    * @return the node set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    * @throws SAXException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    * @throws ParserConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    * @throws ParserConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    * @throws SAXException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
   public Set getNodeSet() throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
              return getNodeSet(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    * Returns the node set from input which was specified as the parameter of {@link XMLSignatureInput} constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    * @param circunvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    * @return the node set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    * @throws SAXException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    * @throws ParserConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    * @throws ParserConfigurationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    * @throws SAXException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
   public Set getNodeSet(boolean circunvent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
           throws ParserConfigurationException, IOException, SAXException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                  CanonicalizationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      if (this._inputNodeSet!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
          return this._inputNodeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
          if (this.isElement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    if (circunvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        XMLUtils.circumventBug2650(XMLUtils.getOwnerDocument(_subNode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            this._inputNodeSet = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            XMLUtils.getSet(_subNode,this._inputNodeSet, excludeNode, this.excludeComments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    return this._inputNodeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
       else if (this.isOctetStream()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         convertToNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         HashSet result=new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         XMLUtils.getSet(_subNode, result,null,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            //this._inputNodeSet=result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         "getNodeSet() called but no input data present");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    * Returns the Octect stream(byte Stream) from input which was specified as the parameter of {@link XMLSignatureInput} constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    * @return the Octect stream(byte Stream) from input which was specified as the parameter of {@link XMLSignatureInput} constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
   public InputStream getOctetStream()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
           throws IOException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      return getResetableInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return real octect stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public InputStream getOctetStreamReal () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
       return this._inputOctetStreamProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    * Returns the byte array from input which was specified as the parameter of {@link XMLSignatureInput} constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    * @return the byte[] from input which was specified as the parameter of {@link XMLSignatureInput} constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
   public byte[] getBytes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
           throws IOException, CanonicalizationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    if (bytes!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
          InputStream is = getResetableInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
          if (is!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        //reseatable can read again bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                if (bytes==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            is.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            bytes=JavaUtils.getBytesFromStream(is);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                return bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         Canonicalizer20010315OmitComments c14nizer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        new Canonicalizer20010315OmitComments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        bytes=c14nizer.engineCanonicalize(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    * Determines if the object has been set up with a Node set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    * @return true is the object has been set up with a Node set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
   public boolean isNodeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      return (( (this._inputOctetStreamProxy == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
              && (this._inputNodeSet != null) ) || isNodeSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    * Determines if the object has been set up with an Element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    * @return true is the object has been set up with a Node set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
   public boolean isElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                return ((this._inputOctetStreamProxy==null)&& (this._subNode!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                                && (this._inputNodeSet==null) && !isNodeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    * Determines if the object has been set up with an octet stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    * @return true is the object has been set up with an octet stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
   public boolean isOctetStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      return ( ((this._inputOctetStreamProxy != null) || bytes!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
              && ((this._inputNodeSet == null) && _subNode ==null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    * Determines if the object has been set up with a ByteArray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    * @return true is the object has been set up with an octet stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
   public boolean isByteArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
      return ( (bytes!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
              && ((this._inputNodeSet == null) && _subNode ==null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    * Is the object correctly set up?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    * @return true if the object has been set up correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
   public boolean isInitialized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      return (this.isOctetStream() || this.isNodeSet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    * Returns MIMEType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    * @return MIMEType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
   public String getMIMEType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      return this._MIMEType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    * Sets MIMEType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    * @param MIMEType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
   public void setMIMEType(String MIMEType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
      this._MIMEType = MIMEType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    * Return SourceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    * @return SourceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
   public String getSourceURI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      return this._SourceURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    * Sets SourceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    * @param SourceURI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
   public void setSourceURI(String SourceURI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      this._SourceURI = SourceURI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    * Method toString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    * @inheritDoc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
   public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      if (this.isNodeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         return "XMLSignatureInput/NodeSet/" + this._inputNodeSet.size()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                   + " nodes/" + this.getSourceURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      if (this.isElement()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return "XMLSignatureInput/Element/" + this._subNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        + " exclude "+ this.excludeNode + " comments:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        this.excludeComments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        +"/" + this.getSourceURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return "XMLSignatureInput/OctetStream/" + this.getBytes().length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                   + " octets/" + this.getSourceURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            return "XMLSignatureInput/OctetStream//" + this.getSourceURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    * Method getHTMLRepresentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    * @throws XMLSignatureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    * @return The HTML representation for this XMLSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
   public String getHTMLRepresentation() throws XMLSignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      XMLSignatureInputDebugger db = new XMLSignatureInputDebugger(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      return db.getHTMLRepresentation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    * Method getHTMLRepresentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    * @param inclusiveNamespaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    * @throws XMLSignatureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    * @return The HTML representation for this XMLSignature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
   public String getHTMLRepresentation(Set inclusiveNamespaces)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
           throws XMLSignatureException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      XMLSignatureInputDebugger db = new XMLSignatureInputDebugger( this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                        inclusiveNamespaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      return db.getHTMLRepresentation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    * Gets the exclude node of this XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    * @return Returns the excludeNode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public Node getExcludeNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
           return excludeNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Sets the exclude node of this XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param excludeNode The excludeNode to set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     public void setExcludeNode(Node excludeNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            this.excludeNode = excludeNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      * Gets the node of this XMLSignatureInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      * @return The excludeNode set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     public Node getSubNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return _subNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      * @return Returns the excludeComments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     public boolean isExcludeComments() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return excludeComments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
      * @param excludeComments The excludeComments to set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     public void setExcludeComments(boolean excludeComments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        this.excludeComments = excludeComments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         * @param diOs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
         * @throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         * @throws CanonicalizationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        public void updateOutputStream(OutputStream diOs) throws CanonicalizationException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (diOs==outputStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (bytes!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            diOs.write(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         }else if (_inputOctetStreamProxy==null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
             Canonicalizer20010315OmitComments c14nizer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    new Canonicalizer20010315OmitComments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
             c14nizer.setWriter(diOs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            c14nizer.engineCanonicalize(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            InputStream is = getResetableInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            if (bytes!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                //already read write it, can be rea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                diOs.write(bytes,0,bytes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            is.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            int num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            byte[] bytesT = new byte[1024];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            while ((num=is.read(bytesT))>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                diOs.write(bytesT,0,num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * @param os
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        public void setOutputStream(OutputStream os) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                outputStream=os;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    protected InputStream getResetableInputStream() throws IOException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if ((_inputOctetStreamProxy instanceof ByteArrayInputStream) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            if (!_inputOctetStreamProxy.markSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                throw new RuntimeException("Accepted as Markable but not truly been"+_inputOctetStreamProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
           return _inputOctetStreamProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (bytes!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            _inputOctetStreamProxy=new ByteArrayInputStream(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            return _inputOctetStreamProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (_inputOctetStreamProxy ==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (_inputOctetStreamProxy.markSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if (log.isLoggable(java.util.logging.Level.INFO))                                  log.log(java.util.logging.Level.INFO, "Mark Suported but not used as reset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        bytes=JavaUtils.getBytesFromStream(_inputOctetStreamProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        _inputOctetStreamProxy.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        _inputOctetStreamProxy=new ByteArrayInputStream(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return _inputOctetStreamProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
         * @param filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        public void addNodeFilter(NodeFilter filter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                if (isOctetStream()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                convertToNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                                throw new XMLSecurityRuntimeException("signature.XMLSignatureInput.nodesetReference",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                nodeFilters.add(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
         * @return the node filters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        public List getNodeFilters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                // TODO Auto-generated method stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                return nodeFilters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * @param b
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        public void setNodeSet(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                isNodeSet=b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        void convertToNodes() throws CanonicalizationException, ParserConfigurationException, IOException, SAXException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        dfactory.setValidating(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        dfactory.setNamespaceAware(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        DocumentBuilder db = dfactory.newDocumentBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        // select all nodes, also the comments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
           db.setErrorHandler(new com.sun.org.apache.xml.internal.security.utils
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
              .IgnoreAllErrorHandler());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
           Document doc = db.parse(this.getOctetStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
           XMLUtils.circumventBug2650(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
           this._subNode=doc.getDocumentElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        } catch (SAXException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
           // if a not-wellformed nodeset exists, put a container around it...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
           ByteArrayOutputStream baos = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
           baos.write("<container>".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
           baos.write(this.getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
           baos.write("</container>".getBytes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
           byte result[] = baos.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
           Document document = db.parse(new ByteArrayInputStream(result));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
           this._subNode=document.getDocumentElement().getFirstChild().getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        this._inputOctetStreamProxy=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        this.bytes=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
}