1 3 import org.faceless.report.*; 4 import org.faceless.pdf2.*; 5 import org.xml.sax.*; 6 import org.xml.sax.helpers.*; 7 import java.io.*; 8 import java.util.*; 9 10 public class SampleTransformer 28 { 29 static final String readerclass = "org.apache.crimson.parser.XMLReaderImpl"; 30 32 public static void main(String [] args) throws SAXException, IOException 33 { 34 XMLReader reader = XMLReaderFactory.createXMLReader(readerclass); 38 TagRemapFilter filter = new TagRemapFilter(reader); 39 filter.setRemap("html", "pdf"); 40 41 ReportParser parser = ReportParser.getInstance(); 44 PDF pdf = parser.parse(filter, new InputSource(args[0])); 45 46 pdf.render(new FileOutputStream("transformed.pdf")); 49 } 50 51 52 58 public static class TagRemapFilter extends XMLFilterImpl 59 { 60 private Map remap; 61 62 66 public TagRemapFilter(XMLReader parent) 67 { 68 super(parent); 69 remap = new HashMap(); 70 } 71 72 77 public void setRemap(String from, String to) 78 { 79 remap.put(from, to); 80 } 81 82 public void startElement(String uri, String local, String qname, Attributes atts) 83 throws SAXException 84 { 85 System.err.println(uri+","+local+","+qname); 86 String to; 87 to = (String )remap.get(local); if (to!=null) local=to; 88 to = (String )remap.get(qname); if (to!=null) qname=to; 89 super.startElement(uri, local, qname, atts); 90 } 91 92 public void endElement(String uri, String local, String qname) 93 throws SAXException 94 { 95 String to; 96 to = (String )remap.get(local); if (to!=null) local=to; 97 to = (String )remap.get(qname); if (to!=null) qname=to; 98 super.endElement(uri, local, qname); 99 } 100 } 101 } 102 | Popular Tags |