1 /*------------------------------------------------------------------------------
2 Name: CollectXml.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Collects all xml requirement files into the all.xml master file
6 Version: $Id: CollectXml.java 12937 2004-11-24 20:15:11Z ruff $
7 ------------------------------------------------------------------------------*/
8 package doc.requirements;
9
10 import java.io.*;
11
12
13 /**
14 * Collects all xml requirement files into the all.xml master file.
15 * <p />
16 * This master file is used by html.xsl to generate HTML output
17 * Example:
18 * <pre>
19 * <?xml version='1.0' encoding='ISO-8859-1' ?>
20 * <!-- all.xml, generated by CollectXml.java -->
21 * <files>
22 * <url>engine.get.no.xml</url>
23 * <url>util.recorder.xml</url>
24 * <url>util.property.env.xml</url>
25 * <url>engine.qos.destination.offline.xml</url>
26 * </files>
27 * </pre>
28 * Invoke example:<br />
29 * <pre>
30 * java doc.requirements.CollectXml
31 * </pre>
32 */
33 public class CollectXml
34 {
35 /**
36 */
37 public CollectXml(String[] args)
38 {
39 try {
40 File dir = new File(".");
41 if (!dir.canWrite()) {
42 System.err.println("Sorry, no write permissions for directory");
43 System.exit(1);
44 }
45
46 File[] files = dir.listFiles(new MyFilenameFilter());
47
48 PrintWriter fout = new PrintWriter(new FileOutputStream("all.xml"));
49 fout.println("<?xml version='1.0' encoding='ISO-8859-1' ?>");
50 fout.println("<!-- all.xml, generated by CollectXml.java -->");
51 fout.println("<files>");
52 String currentPath = System.getProperty("user.dir");
53 fout.println(" <dir>" + currentPath + "</dir>");
54 for (int ii=0; ii<files.length; ii++) {
55 fout.println(" <url>" + files[ii].getName() + "</url>");
56 }
57 fout.println("</files>");
58 fout.close();
59 System.err.println("Created all.xml with " + files.length + " entries");
60 }
61 catch (Exception e) {
62 System.err.println("Can't create all.xml: " + e.toString());
63 System.exit(1);
64 }
65
66 System.exit(0);
67 }
68
69 private class MyFilenameFilter implements FilenameFilter
70 {
71 public MyFilenameFilter() {}
72 public boolean accept(File dir, String name)
73 {
74 if (name.endsWith(".xml") && !name.equals("all.xml"))
75 return true;
76 return false;
77 }
78
79 }
80
81 /**
82 * Invoke: java doc.requirements.CollectXml
83 */
84 public static void main(String args[])
85 {
86 new CollectXml(args);
87 }
88 }
syntax highlighted by Code2HTML, v. 0.9.1