1 51 package org.apache.fop.apps; 52 53 import org.xml.sax.InputSource ; 55 import org.xml.sax.XMLReader ; 56 57 import java.net.URL ; 59 import java.io.File ; 60 import javax.xml.parsers.*; 61 62 import org.apache.fop.messaging.MessageHandler; 64 65 abstract public class InputHandler { 66 67 abstract public InputSource getInputSource(); 68 abstract public XMLReader getParser() throws FOPException; 69 abstract public void run(Driver driver) throws FOPException; 70 71 72 static public InputSource urlInputSource(URL url) { 73 return new InputSource (url.toString()); 74 } 75 76 82 static public InputSource fileInputSource(File file) { 83 84 String path = file.getAbsolutePath(); 85 String fSep = System.getProperty("file.separator"); 86 if (fSep != null && fSep.length() == 1) 87 path = path.replace(fSep.charAt(0), '/'); 88 if (path.length() > 0 && path.charAt(0) != '/') 89 path = '/' + path; 90 try { 91 return new InputSource (new URL ("file", null, path).toString()); 92 } catch (java.net.MalformedURLException e) { 93 throw new Error ("unexpected MalformedURLException"); 94 } 95 } 96 97 102 protected static XMLReader createParser() throws FOPException { 103 try { 104 SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); 105 spf.setNamespaceAware(true); 106 XMLReader xmlReader = spf.newSAXParser().getXMLReader(); 107 MessageHandler.logln("Using " + xmlReader.getClass().getName() + " as SAX2 Parser"); 108 return xmlReader; 109 } catch (javax.xml.parsers.ParserConfigurationException e) { 110 throw new FOPException(e); 111 } catch (org.xml.sax.SAXException e) { 112 throw new FOPException( e); 113 } 114 } 115 116 } 117 118 | Popular Tags |