1 58 package org.krysalis.barcode.xalan; 59 60 import java.io.File ; 61 import java.io.StringWriter ; 62 63 import javax.xml.transform.Result ; 64 import javax.xml.transform.Source ; 65 import javax.xml.transform.Transformer ; 66 import javax.xml.transform.TransformerFactory ; 67 import javax.xml.transform.sax.SAXResult ; 68 import javax.xml.transform.stream.StreamResult ; 69 import javax.xml.transform.stream.StreamSource ; 70 71 import org.xml.sax.SAXException ; 72 import org.xml.sax.helpers.DefaultHandler ; 73 74 import org.krysalis.barcode.AbstractBarcodeTestCase; 75 76 import org.apache.xalan.processor.TransformerFactoryImpl; 77 78 83 public class XalanExtTest extends AbstractBarcodeTestCase { 84 85 public XalanExtTest(String name) { 86 super(name); 87 } 88 89 public void testXalanExtGenerate() throws Exception { 90 innerXalanExt("xalan-test1.xsl"); 91 } 92 93 public void testXalanExtBarcodeElement() throws Exception { 94 innerXalanExt("xalan-test2.xsl"); 95 } 96 97 public void innerXalanExt(String xslt) throws Exception { 98 TransformerFactory factory = new TransformerFactoryImpl(); 99 Transformer trans = factory.newTransformer(new StreamSource ( 100 new File (getBaseDir(), "src/test/xml/" + xslt))); 101 Source src = new StreamSource ( 102 new File (getBaseDir(), "src/test/xml/xslt-test.xml")); 103 StringWriter writer = new StringWriter (); 104 Result res = new StreamResult (writer); 105 106 trans.transform(src, res); 107 String output = writer.getBuffer().toString(); 108 assertTrue(output.indexOf("svg") >= 0); 109 } 111 112 public void testXalanExtSAXOutputGenerate() throws Exception { 113 innerXalanExtSAXOutput("xalan-test1.xsl"); 114 } 115 116 public void testXalanExtSAXOutputBarcodeElement() throws Exception { 117 System.out.println("Skipping test for Xalan barcode element extension because of Xalan bug #24220"); 119 } 120 121 124 public void innerXalanExtSAXOutput(String xslt) throws Exception { 125 TransformerFactory factory = new TransformerFactoryImpl(); 126 Transformer trans = factory.newTransformer(new StreamSource ( 127 new File (getBaseDir(), "src/test/xml/" +xslt))); 128 Source src = new StreamSource ( 129 new File (getBaseDir(), "src/test/xml/xslt-test.xml")); 130 Result res = new SAXResult (new DefaultHandler () { 131 private boolean endDocumentCalled = false; 132 133 public void endDocument() throws SAXException { 134 if (!this.endDocumentCalled) { 135 this.endDocumentCalled = true; 136 } else throw new SAXException ("endDocument() called twice"); 137 } 138 }); 139 trans.transform(src, res); 140 } 141 142 } 143 | Popular Tags |