use of javax.xml.transform.Source in project jdk8u_jdk by JetBrains.
the class BooleanAttributes method test.
public static void test(String mimeType, boolean useStreamMeta, String metaXml, String... boolXpaths) throws Exception {
BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType(mimeType).next();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
iw.setOutput(ios);
ImageWriteParam param = null;
IIOMetadata streamMeta = iw.getDefaultStreamMetadata(param);
IIOMetadata imageMeta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), param);
IIOMetadata meta = useStreamMeta ? streamMeta : imageMeta;
Source src = new StreamSource(new StringReader(metaXml));
DOMResult dst = new DOMResult();
transform(src, dst);
Document doc = (Document) dst.getNode();
Element node = doc.getDocumentElement();
String metaFormat = node.getNodeName();
// Verify that the default metadata gets formatted correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, false);
meta.mergeTree(metaFormat, node);
// Verify that the merged metadata gets formatte correctly.
verify(meta.getAsTree(metaFormat), boolXpaths, true);
iw.write(streamMeta, new IIOImage(img, null, imageMeta), param);
iw.dispose();
ios.close();
ImageReader ir = ImageIO.getImageReader(iw);
byte[] bytes = os.toByteArray();
if (bytes.length == 0)
throw new AssertionError("Zero length image file");
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
ImageInputStream iis = new MemoryCacheImageInputStream(is);
ir.setInput(iis);
if (useStreamMeta)
meta = ir.getStreamMetadata();
else
meta = ir.getImageMetadata(0);
// Verify again after writing and re-reading the image
verify(meta.getAsTree(metaFormat), boolXpaths, true);
}
use of javax.xml.transform.Source in project jdk8u_jdk by JetBrains.
the class NamespacePrefixTest method testConcurrentTransformations.
@Test
public void testConcurrentTransformations() throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new StringReader(XSL));
final Templates tmpl = tf.newTemplates(xslsrc);
concurrentTestPassed.set(true);
// Execute multiple TestWorker tasks
for (int id = 0; id < THREADS_COUNT; id++) {
EXECUTOR.execute(new TransformerThread(tmpl.newTransformer(), id));
}
// Initiate shutdown of previously submitted task
EXECUTOR.shutdown();
// Wait for termination of submitted tasks
if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
// If not all tasks terminates during the time out force them to shutdown
EXECUTOR.shutdownNow();
}
// Check if all transformation threads generated the correct namespace prefix
assertTrue(concurrentTestPassed.get());
}
use of javax.xml.transform.Source in project jdk8u_jdk by JetBrains.
the class NamespacePrefixTest method testReuseTransformer.
@Test
public void testReuseTransformer() throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new StringReader(XSL));
final Transformer t = tf.newTransformer(xslsrc);
for (int i = 0; i < TRANSF_COUNT; i++) {
checkResult(doTransformation(t));
}
}
use of javax.xml.transform.Source 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()));
}
}
use of javax.xml.transform.Source in project jdk8u_jdk by JetBrains.
the class XPathNegativeZero method xform.
private static String xform(final String xml, final String xsl) throws Exception {
final TransformerFactory tf = TransformerFactory.newInstance();
final Source xslsrc = new StreamSource(new File(xsl));
final Templates tmpl = tf.newTemplates(xslsrc);
final Transformer t = tmpl.newTransformer();
StringWriter writer = new StringWriter();
final Source src = new StreamSource(new File(xml));
final Result res = new StreamResult(writer);
t.transform(src, res);
return writer.toString();
}
Aggregations