Source Code Cross Referenced for Main.java in  » Ajax » Laszlo-4.0.10 » org » openlaszlo » js2doc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » Laszlo 4.0.10 » org.openlaszlo.js2doc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* *****************************************************************************
002:         * Main.java
003:         * ****************************************************************************/
004:
005:        /* J_LZ_COPYRIGHT_BEGIN *******************************************************
006:         * Copyright 2006-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
007:         * Use is subject to license terms.                                            *
008:         * J_LZ_COPYRIGHT_END *********************************************************/
009:
010:        package org.openlaszlo.js2doc;
011:
012:        import org.w3c.dom.Document;
013:        import org.apache.log4j.*;
014:        import org.apache.log4j.spi.*;
015:        import org.apache.log4j.varia.NullAppender;
016:        import org.openlaszlo.utils.FileUtils;
017:        import java.io.*;
018:        import java.util.*;
019:
020:        public class Main {
021:
022:            private static Logger logger;
023:
024:            private static final String[] USAGE = {
025:                    "Usage: js2doc [OPTION]... FILE...", "", "Options:", "-v",
026:                    "  Write progress information to standard output.",
027:                    "--test schema",
028:                    "  Test mode: validate result against schema given",
029:                    "--reprocess", "  Reprocess comments", "--help",
030:                    "  Prints this message.", "", "Output options:",
031:                    "--out outputfile", "  Output file", "--dir outputdir",
032:                    "  Output directory (deprecated).", };
033:
034:            /** Extracts reference documentation from the file(s) included.
035:             *
036:             * <p>See the usage string or execute <code>js2doc --help</code>
037:             * to see a list of options.
038:             *
039:             * @param args the command line arguments
040:             */
041:            public static void main(String args[]) throws IOException {
042:                js2doc(args, null, null, null);
043:            }
044:
045:            static final String[] runtimeOptionStrings = { "swf7", "swf8",
046:                    "swf9", "dhtml", "svg", "j2me" };
047:            static final Set runtimeOptions = new HashSet(Arrays
048:                    .asList(runtimeOptionStrings));
049:            // first element is the alias, subsequent elements are valid runtimes
050:            // e.g. js1 === dhtml || j2me || svg
051:            static final String[][] runtimeAliasStrings = {
052:                    { "as2", "swf7", "swf8", "swf9" }, { "as3", "swf9" },
053:                    { "js1", "dhtml" /*, "j2me", "svg" */} };
054:            static final List runtimeAliases = Arrays
055:                    .asList(runtimeAliasStrings);
056:            static final String[] buildOptionStrings = { "debug", "profile" };
057:            static final List buildOptions = Arrays.asList(buildOptionStrings);
058:
059:            /** This method implements the behavior described in main
060:             * but also returns an integer error code.
061:             */
062:            public static int js2doc(String args[], String logFile,
063:                    String outFileName, String outDir) throws IOException {
064:                logger = Logger.getRootLogger();
065:                // Configure logging
066:                logger.setLevel(Level.ERROR);
067:                PatternLayout layout = new PatternLayout("%m%n");
068:                logger.removeAllAppenders();
069:                if (logFile == null) {
070:                    logger.addAppender(new ConsoleAppender(layout));
071:                } else {
072:                    logger
073:                            .addAppender(new FileAppender(layout, logFile,
074:                                    false));
075:                }
076:
077:                List files = new Vector();
078:                boolean testMode = false;
079:                boolean reprocessOnly = false;
080:                String libraryID = null;
081:                String schemaFilename = null; // used for --test mode
082:
083:                for (int i = 0; i < args.length; i++) {
084:                    String arg = args[i].intern();
085:                    if (arg.startsWith("-")) {
086:                        boolean badform = false;
087:                        if (arg.equals("-v")) {
088:                            logger.setLevel(Level.ALL);
089:                        } else if (arg.equals("--test")) {
090:                            testMode = true;
091:                            if (i < args.length) {
092:                                i++;
093:                                schemaFilename = args[i];
094:                            } else
095:                                badform = true;
096:                        } else if (arg.equals("--reprocess")) {
097:                            reprocessOnly = true;
098:                        } else if (arg.equals("--out")) {
099:                            if (i < args.length) {
100:                                i++;
101:                                outFileName = args[i];
102:                            } else
103:                                badform = true;
104:                        } else if (arg.equals("--dir")) {
105:                            if (i < args.length) {
106:                                i++;
107:                                outDir = args[i];
108:                            } else
109:                                badform = true;
110:                        } else if (arg.equals("--libraryid")) {
111:                            if (i < args.length) {
112:                                i++;
113:                                libraryID = args[i];
114:                            } else
115:                                badform = true;
116:                        } else if (arg.equals("--help")) {
117:                            for (int j = 0; j < USAGE.length; j++) {
118:                                System.err.println(USAGE[j]);
119:                            }
120:                            return 0;
121:                        } else {
122:                            badform = true;
123:                        }
124:
125:                        if (badform == true) {
126:                            System.err.println("Bad arg: " + arg);
127:                            System.err
128:                                    .println("Usage: js2doc [OPTION]... file...");
129:                            System.err
130:                                    .println("Try `js2doc --help' for more information.");
131:                            return 1;
132:                        }
133:                    } else {
134:                        files.add(arg);
135:                    }
136:                }
137:
138:                if (testMode == true && outDir != null) {
139:                    System.err
140:                            .println("Both --test and --dir given; ignoring --dir.");
141:                }
142:
143:                for (Iterator iter = files.iterator(); iter.hasNext();) {
144:                    String sourceName = (String) iter.next();
145:                    if (testMode) {
146:                        System.err
147:                                .println("extracting docs and validating from "
148:                                        + sourceName);
149:                        boolean result = validateAndCompare(sourceName,
150:                                schemaFilename, libraryID, runtimeOptions,
151:                                runtimeAliases, buildOptions);
152:                        System.err.println("result: "
153:                                + (result ? "success" : "failure"));
154:                        if (result == false)
155:                            return 1;
156:                    } else if (reprocessOnly) {
157:                        if (files.size() > 1)
158:                            System.err
159:                                    .println("Reprocessing documentation within "
160:                                            + sourceName);
161:                        reprocess(sourceName, outFileName, outDir, libraryID,
162:                                runtimeOptions, runtimeAliases, buildOptions);
163:                    } else {
164:                        if (files.size() > 1)
165:                            System.err.println("Extracting documentation from "
166:                                    + sourceName);
167:                        process(sourceName, outFileName, outDir, libraryID,
168:                                runtimeOptions, runtimeAliases, buildOptions);
169:                    }
170:                }
171:                return 0;
172:            }
173:
174:            static public void process(String sourceName, String outFileName,
175:                    String outDir, String libraryID, Set runtimeOptions,
176:                    List runtimeAliases, List buildOptions) {
177:                File sourceFile = new File(sourceName);
178:                if (outFileName == null) {
179:                    if (outDir == null) {
180:                        outFileName = FileUtils.getBase(sourceName) + ".xml";
181:                    } else {
182:                        outFileName = outDir + File.separator
183:                                + FileUtils.getBase(sourceFile.getName())
184:                                + ".xml";
185:                    }
186:                }
187:                File scriptFile = new File(outFileName);
188:                try {
189:                    String scriptContents = FileUtils
190:                            .readFileString(sourceFile);
191:                    String script = "#file " + sourceName + "\n" + "#line 1\n"
192:                            + scriptContents;
193:                    // TODO [jgrandy 2007/01/11] pass in or retrieve JS2DOC_HOME
194:                    String sourceRoot = System.getProperty("JS2DOC_LIBROOT");
195:                    Document descr = JS2Doc.toXML(script, sourceFile,
196:                            sourceRoot, libraryID, runtimeOptions,
197:                            runtimeAliases, buildOptions);
198:
199:                    JS2DocUtils.xmlToFile(descr, outFileName);
200:
201:                } catch (IOException e) {
202:                    e.printStackTrace();
203:                    System.err.println("Couldn't read script file");
204:                }
205:            }
206:
207:            static public void reprocess(String sourceName, String outFileName,
208:                    String outDir, String libraryID, Set runtimeOptions,
209:                    List runtimeAliases, List buildOptions) {
210:                File sourceFile = new File(sourceName);
211:                if (outFileName == null) {
212:                    if (outDir == null) {
213:                        outFileName = FileUtils.getBase(sourceName) + ".xml";
214:                    } else {
215:                        outFileName = outDir + File.separator
216:                                + FileUtils.getBase(sourceFile.getName())
217:                                + ".xml";
218:                    }
219:                }
220:                File scriptFile = new File(outFileName);
221:                try {
222:                    String scriptContents = FileUtils
223:                            .readFileString(sourceFile);
224:
225:                    Document descr = ReprocessComments
226:                            .reprocess(scriptContents);
227:
228:                    JS2DocUtils.xmlToFile(descr, outFileName);
229:
230:                } catch (IOException e) {
231:                    e.printStackTrace();
232:                    System.err.println("Couldn't read script file");
233:                }
234:            }
235:
236:            static public boolean validateAndCompare(String sourceName,
237:                    String schemaName, String libraryID, Set runtimeOptions,
238:                    List runtimeAliases, List buildOptions) {
239:                boolean result = true;
240:                try {
241:                    File sourceFile = new File(sourceName);
242:                    String sourceContents = FileUtils
243:                            .readFileString(sourceFile);
244:                    String source = "#file " + sourceName + "\n" + "#line 1\n"
245:                            + sourceContents;
246:                    String sourceRoot = System.getProperty("JS2DOC_LIBROOT");
247:                    Document test = JS2Doc.toXML(source, sourceFile,
248:                            sourceRoot, libraryID, runtimeOptions,
249:                            runtimeAliases, buildOptions);
250:
251:                    String expectName = FileUtils.getBase(sourceName) + ".xml";
252:                    File expectFile = new File(expectName);
253:                    String expect = FileUtils.readFileString(expectFile);
254:
255:                } catch (java.io.IOException exc) {
256:                    result = false;
257:                    exc.printStackTrace();
258:                }
259:
260:                return result;
261:            }
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.