src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformC14NExclusive.java

Print this page


   1 /*
   2  * reserved comment block
   3  * DO NOT REMOVE OR ALTER!
   4  */
   5 /*
   6  * Copyright  1999-2004 The Apache Software Foundation.
   7  *
   8  *  Licensed under the Apache License, Version 2.0 (the "License");
   9  *  you may not use this file except in compliance with the License.
  10  *  You may obtain a copy of the License at


  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  *  Unless required by applicable law or agreed to in writing, software
  15  *  distributed under the License is distributed on an "AS IS" BASIS,
  16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  *  See the License for the specific language governing permissions and
  18  *  limitations under the License.
  19  *
  20  */
  21 package com.sun.org.apache.xml.internal.security.transforms.implementations;
  22 
  23 import java.io.OutputStream;
  24 
  25 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
  26 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
  27 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
  28 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
  29 import com.sun.org.apache.xml.internal.security.transforms.Transform;
  30 import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
  31 import com.sun.org.apache.xml.internal.security.transforms.Transforms;
  32 import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces;
  33 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
  34 import org.w3c.dom.Element;
  35 
  36 /**
  37  * Class TransformC14NExclusive
  38  *
  39  * @author $Author: mullan $
  40  * @version $Revision: 1.5 $
  41  */
  42 public class TransformC14NExclusive extends TransformSpi {
  43 
  44    /** Field implementedTransformURI */
  45    public static final String implementedTransformURI =
  46       Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS;
  47 
  48    /**
  49     * Method engineGetURI
  50     *
  51     * @inheritDoc
  52     */
  53    protected String engineGetURI() {
  54       return implementedTransformURI;
  55    }
  56 
  57    /**
  58     * Method enginePerformTransform
  59     *
  60     * @param input
  61     * @return the transformed of the input
  62     * @throws CanonicalizationException
  63     */
  64    protected XMLSignatureInput enginePerformTransform
  65         (XMLSignatureInput input, Transform _transformObject)
  66            throws CanonicalizationException {
  67             return enginePerformTransform(input, null, _transformObject);
  68    }
  69 
  70     protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream os, Transform _transformObject)
  71     throws CanonicalizationException {
  72       try {
  73          String inclusiveNamespaces = null;
  74 
  75          if (_transformObject
  76                  .length(InclusiveNamespaces
  77                     .ExclusiveCanonicalizationNamespace, InclusiveNamespaces
  78                     ._TAG_EC_INCLUSIVENAMESPACES) == 1) {
  79             Element inclusiveElement =
  80                 XMLUtils.selectNode(
  81                _transformObject.getElement().getFirstChild(),
  82                   InclusiveNamespaces.ExclusiveCanonicalizationNamespace,
  83                   InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,0);
  84 
  85             inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement,
  86                     _transformObject.getBaseURI()).getInclusiveNamespaces();



  87          }
  88 
  89          Canonicalizer20010315ExclOmitComments c14n =
  90             new Canonicalizer20010315ExclOmitComments();
  91          if (os!=null) {
  92             c14n.setWriter(os);
  93          }
  94          byte []result;
  95          result =c14n.engineCanonicalize(input, inclusiveNamespaces);
  96 
  97          XMLSignatureInput output=new XMLSignatureInput(result);
  98          if (os!=null) {
  99             output.setOutputStream(os);
 100          }
 101          return output;
 102       } catch (XMLSecurityException ex) {
 103          throw new CanonicalizationException("empty", ex);
 104       }
 105    }
 106 }
   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.transforms.implementations;
  24 
  25 import java.io.OutputStream;
  26 
  27 import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
  28 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
  29 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
  30 import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
  31 import com.sun.org.apache.xml.internal.security.transforms.Transform;
  32 import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
  33 import com.sun.org.apache.xml.internal.security.transforms.Transforms;
  34 import com.sun.org.apache.xml.internal.security.transforms.params.InclusiveNamespaces;
  35 import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
  36 import org.w3c.dom.Element;
  37 
  38 /**
  39  * Class TransformC14NExclusive
  40  *


  41  */
  42 public class TransformC14NExclusive extends TransformSpi {
  43 
  44     /** Field implementedTransformURI */
  45     public static final String implementedTransformURI =
  46         Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS;
  47 
  48     /**
  49      * Method engineGetURI
  50      *
  51      * @inheritDoc 
  52      */
  53     protected String engineGetURI() {
  54         return implementedTransformURI;
  55     }
  56 
  57     protected XMLSignatureInput enginePerformTransform(
  58         XMLSignatureInput input, OutputStream os, Transform transformObject
  59     ) throws CanonicalizationException {












  60         try {
  61             String inclusiveNamespaces = null;
  62 
  63             if (transformObject.length(
  64                 InclusiveNamespaces.ExclusiveCanonicalizationNamespace, 
  65                 InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1
  66             ) {
  67                 Element inclusiveElement =
  68                     XMLUtils.selectNode(
  69                         transformObject.getElement().getFirstChild(),
  70                         InclusiveNamespaces.ExclusiveCanonicalizationNamespace,
  71                         InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,
  72                         0
  73                     );
  74 
  75                 inclusiveNamespaces = 
  76                     new InclusiveNamespaces(
  77                         inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces();
  78             }
  79 
  80             Canonicalizer20010315ExclOmitComments c14n =
  81                 new Canonicalizer20010315ExclOmitComments();
  82             if (os != null) {
  83                 c14n.setWriter(os);
  84             }
  85             byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces);

  86 
  87             XMLSignatureInput output = new XMLSignatureInput(result);
  88             if (os != null) {
  89                 output.setOutputStream(os);
  90             }
  91             return output;      
  92         } catch (XMLSecurityException ex) {
  93             throw new CanonicalizationException("empty", ex);
  94         } 
  95     }
  96 }