Changeset 5283
- Timestamp:
- 2003-08-27T10:46:37+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/Generator.java
r4686 r5283 57 57 public class Generator { 58 58 59 private boolean ignore_file; 59 60 private FileOutputStream file_output_stream = null; 60 61 61 private TemplateManager template_manager = null; 62 62 63 public Generator(File test_file, File template_file) { 64 template_manager = new TemplateManager(template_file); 63 public Generator(File test_file, File template_file, boolean ignore_file) { 64 this.ignore_file = ignore_file; 65 this.template_manager = new TemplateManager(template_file); 65 66 File files[] = null; 66 67 // If test_file is a file, goody. … … 114 115 System.out.println("Rapid repeated HTML generation tool."); 115 116 System.out.println(" written by John Thompson, 2002\n"); 117 boolean ignore_file = false; 116 118 boolean usage = false; 117 119 // Attempt to generate html from text 118 if( args.length == 2) {120 if(2 <= args.length && args.length <= 3) { 119 121 File text_file = new File(args[0]); 120 122 File template_file = new File(args[1]); 123 if(args.length == 3) { 124 if(args[2].equals("-ignore_file")) { 125 ignore_file = true; 126 } 127 } 121 128 if(!text_file.exists() || !template_file.exists() || !template_file.isFile()) { 122 129 usage = true; 123 130 } 124 131 else { 125 Generator generator = new Generator(text_file, template_file );132 Generator generator = new Generator(text_file, template_file, ignore_file); 126 133 generator.exit(); 127 134 } … … 132 139 // Print usage message 133 140 if(usage) { 134 System.out.println("Usage: Gen Help <text_file> <template_file>");141 System.out.println("Usage: Generator <text_file> <template_file> [-ignore_file]"); 135 142 System.out.println("text_file - A file containing text marked up using special tags."); 136 143 System.out.println("template_file - An HTML file using tags to specify where to insert text."); 144 System.out.println("-ignore_file - Instructs generator to ignore $FILE tags, thus generating a single output document."); 137 145 } 138 146 } … … 256 264 // The first case to consider is a file open command tag. This tells us the next block of html should be written to a certain file. 257 265 if(line.startsWith("<$FILE")) { 258 // Close any existing output file. 259 if(output_file != null) { 260 // Write any existing block 261 if(block != null) { 262 if(paragraph != null) { 263 block.insert(paragraph.toString()); 264 paragraph = null; 266 // If we have been asked to ignore file tags, then thats what we do. 267 if(ignore_file) { 268 done = true; 269 } 270 else { 271 // Close any existing output file. 272 if(output_file != null) { 273 // Write any existing block 274 if(block != null) { 275 if(paragraph != null) { 276 block.insert(paragraph.toString()); 277 paragraph = null; 278 } 279 out(" write: " + block.getName()); 280 output_file.write((block.toString()).getBytes()); 281 block = null; 265 282 } 266 out(" write: " + block.getName()); 267 output_file.write((block.toString()).getBytes()); 268 block = null; 269 } 270 output_file.close(); 271 output_file = null; 272 } 273 // Determine the new file name. 274 String name = line.substring(12, line.lastIndexOf(">")); 275 // Create new file. 276 output_file = new FileOutputStream(name); 277 // Dealt with 278 out(" writing to: " + name); 279 name = null; 280 done = true; 283 // Write the file footer 284 output_file.write((template_manager.getHTMLBlock("FILE_FOOTER")).toString().getBytes()); 285 286 output_file.close(); 287 output_file = null; 288 } 289 // Determine the new file name. 290 String name = line.substring(12, line.lastIndexOf(">")); 291 // Create new file. 292 output_file = new FileOutputStream(name); 293 // Write file header 294 output_file.write((template_manager.getHTMLBlock("FILE_HEADER")).toString().getBytes()); 295 // Dealt with 296 out(" writing to: " + name); 297 name = null; 298 done = true; 299 } 281 300 } 282 301 else if(line.startsWith("<$")) { … … 290 309 if(output_file == null) { 291 310 output_file = new FileOutputStream(text_file.getName() + ".htm"); 311 // Write file header 312 output_file.write((template_manager.getHTMLBlock("FILE_HEADER")).toString().getBytes()); 292 313 } 293 314 out(" write: " + block.getName()); … … 339 360 if(output_file == null) { 340 361 output_file = new FileOutputStream(text_file.getName() + ".htm"); 362 // Write file header 363 output_file.write((template_manager.getHTMLBlock("FILE_HEADER")).toString().getBytes()); 341 364 } 342 365 out(" write: " + block.getName()); … … 346 369 paragraph = null; 347 370 line = null; 348 output_file.close(); 371 // Close any remaining output_file 372 if(output_file != null) { 373 // Write file footer 374 output_file.write((template_manager.getHTMLBlock("FILE_FOOTER")).toString().getBytes()); 375 output_file.close(); 376 } 349 377 output_file = null; 350 378 }
Note:
See TracChangeset
for help on using the changeset viewer.