Procházet zdrojové kódy

Modified to use SAXParserFactory instead of loading class by name.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195772 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Oleg Tkachenko před 21 roky
rodič
revize
7dfa6f28c1
1 změnil soubory, kde provedl 16 přidání a 25 odebrání
  1. 16
    25
      src/org/apache/fop/apps/InputHandler.java

+ 16
- 25
src/org/apache/fop/apps/InputHandler.java Zobrazit soubor

@@ -10,27 +10,27 @@ package org.apache.fop.apps;
// SAX
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;

// Java
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.net.URL;
import java.io.File;

public abstract class InputHandler {


public abstract InputSource getInputSource();
public abstract XMLReader getParser() throws FOPException;


public static InputSource urlInputSource(URL url) {
return new InputSource(url.toString());
}

/**
* create an InputSource from a File
*
* @param file the File
* @return the InputSource created
* Creates an <code>InputSource</code> from a <code>File</code>
* @param file the <code>File</code>
* @return the <code>InputSource</code> created
*/
public static InputSource fileInputSource(File file) {
/* this code adapted from James Clark's in XT */
@@ -50,29 +50,20 @@ public abstract class InputHandler {
}

/**
* creates a SAX parser, using the value of org.xml.sax.parser
* defaulting to org.apache.xerces.parsers.SAXParser
*
* @return the created SAX parser
* Creates <code>XMLReader</code> object using default
* <code>SAXParserFactory</code>
* @return the created <code>XMLReader</code>
*/
protected static XMLReader createParser() throws FOPException {
String parserClassName = Driver.getParserClassName();
//log.debug("using SAX parser " + parserClassName);

try {
return (XMLReader)Class.forName(parserClassName).newInstance();
} catch (ClassNotFoundException e) {
throw new FOPException(e);
} catch (InstantiationException e) {
throw new FOPException("Could not instantiate "
+ parserClassName, e);
} catch (IllegalAccessException e) {
throw new FOPException("Could not access " + parserClassName, e);
} catch (ClassCastException e) {
throw new FOPException(parserClassName + " is not a SAX driver",
e);
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
return factory.newSAXParser().getXMLReader();
} catch (SAXException se) {
throw new FOPException("Coudn't create XMLReader", se);
} catch (ParserConfigurationException pce) {
throw new FOPException("Coudn't create XMLReader", pce);
}
}

}


Načítá se…
Zrušit
Uložit