diff options
author | Keiron Liddle <keiron@apache.org> | 2001-07-12 13:03:39 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-07-12 13:03:39 +0000 |
commit | c21d7fce7a9130dddc219ded54b1ac2b20d68685 (patch) | |
tree | 85098837a409953825ca67a30d9aeef1d2dbbfd1 /src/org/apache/fop/apps | |
parent | 4f7b15971b532f85ab1b9831694d9f055b2e19f9 (diff) | |
download | xmlgraphics-fop-c21d7fce7a9130dddc219ded54b1ac2b20d68685.tar.gz xmlgraphics-fop-c21d7fce7a9130dddc219ded54b1ac2b20d68685.zip |
combined property list setting into element setting
also always get parser class name from one place
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194349 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/apps')
-rw-r--r-- | src/org/apache/fop/apps/Driver.java | 147 |
1 files changed, 95 insertions, 52 deletions
diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index 1d954f146..b263e2d99 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -9,7 +9,6 @@ package org.apache.fop.apps; // FOP import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.ElementMapping; -import org.apache.fop.fo.PropertyListMapping; import org.apache.fop.layout.AreaTree; import org.apache.fop.layout.FontInfo; import org.apache.fop.render.Renderer; @@ -136,6 +135,18 @@ public class Driver { /** the system resources that FOP will use */ private BufferManager _bufferManager; + public static final String getParserClassName() { + String parserClassName = null; + try { + parserClassName = System.getProperty("org.xml.sax.parser"); + } catch(SecurityException se) { + } + if (parserClassName == null) { + parserClassName = "org.apache.xerces.parsers.SAXParser"; + } + return parserClassName; + } + /** create a new Driver */ public Driver() { _stream = null; @@ -200,30 +211,24 @@ public class Driver { _reader = reader; } - /** * Sets all the element and property list mappings to their default values. * */ public void setupDefaultMappings() { addElementMapping("org.apache.fop.fo.StandardElementMapping"); - addPropertyList ("org.apache.fop.fo.StandardPropertyListMapping"); - addElementMapping("org.apache.fop.svg.SVGElementMapping"); - addPropertyList ("org.apache.fop.svg.SVGPropertyListMapping"); - addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); - addPropertyList ("org.apache.fop.extensions.ExtensionPropertyListMapping"); - // add mappings from user configuration - Hashtable mappings = Configuration.getHashtableValue("mappings"); - if (mappings != null) { - String prop = (String) mappings.get("property"); - String ele = (String) mappings.get("element"); - try { - addElementMapping(ele); - addPropertyList(prop); - } catch (IllegalArgumentException e) { + // add mappings from available services + Enumeration providers = Service.providers(org.apache.fop.fo.ElementMapping.class); + if (providers != null) { + while(providers.hasMoreElements()) { + String str = (String)providers.nextElement(); + try { + addElementMapping(str); + } catch (IllegalArgumentException e) { + } } } } @@ -271,7 +276,6 @@ public class Driver { } - /** * Set the Renderer to use * @param renderer the renderer instance to use @@ -361,41 +365,6 @@ public class Driver { } /** - * Add the PropertyListMapping. - */ - public void addPropertyList(PropertyListMapping mapping) { - mapping.addToBuilder(_treeBuilder); - } - - /** - * Add the PropertyListMapping with the given class name. - */ - public void addPropertyList(String listClassName) - throws IllegalArgumentException { - try { - PropertyListMapping mapping = - (PropertyListMapping) Class.forName( - listClassName).newInstance(); - addPropertyList(mapping); - - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Could not find " + - listClassName); - } - catch (InstantiationException e) { - throw new IllegalArgumentException( - "Could not instantiate " + listClassName); - } - catch (IllegalAccessException e) { - throw new IllegalArgumentException("Could not access " + - listClassName); - } - catch (ClassCastException e) { - throw new IllegalArgumentException(listClassName + " is not an ElementMapping"); - } - } - - /** * Returns the tree builder (a SAX ContentHandler). * * Used in situations where SAX is used but not via a FOP-invoked @@ -522,5 +491,79 @@ public class Driver { format(); render(); } +} + +// code stolen from org.apache.batik.util and modified slightly +// does what sun.misc.Service probably does, but it cannot be relied on. +// hopefully will be part of standard jdk sometime. +/** + * This class loads services present in the class path. + */ +class Service { + + static Hashtable providerMap = new Hashtable(); + public static synchronized Enumeration providers(Class cls) { + ClassLoader cl = cls.getClassLoader(); + String serviceFile = "META-INF/services/"+cls.getName(); + + // System.out.println("File: " + serviceFile); + + Vector v = (Vector)providerMap.get(serviceFile); + if (v != null) + return v.elements(); + + v = new Vector(); + providerMap.put(serviceFile, v); + + Enumeration e; + try { + e = cl.getResources(serviceFile); + } catch (IOException ioe) { + return v.elements(); + } + + while (e.hasMoreElements()) { + try { + java.net.URL u = (java.net.URL)e.nextElement(); + // System.out.println("URL: " + u); + + InputStream is = u.openStream(); + Reader r = new InputStreamReader(is, "UTF-8"); + BufferedReader br = new BufferedReader(r); + + String line = br.readLine(); + while (line != null) { + try { + // First strip any comment... + int idx = line.indexOf('#'); + if (idx != -1) + line = line.substring(0, idx); + + // Trim whitespace. + line = line.trim(); + + // If nothing left then loop around... + if (line.length() == 0) { + line = br.readLine(); + continue; + } + // System.out.println("Line: " + line); + + // Try and load the class + //Object obj = cl.loadClass(line).newInstance(); + // stick it into our vector... + v.add(line); + } catch (Exception ex) { + // Just try the next line + } + line = br.readLine(); + } + } catch (Exception ex) { + // Just try the next file... + } + } + return v.elements(); + } } + |