git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194080 13f79535-47bb-0310-9956-ffa450edef68tags/fop-0_18_1
@@ -1,54 +1,10 @@ | |||
/*-- $Id$ -- | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, are permitted provided that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "FOP" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
/* | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.apps; | |||
// FOP | |||
@@ -138,12 +94,11 @@ 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; | |||
} | |||
@@ -154,18 +109,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); | |||
@@ -189,26 +144,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); | |||
@@ -237,16 +192,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 " + | |||
@@ -276,20 +231,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 { | |||
@@ -312,8 +267,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 */ | |||
@@ -341,7 +296,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); | |||
@@ -403,8 +358,8 @@ public class Driver { | |||
} | |||
/** | |||
* Dumps an error | |||
*/ | |||
* Dumps an error | |||
*/ | |||
public void dumpError(Exception e) { | |||
if (errorDump) { | |||
if (e instanceof SAXException) { | |||
@@ -420,16 +375,16 @@ public class Driver { | |||
} | |||
/** | |||
* set the OutputStream to use to output the result of the Renderer | |||
* (if applicable) | |||
*/ | |||
* set the OutputStream to use to output the result of the Renderer | |||
* (if applicable) | |||
*/ | |||
public void setOutputStream(OutputStream stream) { | |||
this.stream = stream; | |||
} | |||
/** | |||
* 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); | |||
@@ -441,79 +396,11 @@ 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.stream); | |||
} | |||
/** | |||
* 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); | |||
if (configfile == null) { | |||
MessageHandler.errorln("Fatal error: can't find default configuration file"); | |||
System.exit(1); | |||
} | |||
if (errorDump) { | |||
MessageHandler.logln("reading default configuration file"); | |||
} | |||
ConfigurationReader reader = | |||
new ConfigurationReader (new InputSource(configfile)); | |||
if (errorDump) { | |||
reader.setDumpError(true); | |||
} | |||
try { | |||
reader.start(); | |||
} catch (org.apache.fop.apps.FOPException error) { | |||
MessageHandler.errorln("Fatal Error: Can't process default configuration file. \nProbably it is not well-formed."); | |||
if (errorDump) { | |||
reader.dumpError(error); | |||
} | |||
System.exit(1); | |||
} | |||
} | |||
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)); | |||
if (errorDump) { | |||
reader.setDumpError(true); | |||
} | |||
try { | |||
reader.start(); | |||
} catch (org.apache.fop.apps.FOPException error) { | |||
MessageHandler.errorln( | |||
"Can't find user configuration file " + | |||
userConfigFile); | |||
MessageHandler.errorln("using default values"); | |||
if (errorDump) { | |||
reader.dumpError(error); | |||
} | |||
} | |||
} | |||
} | |||
public void setBaseDir(String fofile) { | |||
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); | |||
} | |||
} | |||
} |
@@ -1,53 +1,9 @@ | |||
/*-- $Id$ -- | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, are permitted provided that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "Fop" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
/* | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.apps; | |||
/** | |||
@@ -61,6 +17,6 @@ public class FOPException extends Exception { | |||
* @param message descriptive message | |||
*/ | |||
public FOPException(String message) { | |||
super(message); | |||
super(message); | |||
} | |||
} |
@@ -1,58 +1,13 @@ | |||
/*-- $Id$ -- | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, are permitted provided that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "FOP" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
/* | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.apps; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
/** | |||
* class representing the version of FOP. | |||
*/ | |||
public class Version { |
@@ -1,3 +1,9 @@ | |||
/* | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.configuration; | |||
@@ -97,23 +103,18 @@ public class Configuration { | |||
* 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. | |||
* @return Boolean true or false as value | |||
* null 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; | |||
} | |||
if (obj instanceof String) { | |||
return new Boolean((String)obj); | |||
} else if (obj instanceof Boolean) { | |||
return (Boolean) obj; | |||
} else { | |||
return null; | |||
} | |||
}; | |||
/** | |||
@@ -189,7 +190,7 @@ public class 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. | |||
* null if the key is not defined. | |||
*/ | |||
public static Boolean getBooleanValue(String key) { | |||
return Configuration.getBooleanValue(key, Configuration.STANDARD); |
@@ -1,54 +1,10 @@ | |||
/* | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, are permitted provided that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "Fop" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
/* | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.configuration; | |||
import org.xml.sax.helpers.DefaultHandler; |
@@ -1,54 +1,10 @@ | |||
/* | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, are permitted provided that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "Fop" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
/* | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.configuration; | |||
//sax | |||
@@ -75,7 +31,7 @@ import org.apache.fop.configuration.Configuration; | |||
* } | |||
* </code> | |||
* Once the configuration has been setup, the information can be accessed with | |||
* the methods of StandardConfiguration. | |||
* the methods of Configuration. | |||
*/ | |||
public class ConfigurationReader { |
@@ -1,58 +1,15 @@ | |||
/* | |||
============================================================================ | |||
The Apache Software License, Version 1.1 | |||
============================================================================ | |||
Copyright (C) 1999 The Apache Software Foundation. All rights reserved. | |||
Redistribution and use in source and binary forms, with or without modifica- | |||
tion, are permitted provided that the following conditions are met: | |||
1. Redistributions of source code must retain the above copyright notice, | |||
this list of conditions and the following disclaimer. | |||
2. Redistributions in binary form must reproduce the above copyright notice, | |||
this list of conditions and the following disclaimer in the documentation | |||
and/or other materials provided with the distribution. | |||
3. The end-user documentation included with the redistribution, if any, must | |||
include the following acknowledgment: "This product includes software | |||
developed by the Apache Software Foundation (http://www.apache.org/)." | |||
Alternately, this acknowledgment may appear in the software itself, if | |||
and wherever such third-party acknowledgments normally appear. | |||
4. The names "Fop" and "Apache Software Foundation" must not be used to | |||
endorse or promote products derived from this software without prior | |||
written permission. For written permission, please contact | |||
apache@apache.org. | |||
5. Products derived from this software may not be called "Apache", nor may | |||
"Apache" appear in their name, without prior written permission of the | |||
Apache Software Foundation. | |||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |||
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |||
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- | |||
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |||
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
This software consists of voluntary contributions made by many individuals | |||
on behalf of the Apache Software Foundation and was originally created by | |||
James Tauber <jtauber@jtauber.com>. For more information on the Apache | |||
Software Foundation, please see <http://www.apache.org/>. | |||
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved. | |||
* For details on use and redistribution please refer to the | |||
* LICENSE file included with these sources." | |||
*/ | |||
package org.apache.fop.messaging; | |||
import java.io.*; | |||
import java.util.*; | |||
//import javax.swing.*; | |||
/** The class MessageHandler contains the static methods log and error which | |||
* should be used for any end user information instead of System.out.print() or | |||
@@ -61,20 +18,20 @@ import java.util.*; | |||
* output. If you don't want to change the default behaviour, you should be | |||
* happy with MessageHandler.log(message) and MessageHandler.error(message)<br> | |||
* The class MessageHandler also supports the setting of an id. If set every message | |||
* has as a prefix an identifying string. That way Fop probably can also be used in | |||
* environments, where more than one Fop instance are running in same JVM.<br> | |||
* If Fop is embedded in a gui application or for any reasons the existing | |||
* has as a prefix an identifying string. That way Fop probably can also be used in | |||
* environments, where more than one Fop instance are running in same JVM.<br> | |||
* If Fop is embedded in a gui application or for any reasons the existing | |||
* messaging system doesn't meet the programmer's requirements, one can add | |||
* a MessageEvent listener to MessageHandler and handle the incoming messages | |||
* in an appropriate way. See the class DefaultMessageListener, which is a trivial | |||
* implementation of the MessageListener. | |||
* a MessageEvent listener to MessageHandler and handle the incoming messages | |||
* in an appropriate way. See the class DefaultMessageListener, which is a trivial | |||
* implementation of the MessageListener. | |||
* Here is an example how to configure MessageHandler for the DefaultMessageListener (anybody | |||
* can provide his own listener by extending MessageListener<br> | |||
* <code> | |||
* MessageHandler.setOutputMethod(MessageHandler.EVENT); | |||
* MessageHandler.addListener(new DefaultMessageListener()); | |||
* </code><br> | |||
* This examples shows, how to redirect the messages to a log file called fop.log. | |||
* This examples shows, how to redirect the messages to a log file called fop.log. | |||
* All messages are appended to this file. | |||
* <code> | |||
* MessageHandler.setOutputMethod(MessageHandler.FILE); | |||
@@ -83,220 +40,238 @@ import java.util.*; | |||
*/ | |||
public class MessageHandler { | |||
public static final int SCREEN = 0; | |||
public static final int FILE = 1; | |||
public static final int EVENT = 2; | |||
public static final int NONE = 3; //this should always be the last method | |||
public static final int SCREEN = 0; | |||
public static final int FILE = 1; | |||
public static final int EVENT = 2; | |||
public static final int NONE = 3; //this should always be the last method | |||
private static String logfileName = "fop.log"; | |||
private static PrintWriter writer; | |||
private static int outputMethod = SCREEN; | |||
private static boolean fileOpened = false; | |||
private static boolean appendToFile = true; | |||
private static String message = ""; | |||
private static String prefix =""; | |||
private static Vector listeners = new Vector(); | |||
private static boolean IDisSet = false; | |||
/** | |||
* helper class to access the message | |||
* @return a string containing the message | |||
*/ | |||
private static String logfileName = "fop.log"; | |||
private static PrintWriter writer; | |||
private static int outputMethod = SCREEN; | |||
private static boolean fileOpened = false; | |||
private static boolean appendToFile = true; | |||
private static String message = ""; | |||
private static String prefix = ""; | |||
private static Vector listeners = new Vector(); | |||
private static boolean IDisSet = false; | |||
private static boolean quiet = false; | |||
private static String getMessage () { | |||
return message; | |||
} | |||
/** | |||
* helper class to access the message | |||
* @return a string containing the message | |||
*/ | |||
/** | |||
* helper class which sets the message | |||
* and adds a prefix which can contain | |||
* the id of the thread which uses this messagehandler | |||
*/ | |||
private static void setMessage (String m) { | |||
if (IDisSet) { | |||
message = getID() + ":" + m; | |||
} else { | |||
message = m; | |||
private static String getMessage () { | |||
return message; | |||
} | |||
} | |||
/** | |||
* informs the user of the message | |||
* @param message the message for the user | |||
*/ | |||
public static void log (String message) { | |||
setMessage(message); | |||
switch (outputMethod) { | |||
case SCREEN: | |||
System.out.print(getMessage ()); | |||
break; | |||
case FILE: | |||
if (fileOpened) { | |||
writer.print(getMessage ()); | |||
writer.flush(); | |||
/** | |||
* helper class which sets the message | |||
* and adds a prefix which can contain | |||
* the id of the thread which uses this messagehandler | |||
*/ | |||
private static void setMessage (String m) { | |||
if (IDisSet) { | |||
message = getID() + ":" + m; | |||
} else { | |||
openFile(); | |||
writer.print(getMessage ()); | |||
writer.flush(); | |||
message = m; | |||
} | |||
break; | |||
case EVENT: | |||
setMessage(message); | |||
Enumeration enum = listeners.elements(); | |||
while (enum.hasMoreElements()) { | |||
((MessageListener) enum.nextElement()).processMessage(new MessageEvent(getMessage())); | |||
} | |||
/** | |||
* informs the user of the message | |||
* @param message the message for the user | |||
*/ | |||
public static void log (String message) { | |||
if (!quiet) { | |||
setMessage(message); | |||
switch (outputMethod) { | |||
case SCREEN: | |||
System.out.print(getMessage ()); | |||
break; | |||
case FILE: | |||
if (fileOpened) { | |||
writer.print(getMessage ()); | |||
writer.flush(); | |||
} else { | |||
openFile(); | |||
writer.print(getMessage ()); | |||
writer.flush(); | |||
} | |||
break; | |||
case EVENT: | |||
setMessage(message); | |||
Enumeration enum = listeners.elements(); | |||
while (enum.hasMoreElements()) { | |||
((MessageListener) enum.nextElement()). | |||
processMessage( | |||
new MessageEvent(getMessage())); | |||
} | |||
break; | |||
case NONE: | |||
//do nothing | |||
break; | |||
default: | |||
System.out.print(message); | |||
} | |||
} | |||
break; | |||
case NONE: | |||
//do nothing | |||
break; | |||
default: | |||
System.out.print(message); | |||
} | |||
} | |||
/** | |||
* convenience method which adds a return to the message | |||
* @param message the message for the user | |||
*/ | |||
public static void logln (String message) { | |||
log (message+"\n"); | |||
} | |||
/** | |||
* convenience method which adds a return to the message | |||
* @param message the message for the user | |||
*/ | |||
public static void logln (String message) { | |||
log (message + "\n"); | |||
} | |||
/** | |||
* error warning for the user | |||
* @param errorMessage contains the warning string | |||
*/ | |||
/** | |||
* error warning for the user | |||
* @param errorMessage contains the warning string | |||
*/ | |||
public static void error (String errorMessage) { | |||
setMessage(errorMessage); | |||
switch (outputMethod) { | |||
case SCREEN: | |||
System.err.print(getMessage()); | |||
break; | |||
case FILE: | |||
if (fileOpened) { | |||
writer.print(getMessage()); | |||
writer.flush(); | |||
} else { | |||
openFile(); | |||
writer.print(getMessage()); | |||
writer.flush(); | |||
} | |||
break; | |||
case EVENT: | |||
setMessage(message); | |||
Enumeration enum = listeners.elements(); | |||
while (enum.hasMoreElements()) { | |||
MessageEvent messEv = new MessageEvent(getMessage()); | |||
messEv.setMessageType(MessageEvent.ERROR); | |||
((MessageListener) enum.nextElement()).processMessage(messEv); | |||
public static void error (String errorMessage) { | |||
setMessage(errorMessage); | |||
switch (outputMethod) { | |||
case SCREEN: | |||
System.err.print(getMessage()); | |||
break; | |||
case FILE: | |||
if (fileOpened) { | |||
writer.print(getMessage()); | |||
writer.flush(); | |||
} else { | |||
openFile(); | |||
writer.print(getMessage()); | |||
writer.flush(); | |||
} | |||
break; | |||
case EVENT: | |||
setMessage(message); | |||
Enumeration enum = listeners.elements(); | |||
while (enum.hasMoreElements()) { | |||
MessageEvent messEv = new MessageEvent(getMessage()); | |||
messEv.setMessageType(MessageEvent.ERROR); | |||
((MessageListener) enum.nextElement()). | |||
processMessage(messEv); | |||
} | |||
break; | |||
case NONE: | |||
//do nothing | |||
break; | |||
default: | |||
System.err.print(errorMessage); | |||
} | |||
break; | |||
case NONE: | |||
//do nothing | |||
break; | |||
default: | |||
System.err.print(errorMessage); | |||
} | |||
} | |||
/** | |||
* convenience method which adds a return to the error message | |||
* @param errorMessage the message for the user | |||
*/ | |||
public static void errorln (String errorMessage) { | |||
error (errorMessage+"\n"); | |||
} | |||
/** | |||
* convenience method which adds a return to the error message | |||
* @param errorMessage the message for the user | |||
*/ | |||
public static void errorln (String errorMessage) { | |||
error (errorMessage + "\n"); | |||
} | |||
/** | |||
* adds a MessageListener which listens for MessageEvents | |||
* @param MessageListener the listener to add | |||
*/ | |||
public static void addListener(MessageListener listener) { | |||
listeners.addElement(listener); | |||
} | |||
/** | |||
* adds a MessageListener which listens for MessageEvents | |||
* @param MessageListener the listener to add | |||
*/ | |||
public static void addListener(MessageListener listener) { | |||
listeners.addElement(listener); | |||
} | |||
/** | |||
* removes a MessageListener | |||
* @param MessageListener the listener to remove | |||
*/ | |||
public static void removeListener(MessageListener listener) { | |||
listeners.removeElement(listener); | |||
} | |||
/** | |||
* removes a MessageListener | |||
* @param MessageListener the listener to remove | |||
*/ | |||
public static void removeListener(MessageListener listener) { | |||
listeners.removeElement(listener); | |||
} | |||
/** | |||
* sets the output method | |||
* @param method the output method to use, allowed values are<br> | |||
* MessageHandler.SCREEN, MessageHandler.FILE, MessageHandler.EVENT | |||
* MessageHandler.NONE | |||
*/ | |||
public static void setOutputMethod (int method) { | |||
if (method > NONE) { | |||
MessageHandler.error("Error: Unknown output method"); | |||
} else { | |||
outputMethod = method; | |||
/** | |||
* sets the output method | |||
* @param method the output method to use, allowed values are<br> | |||
* MessageHandler.SCREEN, MessageHandler.FILE, MessageHandler.EVENT | |||
* MessageHandler.NONE | |||
*/ | |||
public static void setOutputMethod (int method) { | |||
if (method > NONE) { | |||
MessageHandler.error("Error: Unknown output method"); | |||
} else { | |||
outputMethod = method; | |||
} | |||
} | |||
/** | |||
* informs what output method is set | |||
* @return the output method | |||
*/ | |||
public static int getOutputMethod () { | |||
return outputMethod; | |||
} | |||
} | |||
/** | |||
* informs what output method is set | |||
* @return the output method | |||
*/ | |||
public static int getOutputMethod () { | |||
return outputMethod; | |||
} | |||
/** | |||
* sets the logfile name | |||
* @param filename name of the logfile | |||
* @param append if true, the logfile is appended | |||
*/ | |||
public static void setLogfileName (String filename, boolean append) { | |||
logfileName = filename; | |||
appendToFile = append; | |||
} | |||
/** | |||
* sets the logfile name | |||
* @param filename name of the logfile | |||
* @param append if true, the logfile is appended | |||
*/ | |||
public static void setLogfileName (String filename, boolean append) { | |||
logfileName = filename; | |||
appendToFile = append; | |||
} | |||
/** | |||
* returns the logfile name | |||
* @return String containing the logfile name | |||
*/ | |||
public static String getLogfileName () { | |||
return logfileName; | |||
} | |||
/** | |||
* returns the logfile name | |||
* @return String containing the logfile name | |||
*/ | |||
public static String getLogfileName () { | |||
return logfileName; | |||
} | |||
/** | |||
* helper file which opens the file for output method FILE | |||
*/ | |||
private static void openFile () { | |||
try { | |||
writer = new PrintWriter ( | |||
new FileWriter (logfileName, appendToFile), true); | |||
writer.println("\n=============================================="); | |||
fileOpened = true; | |||
} catch (IOException ioe) { | |||
System.err.println("Error: " + ioe); | |||
} | |||
} | |||
/** | |||
* helper file which opens the file for output method FILE | |||
*/ | |||
private static void openFile () { | |||
try { | |||
writer = new PrintWriter (new FileWriter (logfileName,appendToFile),true); | |||
writer.println("\n=============================================="); | |||
fileOpened = true; | |||
} catch (IOException ioe) { | |||
System.err.println("Error: " + ioe); | |||
/** | |||
* if set to true an id string is prefixed to every message | |||
* uses the thread info as an id for the message producer. Should be used if | |||
* more than one instance of Fop is running in the same JVM | |||
* this id becomes a prefix to every message | |||
*/ | |||
private static String getID () { | |||
return Thread.currentThread().toString(); | |||
} | |||
} | |||
/** | |||
* if set to true an id string is prefixed to every message | |||
* uses the thread info as an id for the message producer. Should be used if | |||
* more than one instance of Fop is running in the same JVM | |||
* this id becomes a prefix to every message | |||
*/ | |||
private static String getID () { | |||
return Thread.currentThread().toString() ; | |||
} | |||
/** | |||
* if set to true an id string is prefixed to every message | |||
* uses the thread info as an id for the message producer. Should be used if | |||
* more than one instance of Fop is running in the same JVM | |||
* this id becomes a prefix to every message | |||
* | |||
* @param id boolean (default is false) | |||
*/ | |||
/** | |||
* if set to true an id string is prefixed to every message | |||
* uses the thread info as an id for the message producer. Should be used if | |||
* more than one instance of Fop is running in the same JVM | |||
* this id becomes a prefix to every message | |||
* | |||
* @param id boolean (default is false) | |||
*/ | |||
public static void setID (boolean id) { | |||
IDisSet = id; | |||
} | |||
public static void setID (boolean id) { | |||
IDisSet = id; | |||
} | |||
/** | |||
* if set to true all normal messages are suppressed. | |||
* error messages are displayed allthesame | |||
* | |||
* @param quietMode boolean (default is false) | |||
*/ | |||
public static void setQuiet(boolean quietMode) { | |||
quiet = quietMode; | |||
} | |||
} |
@@ -68,6 +68,8 @@ import java.net.URL; | |||
// FOP | |||
import org.apache.fop.messaging.MessageHandler; | |||
import org.apache.fop.apps.*; | |||
import org.apache.fop.configuration.Configuration; | |||
/** | |||
* extension to Ant which allows usage of Fop in the | |||
@@ -77,7 +79,7 @@ import org.apache.fop.apps.*; | |||
* containing org.w3c.dom.svg etc. for svg support | |||
*/ | |||
public class Fop { | |||
public class Fop extends Starter { | |||
String fofile, pdffile; | |||
/** | |||
@@ -97,96 +99,27 @@ public class Fop { | |||
} | |||
/** | |||
* 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) { | |||
parserClassName = "org.apache.xerces.parsers.SAXParser"; | |||
} | |||
MessageHandler.logln("using SAX parser " + parserClassName); | |||
try { | |||
return (XMLReader) Class.forName( | |||
parserClassName).newInstance(); | |||
} catch (ClassNotFoundException e) { | |||
MessageHandler.errorln("Could not find " + parserClassName); | |||
} | |||
catch (InstantiationException e) { | |||
MessageHandler.errorln("Could not instantiate " + | |||
parserClassName); | |||
} | |||
catch (IllegalAccessException e) { | |||
MessageHandler.errorln("Could not access " + parserClassName); | |||
} | |||
catch (ClassCastException e) { | |||
MessageHandler.errorln(parserClassName + " is not a SAX driver"); | |||
} | |||
return null; | |||
} // end: createParser | |||
/** | |||
* create an InputSource from a file name | |||
* | |||
* @param filename the name of the file | |||
* @return the InputSource created | |||
*/ | |||
protected static InputSource fileInputSource(String filename) { | |||
/* this code adapted from James Clark's in XT */ | |||
File file = new File(filename); | |||
String path = file.getAbsolutePath(); | |||
String fSep = System.getProperty("file.separator"); | |||
if (fSep != null && fSep.length() == 1) | |||
path = path.replace(fSep.charAt(0), '/'); | |||
if (path.length() > 0 && path.charAt(0) != '/') | |||
path = '/' + path; | |||
try { | |||
return new InputSource(new URL("file", null, path).toString()); | |||
} catch (java.net.MalformedURLException e) { | |||
throw new Error("unexpected MalformedURLException"); | |||
} | |||
} // end: fileInputSource | |||
/** | |||
* main method, starts execution of this task | |||
* | |||
*/ | |||
public void execute () throws BuildException { | |||
public void run () { | |||
Driver driver = new Driver(); | |||
driver.setBaseDir(fofile); | |||
boolean errors = false; | |||
Options options = new Options(); | |||
boolean errors = false; | |||
String version = Version.getVersion(); | |||
MessageHandler.logln("=======================\nTask " + | |||
version + "\nconverting file " + fofile + " to " + pdffile); | |||
if (!(new File(fofile).exists())) { | |||
File fofileF = new File (fofile); | |||
Configuration.put("baseDir",new File(fofileF.getAbsolutePath()).getParent()); | |||
if (!fofileF.exists()) { | |||
errors = true; | |||
MessageHandler.errorln( | |||
"Task Fop - ERROR: Formatting objects file " + | |||
fofile + " missing."); | |||
} | |||
XMLReader parser = createParser(); | |||
InputHandler inputHandler = new FOInputHandler(fofileF); | |||
XMLReader parser = inputHandler.getParser(); | |||
super.setParserFeatures(parser); | |||
if (parser == null) { | |||
MessageHandler.errorln("Task Fop - ERROR: Unable to create SAX parser"); | |||
errors = true; | |||
} | |||
// setting the parser features | |||
try { | |||
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", | |||
true); | |||
} catch (SAXException e) { | |||
MessageHandler.errorln("Error in setting up parser feature namespace-prefixes"); | |||
MessageHandler.errorln("You need a parser which supports SAX version 2"); | |||
System.exit(1); | |||
} | |||
MessageHandler.logln("=======================\nTask " + | |||
version + "\nconverting file " + fofile + " to " + pdffile); | |||
if (!errors) { | |||
try { | |||
@@ -194,13 +127,12 @@ public class Fop { | |||
version); | |||
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); | |||
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); | |||
driver.addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); | |||
driver.addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); | |||
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping"); | |||
driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); | |||
driver.addPropertyList("org.apache.fop.extensions.ExtensionPropertyListMapping"); | |||
driver.addPropertyList("org.apache.fop.extensions.ExtensionPropertyListMapping"); | |||
driver.setOutputStream(new FileOutputStream(pdffile)); | |||
driver.buildFOTree(parser, fileInputSource(fofile)); | |||
driver.buildFOTree(parser, inputHandler.fileInputSource(fofileF)); | |||
driver.format(); | |||
driver.render(); | |||
} catch (Exception e) { | |||
@@ -210,6 +142,14 @@ public class Fop { | |||
} | |||
} | |||
MessageHandler.logln("=======================\n"); | |||
} | |||
/** | |||
* main method, starts execution of this task | |||
* | |||
*/ | |||
public void execute () throws BuildException { | |||
run(); | |||
} // end: execute | |||
} | |||