View Javadoc

1   /*
2   This file is part of the xframe software package
3   hosted at http://xframe.sourceforge.net
4   
5   Copyright (c) 2003 Kurt Riede.
6   
7   This library is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Lesser General Public
9   License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11  
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16  
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21  package net.sf.xframe.xsddoc;
22  
23  import net.sf.xframe.ex.ExceptionUtil;
24  
25  /***
26   * Command line interface of xsddoc.
27   *
28   * <dl><dt><b>Usage:</b></dt><dd><pre>xsddoc [-option] schema
29   *              (to document a schema)
30   *where options include:
31   *    -o -out &lt;folder>      Set the output folder
32   *    -t -doctitle &lt;title>  Set the documentation title
33   *    -h -header &lt;header>   Set the documentation header
34   *    -f -footer &lt;footer>   Set the documentation footer
35   *    -b -bottom &lt;bottom>   Set the documentation bottom
36   *    -v -verbose           Output messages about what xsddoc is doing
37   *    -q -quiet             Donot output any messages
38   *    -s -hideSubTypes      hide sub types references
39   *    -l -hideSubLocalUsage hide show local usage references
40   *    -p -hideTypes         hide types in overview pages
41   *    -g -hideGroups        hide groups in overview pages
42   *    -a -hideAttributes    hide attributes in overview pages
43   *    -xml                  output as XML instead of HTML
44   *    -css &lt;css-file>    provide external CSS file
45   *    -version              Only output version of xsddoc
46   *    -d -debug             Output debug messages
47   *    -? -help              Print this help message
48   *</pre></dl>
49   *
50   * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede</a>
51   */
52  public final class Main {
53  
54      /*** version info. */
55      private static final String VERSION = "0.7-beta";
56  
57      /***
58       * Private default constructor to prevent instantiation.
59       */
60      private Main() {
61      }
62  
63      /***
64       * Main method of command line interface of xsddoc.
65       *
66       * @param args Array of command line arguments
67       */
68      public static void main(final String[] args) {
69          final Processor processor = new Processor();
70          try {
71              if (args.length < 1) {
72                  System.out.println("Missing schema argument.");
73                  usage();
74                  return;
75              }
76              int i = 0;
77              while (i < args.length) {
78                  if (args[i].charAt(0) == '-') {
79                      final String option = args[i].substring(1);
80                      if ("o".equals(option) || "out".equals(option)) {
81                          processor.setOut(args[++i]);
82                      } else if ("t".equals(option) || "doctitle".equals(option)) {
83                          processor.setDoctitle(args[++i]);
84                      } else if ("h".equals(option) || "header".equals(option)) {
85                          processor.setHeader(args[++i]);
86                      } else if ("f".equals(option) || "footer".equals(option)) {
87                          processor.setFooter(args[++i]);
88                      } else if ("b".equals(option) || "bottom".equals(option)) {
89                          processor.setBottom(args[++i]);
90                      } else if ("v".equals(option) || "verbose".equals(option)) {
91                          processor.setVerbose(true);
92                      } else if ("q".equals(option) || "quiet".equals(option)) {
93                          processor.setVerbose(false);
94                      } else if ("d".equals(option) || "debug".equals(option)) {
95                          processor.setDebug(true);
96                      } else if ("s".equals(option) || "hideSubTypes".equals(option)) {
97                          processor.setHideSubTypes(true);
98                      } else if ("l".equals(option) || "hideLocalUsage".equals(option)) {
99                          processor.setHideLocalUsage(true);
100                     } else if ("p".equals(option) || "hideTypes".equals(option)) {
101                         processor.setHideTypes(true);
102                     } else if ("g".equals(option) || "hideGroups".equals(option)) {
103                         processor.setHideGroups(true);
104                     } else if ("a".equals(option) || "hideAttributes".equals(option)) {
105                         processor.setHideAttributes(true);
106                     } else if ("c".equals(option) || "css".equals(option)) {
107                         processor.setCss(args[++i]);
108                     } else if ("x".equals(option) || "xml".equals(option)) {
109                         processor.setXml(true);
110                     } else if ("version".equals(option)) {
111                         System.out.println("xframe - xsddoc version " + VERSION);
112                         return;
113                     } else if ("?".equals(option) || "help".equals(option)) {
114                         usage();
115                         return;
116                     } else {
117                         System.out.println("unknown parameter: " + option);
118                         usage();
119                         return;
120                     }
121                 } else {
122                     processor.setSchemaLocation(args[i]);
123                     break;
124                 }
125                 i++;
126             }
127             System.out.println("xsddoc starting.");
128             processor.execute();
129         } catch (Error e) {
130             System.out.println(e.getLocalizedMessage());
131             System.out.println(ExceptionUtil.printStackTrace(e));
132         } catch (RuntimeException e) {
133             System.out.println(e.getLocalizedMessage());
134             System.out.println(ExceptionUtil.printStackTrace(e));
135         } catch (Exception e) {
136             System.out.println(e.getLocalizedMessage());
137             if (processor.isDebug()) {
138                 System.out.println(ExceptionUtil.printStackTrace(e));
139             }
140         }
141         System.out.println("xsddoc finished.");
142     }
143 
144     /***
145      * Print usage information to standard out.
146      */
147     private static void usage() {
148         System.out.println("Usage: xsddoc [-option] schema");
149         System.out.println("             (to document a schema)");
150         System.out.println("where options include:");
151         System.out.println("    -o -out <folder>      Set the output folder");
152         System.out.println("    -t -doctitle <title>  Set the documentation title");
153         System.out.println("    -h -header <header>   Set the documentation header");
154         System.out.println("    -f -footer <footer>   Set the documentation footer");
155         System.out.println("    -b -bottom <bottom>   Set the documentation bottom");
156         System.out.println("    -v -verbose           Output messages about what xsddoc is doing");
157         System.out.println("    -q -quiet             Be quiet about what xsddoc is doing");
158         System.out.println("    -s -hideSubTypes      hide sub types references");
159         System.out.println("    -l -hideSubLocalUsage hide show local usage references");
160         System.out.println("    -p -hideTypes         hide types in overview pages");
161         System.out.println("    -g -hideGroups        hide groups in overview pages");
162         System.out.println("    -a -hideAttributes    hide attributes in overview pages");
163         System.out.println("    -xml                  output as XML instead of HTML");
164         System.out.println("    -version              Only output version of xsddoc");
165         System.out.println("    -d -debug             Output debug messages");
166         System.out.println("    -? -help              Print this help message");
167     }
168 
169 }