1 51 package org.apache.fop.configuration; 52 53 import org.xml.sax.XMLReader ; 55 import org.xml.sax.SAXException ; 56 import org.xml.sax.InputSource ; 57 58 import java.io.IOException ; 60 import javax.xml.parsers.*; 61 62 import org.apache.fop.messaging.MessageHandler; 64 import org.apache.fop.apps.FOPException; 65 66 83 public class ConfigurationReader { 84 85 88 private static boolean errorDump = false; 89 90 93 private InputSource filename; 94 95 96 100 public ConfigurationReader(InputSource filename) { 101 this.filename = filename; 102 } 103 104 107 public void start() throws FOPException { 108 XMLReader parser = createParser(); 109 110 ConfigurationParser configurationParser = new ConfigurationParser(); 111 parser.setContentHandler(configurationParser); 112 113 try { 114 parser.parse(filename); 115 } catch (SAXException e) { 116 if (e.getException() instanceof FOPException) { 117 throw (FOPException)e.getException(); 118 } else { 119 throw new FOPException(e); 120 } 121 } catch (IOException e) { 122 throw new FOPException(e); 123 } 124 } 125 126 131 public static XMLReader createParser() throws FOPException { 132 try { 133 SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); 134 spf.setNamespaceAware(true); 135 XMLReader xmlReader = spf.newSAXParser().getXMLReader(); 136 MessageHandler.logln("Using " + xmlReader.getClass().getName() + " as SAX2 Parser"); 137 return xmlReader; 138 } catch (javax.xml.parsers.ParserConfigurationException e) { 139 throw new FOPException(e); 140 } catch (org.xml.sax.SAXException e) { 141 throw new FOPException( e); 142 } 143 } 144 145 148 public void dumpError(Exception e) { 149 if (errorDump) { 150 if (e instanceof SAXException ) { 151 e.printStackTrace(); 152 if (((SAXException )e).getException() != null) { 153 ((SAXException )e).getException().printStackTrace(); 154 } 155 } else { 156 e.printStackTrace(); 157 } 158 } 159 } 160 161 165 public void setDumpError(boolean dumpError) { 166 errorDump = dumpError; 167 } 168 169 } 170 | Popular Tags |