Search in sources :

Example 86 with StreamSource

use of javax.xml.transform.stream.StreamSource in project jdk8u_jdk by JetBrains.

the class NamespacePrefixTest method testReuseTemplates.

@Test
public void testReuseTemplates() throws Exception {
    final TransformerFactory tf = TransformerFactory.newInstance();
    final Source xslsrc = new StreamSource(new StringReader(XSL));
    final Templates tmpl = tf.newTemplates(xslsrc);
    for (int i = 0; i < TRANSF_COUNT; i++) {
        checkResult(doTransformation(tmpl.newTransformer()));
    }
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Templates(javax.xml.transform.Templates) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.testng.annotations.Test)

Example 87 with StreamSource

use of javax.xml.transform.stream.StreamSource in project jdk8u_jdk by JetBrains.

the class TransformerTest method testBug8169112.

/**
     * @bug 8169112
     * @summary Test compilation of large xsl file with outlining.
     *
     * This test merely compiles a large xsl file and tests if its bytecode
     * passes verification by invoking the transform() method for
     * dummy content. The test succeeds if no Exception is thrown
     */
@Test
public final void testBug8169112() throws FileNotFoundException, TransformerException {
    TransformerFactory tf = TransformerFactory.newInstance();
    String xslFile = getClass().getResource("Bug8169112.xsl").toString();
    Transformer t = tf.newTransformer(new StreamSource(xslFile));
    String xmlIn = "<?xml version=\"1.0\"?><DOCROOT/>";
    ByteArrayInputStream bis = new ByteArrayInputStream(xmlIn.getBytes());
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    t.transform(new StreamSource(bis), new StreamResult(bos));
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 88 with StreamSource

use of javax.xml.transform.stream.StreamSource in project jdk8u_jdk by JetBrains.

the class FeaturePropagationTest method main.

public static void main(String[] args) throws Exception {
    InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
    StreamSource xsdSource = new StreamSource(reader);
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
    Schema schema = null;
    schema = schemaFactory.newSchema(xsdSource);
    Validator validator = schema.newValidator();
    if (validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) {
        throw new RuntimeException("Feature set on the factory is not inherited!");
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource)

Example 89 with StreamSource

use of javax.xml.transform.stream.StreamSource in project jdk8u_jdk by JetBrains.

the class TransformerTest method transformResourceToStringWriter.

private StringWriter transformResourceToStringWriter(Transformer transformer, String xmlResource) throws TransformerException {
    StringWriter sw = new StringWriter();
    transformer.transform(new StreamSource(getClass().getResource(xmlResource).toString()), new StreamResult(sw));
    return sw;
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource)

Example 90 with StreamSource

use of javax.xml.transform.stream.StreamSource in project jdk8u_jdk by JetBrains.

the class TransformerTest method transformInputStreamToDocument.

private Document transformInputStreamToDocument(Transformer transformer, InputStream sourceStream) throws TransformerException {
    DOMResult response = new DOMResult();
    transformer.transform(new StreamSource(sourceStream), response);
    return (Document) response.getNode();
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) StreamSource(javax.xml.transform.stream.StreamSource) Document(org.w3c.dom.Document)

Aggregations

StreamSource (javax.xml.transform.stream.StreamSource)338 Source (javax.xml.transform.Source)115 StringReader (java.io.StringReader)101 StreamResult (javax.xml.transform.stream.StreamResult)85 Transformer (javax.xml.transform.Transformer)74 Test (org.junit.Test)73 InputStream (java.io.InputStream)68 TransformerFactory (javax.xml.transform.TransformerFactory)58 ByteArrayInputStream (java.io.ByteArrayInputStream)56 IOException (java.io.IOException)52 DOMSource (javax.xml.transform.dom.DOMSource)49 TransformerException (javax.xml.transform.TransformerException)48 StringWriter (java.io.StringWriter)45 SchemaFactory (javax.xml.validation.SchemaFactory)44 InputSource (org.xml.sax.InputSource)44 Schema (javax.xml.validation.Schema)43 SAXException (org.xml.sax.SAXException)42 SAXSource (javax.xml.transform.sax.SAXSource)33 Validator (javax.xml.validation.Validator)31 File (java.io.File)27