1 47 48 package com.lowagie.text.xml; 49 50 51 import java.lang.reflect.Field; 52 import java.lang.reflect.Modifier; 53 import java.io.InputStream; 54 import java.io.OutputStream; 55 56 import com.lowagie.text.Document; 57 import com.lowagie.text.PageSize; 58 import com.lowagie.text.Rectangle; 59 import com.lowagie.text.DocumentException; 60 61 62 68 public abstract class XmlToXXX 69 { 70 71 protected Rectangle pageSize; 72 73 74 77 public XmlToXXX() 78 { 79 this(PageSize.LETTER); 80 } 82 83 88 public XmlToXXX(String pageSize) 89 { 90 this(getPageSize(pageSize)); 91 } 93 94 private XmlToXXX(Rectangle pageSize) 95 { 96 this.pageSize = pageSize; 97 } 99 100 107 public final void parse(InputStream in, OutputStream out) 108 throws DocumentException 109 { 110 Document doc = new Document(pageSize); 111 112 addWriter(doc, out); 113 XmlParser.parse(doc, in); 114 } 116 117 private static Rectangle getPageSize(String pageSize) 118 { 119 Rectangle result = PageSize.LETTER; 120 Field fld = null; 121 try 122 { 123 fld = PageSize.class.getDeclaredField(pageSize.toUpperCase()); 124 result = (fld != null 125 && Modifier.isStatic(fld.getModifiers()) 126 && fld.getType().equals(Rectangle.class)) ? (Rectangle)(fld.get(null)) 127 : result; 128 } catch (Exception ex) 130 { 131 System.err.println(ex.getMessage()); 132 } return result; 134 } 136 137 144 protected abstract void addWriter(Document doc, OutputStream out) 145 throws DocumentException; 146 147 } | Popular Tags |