git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@193884 13f79535-47bb-0310-9956-ffa450edef68tags/pre-columns
@@ -71,6 +71,7 @@ import java.io.InputStream; | |||
// FOP | |||
import org.apache.fop.messaging.MessageHandler; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
* mainline class. | |||
@@ -85,6 +86,7 @@ public class CommandLine { | |||
private String pdfFile = null; | |||
private String userConfigFile = null; | |||
private String baseDir = null; | |||
private boolean dumpConfiguration = false; | |||
/** show a full dump on error */ | |||
private static boolean errorDump = false; | |||
@@ -93,7 +95,10 @@ public class CommandLine { | |||
for (int i = 0; i < args.length; i++) { | |||
if (args[i].equals("-d") || args[i].equals("--full-error-dump")) { | |||
errorDump = true; | |||
} else if ((args[i].charAt(0) == '-') && (args[i].charAt(1) == 'c')) { | |||
} else if (args[i].equals("-x")) { | |||
dumpConfiguration = true; | |||
} else if ((args[i].charAt(0) == '-') && | |||
(args[i].charAt(1) == 'c')) { | |||
userConfigFile = args[i].substring(2); | |||
} else if (args[i].charAt(0) == '-') { | |||
printUsage(args[i]); | |||
@@ -112,29 +117,32 @@ public class CommandLine { | |||
public void printUsage(String arg) { | |||
if (arg != null) { | |||
MessageHandler.errorln("Unkown argument: '"+arg + "'"); | |||
MessageHandler.errorln("Usage: java [-d] " + | |||
"[-cMyConfigFile] " + | |||
"org.apache.fop.apps.CommandLine " + "formatting-object-file pdf-file"); | |||
MessageHandler.errorln("Options:\n" + " -d or --full-error-dump Show stack traces upon error"); | |||
MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of default"); | |||
System.exit(1); | |||
} | |||
MessageHandler.errorln("Unknown argument: '"+arg + "'"); | |||
} | |||
MessageHandler.errorln("Usage: java [-d] [-x]" + | |||
"[-cMyConfigFile] \n" + | |||
" org.apache.fop.apps.CommandLine " + "formatting-object-file pdf-file"); | |||
MessageHandler.errorln("Options:\n" + " -d or --full-error-dump Show stack traces upon error"); | |||
MessageHandler.errorln(" -x dump configuration information"); | |||
MessageHandler.errorln(" -cMyConfigFile use configuration file MyConfigFile"); | |||
System.exit(1); | |||
} | |||
public void run() { | |||
Driver driver = new Driver(); | |||
if (errorDump) { | |||
Driver driver = new Driver(); | |||
if (errorDump) { | |||
driver.setErrorDump(true); | |||
} | |||
driver.loadStandardConfiguration("standard"); | |||
// driver.loadStandardConfiguration("pdf"); | |||
if (userConfigFile != null) { | |||
driver.loadUserconfiguration(userConfigFile,"standard"); | |||
if (userConfigFile != null) { | |||
driver.loadUserconfiguration(userConfigFile); | |||
} | |||
driver.setBaseDir(foFile); | |||
if (dumpConfiguration) { | |||
Configuration.dumpConfiguration(); | |||
System.exit(0); | |||
} | |||
String version = Version.getVersion(); | |||
MessageHandler.logln(version); | |||
@@ -181,11 +189,11 @@ public class CommandLine { | |||
/** | |||
* 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 a SAX parser, using the value of org.xml.sax.parser | |||
* defaulting to org.apache.xerces.parsers.SAXParser | |||
* | |||
* @return the created SAX parser | |||
*/ | |||
static XMLReader createParser() { | |||
String parserClassName = System.getProperty("org.xml.sax.parser"); | |||
if (parserClassName == null) { | |||
@@ -229,11 +237,11 @@ public class CommandLine { | |||
} | |||
/** | |||
* create an InputSource from a file name | |||
* | |||
* @param filename the name of the file | |||
* @return the InputSource created | |||
*/ | |||
* create an InputSource from a file name | |||
* | |||
* @param filename the name of the file | |||
* @return the InputSource created | |||
*/ | |||
public static InputSource fileInputSource(String filename) { | |||
/* this code adapted from James Clark's in XT */ | |||
@@ -252,13 +260,13 @@ public class CommandLine { | |||
} | |||
/** | |||
* mainline method | |||
* | |||
* first command line argument is input file | |||
* second command line argument is output file | |||
* | |||
* @param command line arguments | |||
*/ | |||
* mainline method | |||
* | |||
* first command line argument is input file | |||
* second command line argument is output file | |||
* | |||
* @param command line arguments | |||
*/ | |||
public static void main(String[] args) { | |||
CommandLine cmdLine = new CommandLine(args); | |||
cmdLine.run(); |
@@ -60,7 +60,7 @@ import org.apache.fop.layout.FontInfo; | |||
import org.apache.fop.render.Renderer; | |||
import org.apache.fop.messaging.MessageHandler; | |||
import org.apache.fop.configuration.ConfigurationReader; | |||
import org.apache.fop.configuration.StandardConfiguration; | |||
import org.apache.fop.configuration.Configuration; | |||
// DOM | |||
@@ -140,11 +140,12 @@ public class Driver { | |||
/** create a new Driver */ | |||
public Driver() { | |||
this.treeBuilder = new FOTreeBuilder(); | |||
this.loadStandardConfiguration(); | |||
} | |||
/** Set the error dump option | |||
* @param dump if true, full stacks will be reported to the error log | |||
*/ | |||
* @param dump if true, full stacks will be reported to the error log | |||
*/ | |||
public void setErrorDump(boolean dump) { | |||
errorDump = dump; | |||
} | |||
@@ -155,18 +156,18 @@ public class Driver { | |||
} | |||
/** | |||
* set the class name of the Renderer to use as well as the | |||
* producer string for those renderers that can make use of it | |||
*/ | |||
* set the class name of the Renderer to use as well as the | |||
* producer string for those renderers that can make use of it | |||
*/ | |||
public void setRenderer(String rendererClassName, String producer) { | |||
this.renderer = createRenderer(rendererClassName); | |||
this.renderer.setProducer(producer); | |||
} | |||
/** | |||
* protected method used by setRenderer(String, String) to | |||
* instantiate the Renderer class | |||
*/ | |||
* protected method used by setRenderer(String, String) to | |||
* instantiate the Renderer class | |||
*/ | |||
protected Renderer createRenderer(String rendererClassName) { | |||
MessageHandler.logln("using renderer " + rendererClassName); | |||
@@ -190,26 +191,26 @@ public class Driver { | |||
} | |||
/** | |||
* add the given element mapping. | |||
* | |||
* an element mapping maps element names to Java classes | |||
*/ | |||
* add the given element mapping. | |||
* | |||
* an element mapping maps element names to Java classes | |||
*/ | |||
public void addElementMapping(ElementMapping mapping) { | |||
mapping.addToBuilder(this.treeBuilder); | |||
} | |||
/** | |||
* add the element mapping with the given class name | |||
*/ | |||
* add the element mapping with the given class name | |||
*/ | |||
public void addElementMapping(String mappingClassName) { | |||
createElementMapping(mappingClassName).addToBuilder( | |||
this.treeBuilder); | |||
} | |||
/** | |||
* protected method used by addElementMapping(String) to | |||
* instantiate element mapping class | |||
*/ | |||
* protected method used by addElementMapping(String) to | |||
* instantiate element mapping class | |||
*/ | |||
protected ElementMapping createElementMapping( | |||
String mappingClassName) { | |||
MessageHandler.logln("using element mapping " + mappingClassName); | |||
@@ -238,16 +239,16 @@ public class Driver { | |||
} | |||
/** | |||
* add the element mapping with the given class name | |||
*/ | |||
* add the element mapping with the given class name | |||
*/ | |||
public void addPropertyList(String listClassName) { | |||
createPropertyList(listClassName).addToBuilder(this.treeBuilder); | |||
} | |||
/** | |||
* protected method used by addPropertyList(String) to | |||
* instantiate list mapping class | |||
*/ | |||
* protected method used by addPropertyList(String) to | |||
* instantiate list mapping class | |||
*/ | |||
protected PropertyListMapping createPropertyList( | |||
String listClassName) { | |||
MessageHandler.logln("using property list mapping " + | |||
@@ -277,20 +278,20 @@ public class Driver { | |||
} | |||
/** | |||
* return the tree builder (a SAX ContentHandler). | |||
* | |||
* used in situations where SAX is used but not via a FOP-invoked | |||
* SAX parser. A good example is an XSLT engine that fires SAX | |||
* events but isn't a SAX Parser itself. | |||
*/ | |||
* return the tree builder (a SAX ContentHandler). | |||
* | |||
* used in situations where SAX is used but not via a FOP-invoked | |||
* SAX parser. A good example is an XSLT engine that fires SAX | |||
* events but isn't a SAX Parser itself. | |||
*/ | |||
public ContentHandler getContentHandler() { | |||
return this.treeBuilder; | |||
} | |||
/** | |||
* build the formatting object tree using the given SAX Parser and | |||
* SAX InputSource | |||
*/ | |||
* build the formatting object tree using the given SAX Parser and | |||
* SAX InputSource | |||
*/ | |||
public void buildFOTree(XMLReader parser, | |||
InputSource source) throws FOPException { | |||
@@ -313,8 +314,8 @@ public class Driver { | |||
} | |||
/** | |||
* build the formatting object tree using the given DOM Document | |||
*/ | |||
* build the formatting object tree using the given DOM Document | |||
*/ | |||
public void buildFOTree(Document document) throws FOPException { | |||
/* most of this code is modified from John Cowan's */ | |||
@@ -342,7 +343,7 @@ public class Driver { | |||
int datalen = data.length(); | |||
if (array == null || array.length < datalen) { | |||
/* if the array isn't big enough, make a new | |||
one */ | |||
one */ | |||
array = new char[datalen]; | |||
} | |||
data.getChars(0, datalen, array, 0); | |||
@@ -404,8 +405,8 @@ public class Driver { | |||
} | |||
/** | |||
* Dumps an error | |||
*/ | |||
* Dumps an error | |||
*/ | |||
public void dumpError(Exception e) { | |||
if (errorDump) { | |||
if (e instanceof SAXException) { | |||
@@ -422,16 +423,16 @@ public class Driver { | |||
/** | |||
* set the PrintWriter to use to output the result of the Renderer | |||
* (if applicable) | |||
*/ | |||
* set the PrintWriter to use to output the result of the Renderer | |||
* (if applicable) | |||
*/ | |||
public void setWriter(PrintWriter writer) { | |||
this.writer = writer; | |||
} | |||
/** | |||
* format the formatting object tree into an area tree | |||
*/ | |||
* format the formatting object tree into an area tree | |||
*/ | |||
public void format() throws FOPException { | |||
FontInfo fontInfo = new FontInfo(); | |||
this.renderer.setupFontInfo(fontInfo); | |||
@@ -443,31 +444,22 @@ public class Driver { | |||
} | |||
/** | |||
* render the area tree to the output form | |||
*/ | |||
* render the area tree to the output form | |||
*/ | |||
public void render() throws IOException, FOPException { | |||
this.renderer.render(areaTree, this.writer); | |||
} | |||
/** | |||
* loads standard configuration file and a user file, if it has been specified | |||
*/ | |||
public void loadStandardConfiguration(String role) { | |||
String file; | |||
if (role.equals("standard")) { | |||
file = "config.xml"; | |||
} else if (role.equals("pdf")) { | |||
file = "pdf.xml"; | |||
} else if (role.equals("awt")) { | |||
file = "awt.xml"; | |||
} else { | |||
MessageHandler.errorln("Error: unknown configuration role: " + role | |||
+ "\n using standard"); | |||
file = "config.xml"; | |||
} | |||
* loads standard configuration file and a user file, if it has been specified | |||
*/ | |||
public void loadStandardConfiguration() { | |||
String file = "config.xml"; | |||
// the entry /conf/config.xml refers to a directory conf which is a sibling of org | |||
InputStream configfile = | |||
ConfigurationReader.class.getResourceAsStream("/conf/"+file); | |||
ConfigurationReader.class.getResourceAsStream("/conf/"+ | |||
file); | |||
if (configfile == null) { | |||
MessageHandler.errorln("Fatal error: can't find default configuration file"); | |||
System.exit(1); | |||
@@ -476,8 +468,7 @@ public class Driver { | |||
MessageHandler.logln("reading default configuration file"); | |||
} | |||
ConfigurationReader reader = | |||
new ConfigurationReader (new InputSource(configfile), | |||
"standard"); | |||
new ConfigurationReader (new InputSource(configfile)); | |||
if (errorDump) { | |||
reader.setDumpError(true); | |||
} | |||
@@ -492,12 +483,12 @@ public class Driver { | |||
} | |||
} | |||
public void loadUserconfiguration(String userConfigFile, String role) { | |||
public void loadUserconfiguration(String userConfigFile) { | |||
//read user configuration file | |||
if (userConfigFile != null) { | |||
MessageHandler.logln("reading user configuration file"); | |||
ConfigurationReader reader = new ConfigurationReader ( | |||
CommandLine.fileInputSource(userConfigFile), role); | |||
CommandLine.fileInputSource(userConfigFile)); | |||
if (errorDump) { | |||
reader.setDumpError(true); | |||
} | |||
@@ -516,14 +507,15 @@ public class Driver { | |||
} | |||
public void setBaseDir(String fofile) { | |||
String baseDir = StandardConfiguration.getStringValue("baseDir"); | |||
if (baseDir == null) { | |||
baseDir = new File(new File(fofile).getAbsolutePath()).getParent(); | |||
StandardConfiguration.put("baseDir",baseDir); | |||
} | |||
if (errorDump) { | |||
MessageHandler.logln("base directory: " + baseDir); | |||
} | |||
String baseDir = Configuration.getStringValue("baseDir"); | |||
if (baseDir == null) { | |||
baseDir = new File( | |||
new File(fofile).getAbsolutePath()).getParent(); | |||
Configuration.put("baseDir",baseDir); | |||
} | |||
if (errorDump) { | |||
MessageHandler.logln("base directory: " + baseDir); | |||
} | |||
} | |||
@@ -51,7 +51,7 @@ | |||
package org.apache.fop.apps; | |||
import org.apache.fop.configuration.StandardConfiguration; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
* class representing the version of FOP. | |||
*/ | |||
@@ -63,6 +63,6 @@ public class Version { | |||
* @return the version string | |||
*/ | |||
public static String getVersion() { | |||
return StandardConfiguration.getStringValue("version"); | |||
return Configuration.getStringValue("version"); | |||
} | |||
} |
@@ -82,6 +82,7 @@ import org.apache.xalan.xslt.XSLTResultTarget; | |||
// FOP | |||
import org.apache.fop.messaging.MessageHandler; | |||
import org.apache.fop.configuration.ConfigurationReader; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
* mainline class. | |||
@@ -97,7 +98,7 @@ public class XalanCommandLine { | |||
private String xsltFile = null; | |||
private String userConfigFile = null; | |||
private String baseDir = null; | |||
private boolean dumpConfiguration = false; | |||
/** show a full dump on error */ //this should be implemented here too | |||
private static boolean errorDump = false; | |||
@@ -106,6 +107,8 @@ public class XalanCommandLine { | |||
for (int i = 0; i < args.length; i++) { | |||
if (args[i].equals("-d") || args[i].equals("--full-error-dump")) { | |||
errorDump = true; | |||
} else if (args[i].equals("-x")) { | |||
dumpConfiguration = true; | |||
} else if ((args[i].charAt(0) == '-') && | |||
(args[i].charAt(1) == 'c')) { | |||
userConfigFile = args[i].substring(2); | |||
@@ -133,14 +136,15 @@ public class XalanCommandLine { | |||
public void printUsage(String arg) { | |||
if (arg != null) { | |||
MessageHandler.errorln("Unkown argument: '"+ arg + "'"); | |||
MessageHandler.errorln("Usage: java [-d] " + | |||
"[-cMyConfigFile] " + | |||
"org.apache.fop.apps.XalanCommandLine " + "xml-file xslt-file pdf-file"); | |||
MessageHandler.errorln("Options:\n" + " -d or --full-error-dump Show stack traces upon error"); | |||
MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of/additional to default"); | |||
System.exit(1); | |||
} | |||
} | |||
MessageHandler.errorln("Usage: java [-d] [-x]" + | |||
"[-cMyConfigFile] " + | |||
"org.apache.fop.apps.XalanCommandLine " + "xml-file xslt-file pdf-file"); | |||
MessageHandler.errorln("Options:\n" + " -d or --full-error-dump Show stack traces upon error"); | |||
MessageHandler.errorln(" -x dump configuration information"); | |||
MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of/additional to default"); | |||
System.exit(1); | |||
} | |||
/** | |||
@@ -217,10 +221,14 @@ public class XalanCommandLine { | |||
if (errorDump) { | |||
driver.setErrorDump(true); | |||
} | |||
driver.loadStandardConfiguration("standard"); | |||
if (userConfigFile != null) { | |||
driver.loadUserconfiguration(userConfigFile, "standard"); | |||
driver.loadUserconfiguration(userConfigFile); | |||
} | |||
if (dumpConfiguration) { | |||
Configuration.dumpConfiguration(); | |||
System.exit(0); | |||
} | |||
driver.setBaseDir(foFile); | |||
String version = Version.getVersion(); | |||
MessageHandler.logln(version); |
@@ -1,141 +0,0 @@ | |||
package org.apache.fop.configuration; | |||
import java.util.Vector; | |||
import java.util.Hashtable; | |||
import java.util.Enumeration; | |||
public class AWTConfiguration { | |||
/** stores the configuration information */ | |||
private static Hashtable configuration; | |||
/** | |||
* general access method | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return Object containing the value; normally you would use one of the | |||
* convenience methods, which return the correct form. | |||
* null if the key is not defined. | |||
*/ | |||
public static Object getValue (String key){ | |||
return configuration.get(key); | |||
}; | |||
/** | |||
* convenience methods to access strings values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return String a string containing the value | |||
* null if the key is not defined. | |||
*/ | |||
public static String getStringValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
return (String) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access int values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return int a int containing the value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static int getIntValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
return Integer.parseInt((String) obj); | |||
} else { | |||
return -1; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access list values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return Vector a Vector containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Vector getListValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof Vector) { | |||
return (Vector) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access map/hashtable values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return Hashtable a Hashtable containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Hashtable getHashtableValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof Hashtable) { | |||
return (Hashtable) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* adds information to the configuration map/hashtable in key,value form | |||
* @param key a string containing the key value for the configuration value | |||
* @param value an Object containing the value; can be a String, a Vector or a Hashtable | |||
*/ | |||
public static void put(String key,Object value){ | |||
configuration.put(key,value); | |||
}; | |||
/** | |||
* debug methods, which writes out all information in this configuration | |||
*/ | |||
public static void dumpConfiguration() { | |||
String key; | |||
Object value; | |||
Vector list; | |||
Hashtable map; | |||
Enumeration enum; | |||
String tmp; | |||
System.out.println("Dumping standard configuration: "); | |||
Enumeration enumeration = configuration.keys(); | |||
while (enumeration.hasMoreElements()) { | |||
key = (String) enumeration.nextElement(); | |||
System.out.print(" key: " + key); | |||
value = configuration.get(key); | |||
if (value instanceof String) { | |||
System.out.println(" value: " + value); | |||
} else if (value instanceof Vector) { | |||
list = (Vector) value; | |||
enum = list.elements(); | |||
System.out.print(" value: "); | |||
while (enum.hasMoreElements()) { | |||
System.out.print( enum.nextElement() + " - "); | |||
} | |||
System.out.println(""); | |||
} else if (value instanceof Hashtable) { | |||
map = (Hashtable) value; | |||
enum = map.keys(); | |||
while (enum.hasMoreElements()) { | |||
tmp = (String) enum.nextElement(); | |||
System.out.print(" " + tmp + ":" + map.get(tmp)); | |||
} | |||
System.out.println(""); | |||
} | |||
} | |||
} | |||
/** | |||
* initializes this configuration | |||
* @param config contains the configuration information | |||
*/ | |||
public static void setup(Hashtable config){ | |||
configuration = config; | |||
} | |||
} |
@@ -0,0 +1,313 @@ | |||
package org.apache.fop.configuration; | |||
import java.util.Vector; | |||
import java.util.Hashtable; | |||
import java.util.Enumeration; | |||
import org.apache.fop.messaging.MessageHandler; | |||
/** | |||
* a configuration class for all general configuration aspects except those | |||
* related to specific renderers. All configuration is stored | |||
* in key / value pairs. The value can be a String, a list of Strings | |||
* or a map, containing a list of key / value pairs. | |||
* | |||
*/ | |||
public class Configuration { | |||
/** stores the configuration information */ | |||
private static Hashtable standardConfiguration; | |||
private static Hashtable pdfConfiguration; | |||
private static Hashtable awtConfiguration; | |||
/** defines role types */ | |||
public final static int STANDARD = 0; | |||
public final static int PDF = 1; | |||
public final static int AWT = 2; | |||
/** | |||
* general access method | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* role detemines the configuration target | |||
* @return Object containing the value; normally you would use one of the | |||
* convenience methods, which return the correct form. | |||
* null if the key is not defined. | |||
*/ | |||
public static Object getValue (String key, int role) { | |||
switch (role) { | |||
case Configuration.STANDARD: | |||
return standardConfiguration.get(key); | |||
case Configuration.PDF: | |||
return pdfConfiguration.get(key); | |||
case Configuration.AWT: | |||
return awtConfiguration.get(key); | |||
default: | |||
return standardConfiguration.get(key); | |||
} | |||
}; | |||
/** | |||
* convenience methods to access strings values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* role detemines the configuration target | |||
* @return String a string containing the value | |||
* null if the key is not defined. | |||
*/ | |||
public static String getStringValue(String key, int role) { | |||
Object obj = Configuration.getValue (key, role); | |||
if (obj instanceof String) { | |||
return (String) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access int values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* role detemines the configuration target | |||
* @return int a int containing the value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static int getIntValue(String key, int role) { | |||
Object obj = Configuration.getValue (key, role); | |||
if (obj instanceof String) { | |||
return Integer.parseInt((String) obj); | |||
} else { | |||
return -1; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access boolean values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* role detemines the configuration target | |||
* @return boolean true or false as value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static Boolean getBooleanValue(String key, int role) { | |||
Object obj = Configuration.getValue (key, role); | |||
if (obj instanceof String) { | |||
String value = (String) obj; | |||
if (value.equals("true")) { | |||
return new Boolean(true); | |||
} else if (value.equals("false")) { | |||
return new Boolean(false); | |||
} else { | |||
return null; | |||
} | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access list values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* role detemines the configuration target | |||
* @return Vector a Vector containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Vector getListValue(String key, int role) { | |||
Object obj = Configuration.getValue (key, role); | |||
if (obj instanceof Vector) { | |||
return (Vector) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access map/hashtable values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* role detemines the configuration target | |||
* @return Hashtable a Hashtable containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Hashtable getHashtableValue(String key, int role) { | |||
Object obj = Configuration.getValue (key, role); | |||
if (obj instanceof Hashtable) { | |||
return (Hashtable) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience method which retrieves some configuration information | |||
* from the standard configuration | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return Object containing the value; normally you would use one of the | |||
* convenience methods, which return the correct form. | |||
* null if the key is not defined. | |||
*/ | |||
public static Object getValue (String key) { | |||
return Configuration.getValue(key, Configuration.STANDARD); | |||
} | |||
/** | |||
* convenience methods to access strings values in the standard configuration | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return String a string containing the value | |||
* null if the key is not defined. | |||
*/ | |||
public static String getStringValue(String key) { | |||
return Configuration.getStringValue(key, Configuration.STANDARD); | |||
} | |||
/** | |||
* convenience methods to access int values in the standard configuration | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return int a int containing the value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static int getIntValue(String key) { | |||
return Configuration.getIntValue(key, Configuration.STANDARD); | |||
} | |||
/** | |||
* convenience methods to access boolean values in the configuration | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return boolean true or false as value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static Boolean getBooleanValue(String key) { | |||
return Configuration.getBooleanValue(key, Configuration.STANDARD); | |||
} | |||
/** | |||
* convenience methods to access list values in the standard configuration | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return Vector a Vector containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Vector getListValue(String key) { | |||
return Configuration.getListValue(key, Configuration.STANDARD); | |||
} | |||
/** | |||
* convenience methods to access map/hashtable values in the standard configuration | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return Hashtable a Hashtable containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Hashtable getHashtableValue(String key) { | |||
return Configuration.getHashtableValue(key, Configuration.STANDARD); | |||
} | |||
/** | |||
* initializes this configuration | |||
* @param config contains the configuration information | |||
*/ | |||
public static void setup(int role, Hashtable config) { | |||
switch (role) { | |||
case Configuration.STANDARD: | |||
standardConfiguration = config; | |||
break; | |||
case Configuration.PDF: | |||
pdfConfiguration = config; | |||
break; | |||
case Configuration.AWT: | |||
awtConfiguration = config; | |||
break; | |||
default: | |||
MessageHandler.errorln("Can't setup configuration. Unknown configuration role/target"); | |||
} | |||
} | |||
/** | |||
* adds information to the configuration map/hashtable in key,value form | |||
* @param key a string containing the key value for the configuration value | |||
* value the configuration information | |||
* role detemines the configuration target | |||
* @param value an Object containing the value; can be a String, a Vector or a Hashtable | |||
*/ | |||
public static void put(String key, Object value, int role) { | |||
switch (role) { | |||
case Configuration.STANDARD: | |||
standardConfiguration.put(key, value); | |||
break; | |||
case Configuration.PDF: | |||
pdfConfiguration.put(key, value); | |||
break; | |||
case Configuration.AWT: | |||
awtConfiguration.put(key, value); | |||
break; | |||
default: | |||
standardConfiguration.put(key, value); | |||
MessageHandler.errorln( | |||
"Unknown role for new configuration entry. " + | |||
"Putting key:" + key + " - value:" + value + " into standard configuration."); | |||
} | |||
}; | |||
/** | |||
* adds information to the standard configuration map/hashtable in key,value form | |||
* @param key a string containing the key value for the configuration value | |||
* value the configuration information | |||
* role detemines the configuration target | |||
* @param value an Object containing the value; can be a String, a Vector or a Hashtable | |||
*/ | |||
public static void put(String key, Object value) { | |||
Configuration.put(key, value, Configuration.STANDARD); | |||
} | |||
/** | |||
* debug methods, which writes out all information in this configuration | |||
*/ | |||
public static void dumpConfiguration() { | |||
String key; | |||
Object value; | |||
Vector list; | |||
Hashtable map, configuration; | |||
Enumeration enum; | |||
String tmp; | |||
System.out.println("Dumping configuration: "); | |||
Hashtable [] configs = {standardConfiguration, | |||
pdfConfiguration, awtConfiguration}; | |||
for (int i = 0; i < configs.length ; i++) { | |||
MessageHandler.logln("----------------------"); | |||
configuration = configs[i]; | |||
Enumeration enumeration = configuration.keys(); | |||
while (enumeration.hasMoreElements()) { | |||
key = (String) enumeration.nextElement(); | |||
MessageHandler.logln("key: " + key); | |||
value = configuration.get(key); | |||
if (value instanceof String) { | |||
MessageHandler.logln(" value: " + value); | |||
} else if (value instanceof Vector) { | |||
list = (Vector) value; | |||
enum = list.elements(); | |||
MessageHandler.log(" values: "); | |||
while (enum.hasMoreElements()) { | |||
MessageHandler.log(enum.nextElement() + " - "); | |||
} | |||
MessageHandler.logln(""); | |||
} else if (value instanceof Hashtable) { | |||
map = (Hashtable) value; | |||
enum = map.keys(); | |||
MessageHandler.log(" values: "); | |||
while (enum.hasMoreElements()) { | |||
tmp = (String) enum.nextElement(); | |||
MessageHandler.log(" " + tmp + ":" + map.get(tmp)); | |||
} | |||
MessageHandler.logln(""); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
@@ -81,8 +81,10 @@ public class ConfigurationParser extends DefaultHandler { | |||
private int status = OUT; | |||
private int datatype = -1; | |||
//stores the result configuration | |||
private static Hashtable configuration = new Hashtable(20); | |||
//store the result configuration | |||
private static Hashtable standardConfiguration = new Hashtable(30); | |||
private static Hashtable pdfConfiguration = new Hashtable(20); | |||
private static Hashtable awtConfiguration = new Hashtable(20); | |||
//stores key for new config entry | |||
private String key = ""; | |||
@@ -102,6 +104,8 @@ public class ConfigurationParser extends DefaultHandler { | |||
/** locator for line number information */ | |||
private Locator locator; | |||
/** determines role / target of configuration information, default is standard */ | |||
private int role = Configuration.STANDARD; | |||
/** get locator for position information */ | |||
public void setDocumentLocator(Locator locator) { | |||
@@ -121,8 +125,24 @@ public class ConfigurationParser extends DefaultHandler { | |||
status += IN_LIST; | |||
} else if (localName.equals("subentry")) { | |||
status += IN_SUBENTRY; | |||
} else if (localName.equals("configuration") || | |||
localName.equals("entry") || localName.equals("datatype")) { | |||
} else if (localName.equals("entry")) { | |||
if (attributes.getLength() == 0) { | |||
role = Configuration.STANDARD; | |||
} else { | |||
//retrieve attribute value for "role" which determines configuration target | |||
String rolen = attributes.getValue("role"); | |||
if (rolen.equalsIgnoreCase("pdf")) { | |||
role = Configuration.PDF; | |||
} else if (rolen.equalsIgnoreCase("awt")) { | |||
role = Configuration.AWT; | |||
} else if (rolen.equalsIgnoreCase("standard")) { | |||
role = Configuration.STANDARD; | |||
} else { | |||
MessageHandler.errorln("unknown role: " + rolen + ". Using standard."); | |||
} | |||
} | |||
//role=standard as default | |||
} else if (localName.equals("configuration") ) { | |||
} else { | |||
//to make sure that user knows about false tag | |||
MessageHandler.errorln( | |||
@@ -135,18 +155,18 @@ public class ConfigurationParser extends DefaultHandler { | |||
*/ | |||
public void endElement(String uri, String localName, String qName) { | |||
if (localName.equals("entry")) { | |||
int tek = 0; | |||
switch (datatype) { | |||
case STRING: | |||
configuration.put(key, value); | |||
this.store(role, key, value); | |||
break; | |||
case LIST: | |||
configuration.put(key, list); | |||
this.store(role, key, list); | |||
break; | |||
case MAP: | |||
configuration.put(key, map); | |||
this.store(role, key, map); | |||
} | |||
status = OUT; | |||
role = Configuration.STANDARD; | |||
} else if (localName.equals("subentry")) { | |||
map.put(subkey, value); | |||
status -= IN_SUBENTRY; | |||
@@ -157,7 +177,23 @@ public class ConfigurationParser extends DefaultHandler { | |||
} else if (localName.equals("value")) { | |||
status -= IN_VALUE; | |||
} | |||
} | |||
private void store (int role, String key, Object value) { | |||
switch (role) { | |||
case Configuration.STANDARD: | |||
standardConfiguration.put(key,value); | |||
break; | |||
case Configuration.PDF: | |||
pdfConfiguration.put(key,value); | |||
break; | |||
case Configuration.AWT: | |||
awtConfiguration.put(key,value); | |||
break; | |||
default: | |||
MessageHandler.errorln("Unknown role for new configuration entry. " | |||
+"Putting key:" + key + " - value:" + value +" into standard configuration."); | |||
} | |||
} | |||
/** | |||
@@ -195,8 +231,18 @@ public class ConfigurationParser extends DefaultHandler { | |||
* returns the parsed configuration information | |||
* @return Hashtable containing the configuration information as key/value pairs | |||
*/ | |||
public Hashtable getConfiguration() { | |||
return configuration; | |||
public Hashtable getConfiguration(int role) { | |||
switch (role) { | |||
case Configuration.STANDARD: | |||
return standardConfiguration; | |||
case Configuration.PDF: | |||
return pdfConfiguration; | |||
case Configuration.AWT: | |||
return awtConfiguration; | |||
default: | |||
MessageHandler.errorln("Can't return asked for configuration. Unknown role " ); | |||
return null; | |||
} | |||
} | |||
} |
@@ -61,9 +61,7 @@ import org.xml.sax.InputSource; | |||
//fop | |||
import org.apache.fop.messaging.MessageHandler; | |||
import org.apache.fop.apps.FOPException; | |||
import org.apache.fop.configuration.AWTConfiguration; | |||
import org.apache.fop.configuration.PDFConfiguration; | |||
import org.apache.fop.configuration.StandardConfiguration; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
* entry class for reading configuration from file and creating a configuration | |||
@@ -87,16 +85,13 @@ public class ConfigurationReader { | |||
/** inputsource for configuration file */ | |||
private InputSource filename; | |||
private String role ; | |||
/** | |||
* creates a configuration reader | |||
* @param filename the file which contains the configuration information | |||
* @param role three values are recognized: awt, pdf, standard | |||
*/ | |||
public ConfigurationReader (InputSource filename, String role) { | |||
public ConfigurationReader (InputSource filename) { | |||
this.filename = filename; | |||
this.role = role; | |||
} | |||
@@ -127,16 +122,9 @@ public class ConfigurationReader { | |||
try { | |||
parser.parse(filename); | |||
if (role.equalsIgnoreCase("standard")) { | |||
StandardConfiguration.setup( | |||
configurationParser.getConfiguration()); | |||
} else if (role.equalsIgnoreCase("pdf")) { | |||
PDFConfiguration.setup( | |||
configurationParser.getConfiguration()); | |||
} else if (role.equalsIgnoreCase("awt")) { | |||
AWTConfiguration.setup( | |||
configurationParser.getConfiguration()); | |||
} | |||
Configuration.setup(Configuration.STANDARD, configurationParser.getConfiguration(Configuration.STANDARD)); | |||
Configuration.setup(Configuration.PDF, configurationParser.getConfiguration(Configuration.PDF)); | |||
Configuration.setup(Configuration.AWT, configurationParser.getConfiguration(Configuration.AWT)); | |||
} catch (SAXException e) { | |||
if (e.getException() instanceof FOPException) { | |||
dumpError(e.getException()); | |||
@@ -221,7 +209,7 @@ public class ConfigurationReader { | |||
* | |||
*/ | |||
public void setDumpError(boolean dumpError) { | |||
this.errorDump = errorDump; | |||
errorDump = dumpError; | |||
} | |||
} |
@@ -1,147 +0,0 @@ | |||
package org.apache.fop.configuration; | |||
import java.util.Vector; | |||
import java.util.Hashtable; | |||
import java.util.Enumeration; | |||
/** | |||
* a configuration class for information related to the pdf renderer. All configuration is stored | |||
* in key / value pairs. The value can be a String, a list of Strings | |||
* or a map, containing a list of key / value pairs. | |||
* | |||
*/ | |||
public class PDFConfiguration { | |||
/** stores the configuration information */ | |||
private static Hashtable configuration; | |||
/** | |||
* general access method | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return Object containing the value; normally you would use one of the | |||
* convenience methods, which return the correct form. | |||
* null if the key is not defined. | |||
*/ | |||
public static Object getValue (String key){ | |||
return configuration.get(key); | |||
}; | |||
/** | |||
* convenience methods to access strings values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return String a string containing the value | |||
* null if the key is not defined. | |||
*/ | |||
public static String getStringValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
return (String) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access int values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return int a int containing the value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static int getIntValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
return Integer.parseInt((String) obj); | |||
} else { | |||
return -1; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access list values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return Vector a Vector containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Vector getListValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof Vector) { | |||
return (Vector) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access map/hashtable values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return Hashtable a Hashtable containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Hashtable getHashtableValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof Hashtable) { | |||
return (Hashtable) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* adds information to the configuration map/hashtable in key,value form | |||
* @param key a string containing the key value for the configuration value | |||
* @param value an Object containing the value; can be a String, a Vector or a Hashtable | |||
*/ | |||
public static void put(String key,Object value){ | |||
configuration.put(key,value); | |||
}; | |||
/** | |||
* debug methods, which writes out all information in this configuration | |||
*/ | |||
public static void dumpConfiguration() { | |||
String key; | |||
Object value; | |||
Vector list; | |||
Hashtable map; | |||
Enumeration enum; | |||
String tmp; | |||
System.out.println("Dumping standard configuration: "); | |||
Enumeration enumeration = configuration.keys(); | |||
while (enumeration.hasMoreElements()) { | |||
key = (String) enumeration.nextElement(); | |||
System.out.print(" key: " + key); | |||
value = configuration.get(key); | |||
if (value instanceof String) { | |||
System.out.println(" value: " + value); | |||
} else if (value instanceof Vector) { | |||
list = (Vector) value; | |||
enum = list.elements(); | |||
System.out.print(" value: "); | |||
while (enum.hasMoreElements()) { | |||
System.out.print( enum.nextElement() + " - "); | |||
} | |||
System.out.println(""); | |||
} else if (value instanceof Hashtable) { | |||
map = (Hashtable) value; | |||
enum = map.keys(); | |||
while (enum.hasMoreElements()) { | |||
tmp = (String) enum.nextElement(); | |||
System.out.print(" " + tmp + ":" + map.get(tmp)); | |||
} | |||
System.out.println(""); | |||
} | |||
} | |||
} | |||
/** | |||
* initializes this configuration | |||
* @param config contains the configuration information | |||
*/ | |||
public static void setup(Hashtable config){ | |||
configuration = config; | |||
} | |||
} |
@@ -1,171 +0,0 @@ | |||
package org.apache.fop.configuration; | |||
import java.util.Vector; | |||
import java.util.Hashtable; | |||
import java.util.Enumeration; | |||
/** | |||
* a configuration class for all general configuration aspects except those | |||
* related to specific renderers. All configuration is stored | |||
* in key / value pairs. The value can be a String, a list of Strings | |||
* or a map, containing a list of key / value pairs. | |||
* | |||
*/ | |||
public class StandardConfiguration { | |||
/** stores the configuration information */ | |||
private static Hashtable configuration; | |||
/** | |||
* general access method | |||
* | |||
* @param key a string containing the key value for the configuration value | |||
* @return Object containing the value; normally you would use one of the | |||
* convenience methods, which return the correct form. | |||
* null if the key is not defined. | |||
*/ | |||
public static Object getValue (String key){ | |||
return configuration.get(key); | |||
}; | |||
/** | |||
* convenience methods to access strings values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return String a string containing the value | |||
* null if the key is not defined. | |||
*/ | |||
public static String getStringValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
return (String) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access int values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return int a int containing the value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static int getIntValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
return Integer.parseInt((String) obj); | |||
} else { | |||
return -1; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access boolean values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return boolean true or false as value | |||
* -1 if the key is not defined. | |||
*/ | |||
public static Boolean getBooleanValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof String) { | |||
String value = (String) obj; | |||
if (value.equals("true")) { | |||
return new Boolean(true); | |||
} else if (value.equals("false")) { | |||
return new Boolean(false); | |||
} else { | |||
return null; | |||
} | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access list values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return Vector a Vector containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Vector getListValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof Vector) { | |||
return (Vector) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* convenience methods to access map/hashtable values in the configuration | |||
* @param key a string containing the key value for the configuration value | |||
* @return Hashtable a Hashtable containing the values | |||
* null if the key is not defined. | |||
*/ | |||
public static Hashtable getHashtableValue(String key){ | |||
Object obj = configuration.get(key); | |||
if (obj instanceof Hashtable) { | |||
return (Hashtable) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
* adds information to the configuration map/hashtable in key,value form | |||
* @param key a string containing the key value for the configuration value | |||
* @param value an Object containing the value; can be a String, a Vector or a Hashtable | |||
*/ | |||
public static void put(String key,Object value){ | |||
configuration.put(key,value); | |||
}; | |||
/** | |||
* debug methods, which writes out all information in this configuration | |||
*/ | |||
public static void dumpConfiguration() { | |||
String key; | |||
Object value; | |||
Vector list; | |||
Hashtable map; | |||
Enumeration enum; | |||
String tmp; | |||
System.out.println("Dumping standard configuration: "); | |||
Enumeration enumeration = configuration.keys(); | |||
while (enumeration.hasMoreElements()) { | |||
key = (String) enumeration.nextElement(); | |||
System.out.print(" key: " + key); | |||
value = configuration.get(key); | |||
if (value instanceof String) { | |||
System.out.println(" value: " + value); | |||
} else if (value instanceof Vector) { | |||
list = (Vector) value; | |||
enum = list.elements(); | |||
System.out.print(" value: "); | |||
while (enum.hasMoreElements()) { | |||
System.out.print( enum.nextElement() + " - "); | |||
} | |||
System.out.println(""); | |||
} else if (value instanceof Hashtable) { | |||
map = (Hashtable) value; | |||
enum = map.keys(); | |||
while (enum.hasMoreElements()) { | |||
tmp = (String) enum.nextElement(); | |||
System.out.print(" " + tmp + ":" + map.get(tmp)); | |||
} | |||
System.out.println(""); | |||
} | |||
} | |||
} | |||
/** | |||
* initializes this configuration | |||
* @param config contains the configuration information | |||
*/ | |||
public static void setup(Hashtable config){ | |||
configuration = config; | |||
} | |||
} | |||