src/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformC14NExclusiveWithComments.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.Canonicalizer20010315ExclWithComments;
  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  * Implements the <CODE>http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments</CODE>
  38  * transform.
  39  *
  40  * @author Christian Geuer-Pollmann
  41  */
  42 public class TransformC14NExclusiveWithComments extends TransformSpi {
  43 
  44    /** Field implementedTransformURI */
  45    public static final String implementedTransformURI =
  46       Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS;
  47 
  48    /**
  49     * Method engineGetURI
  50     *@inheritDoc
  51     *
  52     */
  53    protected String engineGetURI() {
  54       return implementedTransformURI;
  55    }
  56 
  57    /**
  58     * @inheritDoc
  59     */
  60    protected XMLSignatureInput enginePerformTransform
  61         (XMLSignatureInput input, Transform _transformObject)
  62            throws CanonicalizationException {
  63             return enginePerformTransform(input, null, _transformObject);
  64    }
  65 
  66     protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input,OutputStream os, Transform _transformObject)
  67     throws CanonicalizationException {
  68      try {
  69         String inclusiveNamespaces = null;
  70 
  71         if (_transformObject
  72                 .length(InclusiveNamespaces
  73                    .ExclusiveCanonicalizationNamespace, InclusiveNamespaces
  74                    ._TAG_EC_INCLUSIVENAMESPACES) == 1) {
  75            Element inclusiveElement =
  76                XMLUtils.selectNode(
  77               _transformObject.getElement().getFirstChild(),
  78                  InclusiveNamespaces.ExclusiveCanonicalizationNamespace,
  79                  InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES,0);
  80 
  81            inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement,
  82                    _transformObject.getBaseURI()).getInclusiveNamespaces();




  83         }
  84 
  85         Canonicalizer20010315ExclWithComments c14n =
  86             new Canonicalizer20010315ExclWithComments();
  87         if (os!=null) {
  88            c14n.setWriter( os);
  89         }
  90         byte []result;
  91         result =c14n.engineCanonicalize(input, inclusiveNamespaces);
  92         XMLSignatureInput output=new XMLSignatureInput(result);
  93 
  94         return output;
  95      } catch (XMLSecurityException ex) {
  96         throw new CanonicalizationException("empty", ex);
  97      }
  98    }
  99 }
   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.Canonicalizer20010315ExclWithComments;
  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  * Implements the <CODE>http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments</CODE>
  40  * transform.
  41  *
  42  * @author Christian Geuer-Pollmann
  43  */
  44 public class TransformC14NExclusiveWithComments extends TransformSpi {
  45 
  46     /** Field implementedTransformURI */
  47     public static final String implementedTransformURI =
  48         Transforms.TRANSFORM_C14N_EXCL_WITH_COMMENTS;
  49 
  50     /**
  51      * Method engineGetURI
  52      *@inheritDoc 
  53      *
  54      */
  55     protected String engineGetURI() {
  56         return implementedTransformURI;
  57     }
  58 
  59     protected XMLSignatureInput enginePerformTransform(
  60         XMLSignatureInput input, OutputStream os, Transform transformObject
  61     ) throws CanonicalizationException {








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

  90 
  91             return output;
  92         } catch (XMLSecurityException ex) {
  93             throw new CanonicalizationException("empty", ex);
  94         } 
  95     }
  96 }