Source code: jtt/docbook/DocBookArticles.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: DocBookArticles.java,v $
3 // Purpose: Descriptor base class.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.2 $
8 // $Date: 2003/10/13 08:17:00 $
9 // $Author: wegner $
10 //
11 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
12 //
13 // This program is free software; you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation version 2 of the License.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 ///////////////////////////////////////////////////////////////////////////////
22 package jtt.docbook;
23
24 import wsi.ra.tool.PropertyHolder;
25
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.io.PrintStream;
30
31 import org.apache.log4j.Category;
32 import org.apache.tools.ant.DirectoryScanner;
33
34
35 /*==========================================================================*
36 * IMPORTS
37 *========================================================================== */
38 /*==========================================================================*
39 * INTERFACE DECLARATION
40 *========================================================================== */
41
42 /**
43 * Interface for defining a decimal formatter.
44 *
45 * @author wegnerj
46 * @license GPL
47 * @cvsversion $Revision: 1.2 $, $Date: 2003/10/13 08:17:00 $
48 */
49 public class DocBookArticles
50 {
51 //~ Static fields/initializers /////////////////////////////////////////////
52
53 private static Category logger = Category.getInstance(
54 "jtt.docbook.DocBookArticles");
55
56 //~ Instance fields ////////////////////////////////////////////////////////
57
58 private PropertyHolder propertyHolder;
59 private String baseDir;
60 private String dtd;
61 private String fileExtension;
62 private String outputDir;
63 private String version;
64
65 //~ Constructors ///////////////////////////////////////////////////////////
66
67 public DocBookArticles() throws Exception
68 {
69 propertyHolder = PropertyHolder.instance();
70
71 if (!loadParameters())
72 {
73 throw new Exception("Could not get all parameters.");
74 }
75 }
76
77 //~ Methods ////////////////////////////////////////////////////////////////
78
79 public String[] getFileList()
80 {
81 DirectoryScanner ds = new DirectoryScanner();
82 String[] includes = {"*." + fileExtension};
83 ds.setIncludes(includes);
84
85 //System.out.println("BASEDIR: " + baseDir);
86 ds.setBasedir(new File(baseDir));
87 ds.setCaseSensitive(true);
88 ds.scan();
89
90 return ds.getIncludedFiles();
91 }
92
93 public void apply(String[] args)
94 {
95 baseDir = args[0];
96 outputDir = args[1];
97
98 String[] files = getFileList();
99
100 //System.out.println("FILES:");
101 int index;
102
103 for (int i = 0; i < files.length; i++)
104 {
105 //System.out.println(files[i]);
106 index = files[i].indexOf(".");
107 generateArticleFile("..", files[i].substring(0, index), args[2]);
108
109 //createArticle(files[i].substring(0,index));
110 }
111 }
112
113 public void createArticle(String name)
114 {
115 try
116 {
117 Jade jade = new Jade();
118
119 //System.out.println("execute jade on "+outputDir + "/" + name + "."+fileExtension);
120 jade.execute(outputDir, "sgml",
121 //outputDir + "/" +
122 name + "." + fileExtension);
123 jade.execute(outputDir, "rtf",
124 //outputDir + "/" +
125 name + "." + fileExtension);
126
127 //jade.execute(outputDir,"xml",
128 //outputDir + "/" + name + "."+fileExtension);
129 }
130 catch (Exception e)
131 {
132 e.printStackTrace();
133 }
134 }
135
136 public void generateArticleFile(String directory, String name,
137 String bibliography)
138 {
139 // System.out.println(name);
140 // System.out.println("---");
141 FileOutputStream os = null;
142 PrintStream ps = null;
143
144 try
145 {
146 os = new FileOutputStream(outputDir + "/" + name + "." +
147 fileExtension);
148 ps = new PrintStream(os);
149 }
150 catch (Exception ex)
151 {
152 ex.printStackTrace();
153 }
154
155 ps.print("<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook ");
156 ps.print(version);
157 ps.print("//EN\" \"");
158 ps.print(dtd);
159 ps.println("\" [");
160 ps.print(" <!ENTITY ");
161 ps.print(name);
162 ps.print(" SYSTEM \"");
163 ps.print(directory);
164 ps.print('/');
165 ps.print(name);
166 ps.print('.');
167 ps.print(fileExtension);
168 ps.println("\">");
169
170 if (bibliography != null)
171 {
172 ps.print(" <!ENTITY bibliography SYSTEM \"");
173 ps.print(bibliography);
174 ps.println("\">");
175 }
176
177 ps.println("]>");
178 ps.println("<article>");
179
180 ps.print(" <?dbhtml filename='");
181 ps.print(name);
182 ps.println(".html' output-dir='.'>");
183 ps.print(" <sect1 id=\"joelib.descriptor");
184
185 //ps.print('.');
186 //ps.print(name);
187 ps.println("\">");
188 ps.println(" <title>Descriptor</title>");
189 ps.print(" &");
190 ps.print(name);
191 ps.println(";");
192 ps.println(" </sect1>");
193
194 if (bibliography != null)
195 {
196 ps.println(" &bibliography;");
197 }
198
199 ps.println("</article>");
200
201 try
202 {
203 ps.close();
204 os.close();
205 }
206 catch (IOException e)
207 {
208 e.printStackTrace();
209 }
210 }
211
212 /**
213 * Description of the Method
214 *
215 * @return Description of the Return Value
216 */
217 public boolean loadParameters() throws Exception
218 {
219 String value;
220
221 if ((value = propertyHolder.getProperty(this, "version")) == null)
222 {
223 logger.error("DocBook version not defined.");
224
225 return false;
226 }
227 else
228 {
229 version = value;
230 }
231
232 if ((value = propertyHolder.getProperty(this, "fileExtension")) == null)
233 {
234 logger.error("File extension not defined.");
235
236 return false;
237 }
238 else
239 {
240 fileExtension = value;
241 }
242
243 if ((value = propertyHolder.getProperty(this, "DTD")) == null)
244 {
245 logger.error("File extension not defined.");
246
247 return false;
248 }
249 else
250 {
251 dtd = value;
252 }
253
254 return true;
255 }
256
257 /**
258 * The main program for the TestSmarts class
259 *
260 * @param args The command line arguments
261 */
262 public static void main(String[] args)
263 {
264 DocBookArticles createArticles;
265
266 try
267 {
268 createArticles = new DocBookArticles();
269 createArticles.apply(args);
270 }
271 catch (Exception e)
272 {
273 e.printStackTrace();
274 System.exit(1);
275 }
276
277 System.exit(0);
278 }
279
280 /**
281 * Description of the Method
282 */
283 public void usage()
284 {
285 StringBuffer sb = new StringBuffer();
286 String programName = this.getClass().getName();
287
288 sb.append("\nUsage is : ");
289 sb.append("java -cp . ");
290 sb.append(programName);
291 sb.append(" <args>");
292 sb.append(
293 "\n\nThis is version $Revision: 1.2 $ ($Date: 2003/10/13 08:17:00 $)\n");
294
295 System.out.println(sb.toString());
296
297 System.exit(0);
298 }
299 }
300 ///////////////////////////////////////////////////////////////////////////////
301 // END OF FILE.
302 ///////////////////////////////////////////////////////////////////////////////