KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > rtf > rtflib > testdocs > CreateTestDocuments


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: CreateTestDocuments.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20
21 /*
22  * This file is part of the RTF library of the FOP project, which was originally
23  * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
24  * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
25  * the FOP project.
26  */

27
28 package org.apache.fop.render.rtf.rtflib.testdocs;
29
30 import java.io.File JavaDoc;
31 import java.io.IOException JavaDoc;
32 //import org.apache.fop.render.rtf.rtflib.jfor.main.JForVersionInfo;
33

34 /** Create test RTF documents from classes found in this package.
35  * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
36  * @author Andreas Putz a.putz@skynamics.com
37  */

38
39 public class CreateTestDocuments {
40
41     /**
42      * package name for the testdocs
43      */

44     public static final String JavaDoc TESTDOCS_PACKAGE = "org.apache.fop.render.rtf.rtflib.testdocs";
45
46     /** List of all TestDocument subclasses from this package */
47     private static final String JavaDoc [] CLASS_NAMES = {
48         "SimpleDocument",
49         "TextAttributes",
50         "SimpleTable",
51         "SimpleLists",
52         "ListInTable",
53         "Whitespace",
54         "MergedTableCells",
55         "NestedTable",
56         "ExternalGraphic",
57         "BasicLink",
58         "ParagraphAlignment"
59     };
60
61     CreateTestDocuments(File JavaDoc outDir)
62     throws Exception JavaDoc {
63         if (!outDir.isDirectory() || !outDir.canWrite()) {
64             throw new IOException JavaDoc("output directory (" + outDir + ") must exist and be writable");
65         }
66
67         for (int i = 0; i < CLASS_NAMES.length; i++) {
68             createOneTestDocument(CLASS_NAMES[i], outDir);
69         }
70     }
71
72     /** instantiate one TestDocument and let it generate its document */
73     void createOneTestDocument(String JavaDoc className, File JavaDoc outDir)
74             throws Exception JavaDoc {
75         className = TESTDOCS_PACKAGE + "." + className;
76         TestDocument td = null;
77         try {
78             td = (TestDocument)Class.forName(className).newInstance();
79         } catch (Exception JavaDoc e) {
80             throw new Exception JavaDoc("unable to instantiate '" + className
81                     + " as a TestDocument object: " + e);
82         }
83         td.setOutputDir(outDir);
84         try {
85             td.generateOutput();
86         } catch (Exception JavaDoc e) {
87             System.err.println("Error while generating test RTF document:");
88             e.printStackTrace();
89         }
90     }
91
92     /** execute this to create test documents from all classes listed in classNames array
93      * @param args String array of arguments
94      * @throws Exception for errors
95      */

96     public static void main(String JavaDoc[] args)
97     throws Exception JavaDoc {
98         if (args.length < 1) {
99             System.err.println("usage: CreateTestDocuments <output directory>");
100             System.exit(1);
101         }
102
103 // System.err.println("CreateTestDocuments - using " + JForVersionInfo.getLongVersionInfo());
104
System.err.println("Generates documents to test the RTF library.");
105         final File JavaDoc outDir = new File JavaDoc(args[0]);
106         new CreateTestDocuments(outDir);
107         System.err.println("CreateTestDocuments - all done.");
108         System.exit(0);
109     }
110 }
111
Popular Tags