src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/c14n/Canonicalizer.java
changeset 59240 b3116877866f
parent 50614 3810c9a2efa1
equal deleted inserted replaced
59239:9fe5d0d4e9c5 59240:b3116877866f
    28 import java.nio.charset.StandardCharsets;
    28 import java.nio.charset.StandardCharsets;
    29 import java.util.Map;
    29 import java.util.Map;
    30 import java.util.Set;
    30 import java.util.Set;
    31 import java.util.concurrent.ConcurrentHashMap;
    31 import java.util.concurrent.ConcurrentHashMap;
    32 
    32 
    33 import javax.xml.parsers.DocumentBuilder;
       
    34 
       
    35 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_OmitComments;
    33 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_OmitComments;
    36 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_WithComments;
    34 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer11_WithComments;
    37 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
    35 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclOmitComments;
    38 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
    36 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
    39 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
    37 import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
   259         java.io.IOException, org.xml.sax.SAXException, CanonicalizationException {
   257         java.io.IOException, org.xml.sax.SAXException, CanonicalizationException {
   260         Document document = null;
   258         Document document = null;
   261         try (InputStream bais = new ByteArrayInputStream(inputBytes)) {
   259         try (InputStream bais = new ByteArrayInputStream(inputBytes)) {
   262             InputSource in = new InputSource(bais);
   260             InputSource in = new InputSource(bais);
   263 
   261 
   264             // needs to validate for ID attribute normalization
       
   265             DocumentBuilder db = XMLUtils.createDocumentBuilder(true, secureValidation);
       
   266 
       
   267             /*
   262             /*
   268              * for some of the test vectors from the specification,
       
   269              * there has to be a validating parser for ID attributes, default
       
   270              * attribute values, NMTOKENS, etc.
       
   271              * Unfortunately, the test vectors do use different DTDs or
       
   272              * even no DTD. So Xerces 1.3.1 fires many warnings about using
       
   273              * ErrorHandlers.
       
   274              *
       
   275              * Text from the spec:
   263              * Text from the spec:
   276              *
   264              *
   277              * The input octet stream MUST contain a well-formed XML document,
   265              * The input octet stream MUST contain a well-formed XML document,
   278              * but the input need not be validated. However, the attribute
   266              * but the input need not be validated. However, the attribute
   279              * value normalization and entity reference resolution MUST be
   267              * value normalization and entity reference resolution MUST be
   283              * in each element. Thus, the declarations in the document type
   271              * in each element. Thus, the declarations in the document type
   284              * declaration are used to help create the canonical form, even
   272              * declaration are used to help create the canonical form, even
   285              * though the document type declaration is not retained in the
   273              * though the document type declaration is not retained in the
   286              * canonical form.
   274              * canonical form.
   287              */
   275              */
   288             db.setErrorHandler(new com.sun.org.apache.xml.internal.security.utils.IgnoreAllErrorHandler());
   276             document = XMLUtils.read(in, secureValidation);
   289 
       
   290             document = db.parse(in);
       
   291         }
   277         }
   292         return this.canonicalizeSubtree(document);
   278         return this.canonicalizeSubtree(document);
   293     }
   279     }
   294 
   280 
   295     /**
   281     /**