--- /dev/null
+/*\r
+ * Copyright 1999-2003,2005 The Apache Software Foundation.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+/* $Id$ */\r
+ \r
+package embedding;\r
+\r
+//Java\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+//JAXP\r
+import javax.xml.transform.Transformer;\r
+import javax.xml.transform.TransformerFactory;\r
+import javax.xml.transform.TransformerException;\r
+import javax.xml.transform.Source;\r
+import javax.xml.transform.Result;\r
+import javax.xml.transform.stream.StreamSource;\r
+import javax.xml.transform.sax.SAXResult;\r
+\r
+//Avalon\r
+import org.apache.avalon.framework.ExceptionUtil;\r
+\r
+//FOP\r
+import org.apache.fop.apps.FOPException;\r
+import org.apache.fop.apps.Fop;\r
+import org.apache.fop.fo.Constants;\r
+\r
+/**\r
+ * This class demonstrates the use of the AWT Viewer.\r
+ */\r
+public class ExampleAWTViewer {\r
+\r
+ public void viewFO(File fo)\r
+ throws IOException, FOPException, TransformerException {\r
+\r
+ //Setup FOP\r
+ Fop fop = new Fop(Constants.RENDER_AWT);\r
+\r
+ try {\r
+\r
+ //Load XSL-FO file (you can also do an XSL transformation here)\r
+ TransformerFactory factory = TransformerFactory.newInstance();\r
+ Transformer transformer = factory.newTransformer();\r
+ Source src = new StreamSource(fo);\r
+ Result res = new SAXResult(fop.getDefaultHandler());\r
+ transformer.transform(src, res);\r
+\r
+ } catch (Exception e) {\r
+ if (e instanceof FOPException) {\r
+ throw (FOPException)e;\r
+ }\r
+ throw new FOPException(e);\r
+ }\r
+ }\r
+\r
+ public static void main(String[] args) {\r
+ try {\r
+ System.out.println("FOP ExampleAWTViewer\n");\r
+ System.out.println("Preparing...");\r
+\r
+ //Setup directories\r
+ File baseDir = new File(".");\r
+ File outDir = new File(baseDir, "out");\r
+ outDir.mkdirs();\r
+\r
+ //Setup input and output files\r
+ File fofile = new File(baseDir, "xml/fo/helloworld.fo");\r
+\r
+ System.out.println("Input: XSL-FO (" + fofile + ")");\r
+ System.out.println("Output: AWT Viewer");\r
+ System.out.println();\r
+ System.out.println("Starting AWT Viewer...");\r
+\r
+ ExampleAWTViewer app = new ExampleAWTViewer();\r
+ app.viewFO(fofile);\r
+\r
+ System.out.println("Success!");\r
+ } catch (Exception e) {\r
+ System.err.println(ExceptionUtil.printStackTrace(e));\r
+ System.exit(-1);\r
+ }\r
+ }\r
+}\r