diff options
author | Jeremias Maerki <jeremias@apache.org> | 2005-08-23 14:06:25 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2005-08-23 14:06:25 +0000 |
commit | d23dad3ac526243651ecfc64e5ba42f2b76c959c (patch) | |
tree | 52820c77727ad46685477114b339f33631d283b3 /src/java/org/apache/fop/apps/Fop.java | |
parent | c4aa8acd9cffd99ba4858d54991a00e338fb1e5b (diff) | |
download | xmlgraphics-fop-d23dad3ac526243651ecfc64e5ba42f2b76c959c.tar.gz xmlgraphics-fop-d23dad3ac526243651ecfc64e5ba42f2b76c959c.zip |
Moved CLI to its own package. New main class is org.apache.fop.cli.Main.
InputHandler is not passed through the FOUserAgent anymore. IMO it doesn't belong there. Instead I defined an interface "Renderable" in the AWT preview that InputHandler implements. This is used exclusively for reloading the document inside the preview dialog.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@239409 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/apps/Fop.java')
-rw-r--r-- | src/java/org/apache/fop/apps/Fop.java | 166 |
1 files changed, 1 insertions, 165 deletions
diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java index b359e23b7..bef2b4a3e 100644 --- a/src/java/org/apache/fop/apps/Fop.java +++ b/src/java/org/apache/fop/apps/Fop.java @@ -19,15 +19,7 @@ package org.apache.fop.apps; // Java -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileFilter; -import java.io.FileOutputStream; import java.io.OutputStream; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; // XML import org.xml.sax.helpers.DefaultHandler; @@ -37,8 +29,7 @@ import org.apache.fop.fo.Constants; import org.apache.fop.fo.FOTreeBuilder; /** - * Primary class that activates the FOP process for both command line - * and embedded usage. + * Primary class that activates the FOP process for embedded usage. * <P> * JAXP is the standard method of embedding FOP in Java programs. * Please check our embedding page (http://xml.apache.org/fop/embedding.html) @@ -161,161 +152,6 @@ public class Fop implements Constants { } /** - * @return the list of URLs to all libraries. - * @throws MalformedURLException In case there is a problem converting java.io.File - * instances to URLs. - */ - public static URL[] getJARList() throws MalformedURLException { - File baseDir = new File(".").getAbsoluteFile().getParentFile(); - File buildDir; - if ("build".equals(baseDir.getName())) { - buildDir = baseDir; - baseDir = baseDir.getParentFile(); - } else { - buildDir = new File(baseDir, "build"); - } - File fopJar = new File(buildDir, "fop.jar"); - if (!fopJar.exists()) { - fopJar = new File(baseDir, "fop.jar"); - } - if (!fopJar.exists()) { - throw new RuntimeException("fop.jar not found in directory: " - + baseDir.getAbsolutePath() + " (or below)"); - } - List jars = new java.util.ArrayList(); - jars.add(fopJar.toURL()); - File[] files; - FileFilter filter = new FileFilter() { - public boolean accept(File pathname) { - return pathname.getName().endsWith(".jar"); - } - }; - File libDir = new File(baseDir, "lib"); - if (!libDir.exists()) { - libDir = baseDir; - } - files = libDir.listFiles(filter); - if (files != null) { - for (int i = 0, size = files.length; i < size; i++) { - jars.add(files[i].toURL()); - } - } - String optionalLib = System.getProperty("fop.optional.lib"); - if (optionalLib != null) { - files = new File(optionalLib).listFiles(filter); - if (files != null) { - for (int i = 0, size = files.length; i < size; i++) { - jars.add(files[i].toURL()); - } - } - } - URL[] urls = (URL[])jars.toArray(new URL[jars.size()]); - /* - for (int i = 0, c = urls.length; i < c; i++) { - System.out.println(urls[i]); - }*/ - return urls; - } - - /** - * @return true if FOP's dependecies are available in the current ClassLoader setup. - */ - public static boolean checkDependencies() { - try { - //System.out.println(Thread.currentThread().getContextClassLoader()); - Class clazz = Class.forName("org.apache.batik.Version"); - if (clazz != null) { - clazz = Class.forName("org.apache.avalon.framework.configuration.Configuration"); - } - return (clazz != null); - } catch (Exception e) { - return false; - } - } - - /** - * Dynamically builds a ClassLoader and executes FOP. - * @param args command-line arguments - */ - public static void startFOPWithDynamicClasspath(String[] args) { - try { - URL[] urls = getJARList(); - //System.out.println("CCL: " - // + Thread.currentThread().getContextClassLoader().toString()); - ClassLoader loader = new java.net.URLClassLoader(urls, null); - Thread.currentThread().setContextClassLoader(loader); - Class clazz = Class.forName("org.apache.fop.apps.Fop", true, loader); - //System.out.println("CL: " + clazz.getClassLoader().toString()); - Method mainMethod = clazz.getMethod("startFOP", new Class[] {String[].class}); - mainMethod.invoke(null, new Object[] {args}); - } catch (Exception e) { - System.err.println("Unable to start FOP:"); - e.printStackTrace(); - System.exit(-1); - } - } - - /** - * Executes FOP with the given ClassLoader setup. - * @param args command-line arguments - */ - public static void startFOP(String[] args) { - //System.out.println("static CCL: " - // + Thread.currentThread().getContextClassLoader().toString()); - //System.out.println("static CL: " + Fop.class.getClassLoader().toString()); - CommandLineOptions options = null; - FOUserAgent foUserAgent = null; - BufferedOutputStream bos = null; - - try { - options = new CommandLineOptions(); - options.parse(args); - foUserAgent = options.getFOUserAgent(); - - Fop fop = new Fop(options.getRenderer(), foUserAgent); - - try { - if (options.getOutputFile() != null) { - bos = new BufferedOutputStream(new FileOutputStream( - options.getOutputFile())); - fop.setOutputStream(bos); - foUserAgent.setOutputFile(options.getOutputFile()); - } - foUserAgent.getInputHandler().render(fop); - } finally { - if (bos != null) { - bos.close(); - } - } - - // System.exit(0) called to close AWT/SVG-created threads, if any. - // AWTRenderer closes with window shutdown, so exit() should not - // be called here - if (options.getOutputMode() != CommandLineOptions.RENDER_AWT) { - System.exit(0); - } - } catch (Exception e) { - if (options != null) { - options.getLogger().error("Exception", e); - } - System.exit(1); - } - } - - /** - * The main routine for the command line interface - * @param args the command line parameters - */ - public static void main(String[] args) { - if (checkDependencies()) { - startFOP(args); - } else { - startFOPWithDynamicClasspath(args); - } - } - - - /** * Get the version of FOP * @return the version string */ |