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  *  &lt;?xml version='1.0' encoding='ISO-8859-1' ?>
20  *  &lt;!-- all.xml, generated by CollectXml.java -->
21  *  &lt;files>
22  *     &lt;url>engine.get.no.xml&lt;/url>
23  *     &lt;url>util.recorder.xml&lt;/url>
24  *     &lt;url>util.property.env.xml&lt;/url>
25  *     &lt;url>engine.qos.destination.offline.xml&lt;/url>
26  *  &lt;/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