Source Code Cross Referenced for CommandLineParser.java in  » Web-Crawler » heritrix » org » archive » crawler » 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 » Web Crawler » heritrix » org.archive.crawler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* CommandLineParser
002:         *
003:         * Created on Feb 2, 2004
004:         *
005:         * Copyright (C) 2004 Internet Archive.
006:         *
007:         * This file is part of the Heritrix web crawler (crawler.archive.org).
008:         *
009:         * Heritrix is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU Lesser Public License as published by
011:         * the Free Software Foundation; either version 2.1 of the License, or
012:         * any later version.
013:         *
014:         * Heritrix is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         * GNU Lesser Public License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser Public License
020:         * along with Heritrix; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
022:         */
023:        package org.archive.crawler;
024:
025:        import java.io.PrintWriter;
026:        import java.util.List;
027:
028:        import org.apache.commons.cli.CommandLine;
029:        import org.apache.commons.cli.HelpFormatter;
030:        import org.apache.commons.cli.Option;
031:        import org.apache.commons.cli.Options;
032:        import org.apache.commons.cli.ParseException;
033:        import org.apache.commons.cli.PosixParser;
034:        import org.apache.commons.cli.UnrecognizedOptionException;
035:
036:        /**
037:         * Print Heritrix command-line usage message.
038:         *
039:         * @author stack
040:         * @version $Id: CommandLineParser.java 4551 2006-08-29 00:47:56Z stack-sf $
041:         */
042:        public class CommandLineParser {
043:            private static final String USAGE = "Usage: ";
044:            private static final String NAME = "heritrix";
045:            private Options options = null;
046:            private CommandLine commandLine = null;
047:            private PrintWriter out = null;
048:            private String version = null;
049:
050:            /**
051:             * Block default construction.
052:             *
053:             */
054:            private CommandLineParser() {
055:                super ();
056:            }
057:
058:            /**
059:             * Constructor.
060:             *
061:             * @param args Command-line arguments to process.
062:             * @param out PrintStream to write on.
063:             * @param version Heritrix version
064:             *
065:             * @throws ParseException Failied parse of command line.
066:             */
067:            public CommandLineParser(String[] args, PrintWriter out,
068:                    String version) throws ParseException {
069:                super ();
070:
071:                this .out = out;
072:                this .version = version;
073:
074:                this .options = new Options();
075:                this .options.addOption(new Option("h", "help", false,
076:                        "Prints this message and exits."));
077:                this .options
078:                        .addOption(new Option(
079:                                "b",
080:                                "bind",
081:                                true,
082:                                "Comma-separated list of IP addresses or hostnames for web server "
083:                                        + "to listen on.  Set to / to listen on all available\nnetwork "
084:                                        + "interfaces.  Default is 127.0.0.1."));
085:                this .options.addOption(new Option("p", "port", true,
086:                        "Port to run web user interface on.  Default: 8080."));
087:                this .options
088:                        .addOption(new Option(
089:                                "a",
090:                                "admin",
091:                                true,
092:                                "Login and password for web user interface administration. "
093:                                        + "Required (unless passed via the 'heritrix.cmdline.admin'\n"
094:                                        + "system property).  Pass value of the form 'LOGIN:PASSWORD'."));
095:                this .options
096:                        .addOption(new Option("r", "run", false,
097:                                "Put heritrix into run mode. If ORDER.XML begin crawl."));
098:                this .options.addOption(new Option("n", "nowui", false,
099:                        "Put heritrix into run mode and begin crawl using ORDER.XML."
100:                                + " Do not put up web user interface."));
101:                Option option = new Option(
102:                        "s",
103:                        "selftest",
104:                        true,
105:                        "Run the integrated selftests. Pass test name to test it only"
106:                                + " (Case sensitive: E.g. pass 'Charset' to run charset selftest).");
107:                option.setOptionalArg(true);
108:                this .options.addOption(option);
109:
110:                PosixParser parser = new PosixParser();
111:                try {
112:                    this .commandLine = parser.parse(this .options, args, false);
113:                } catch (UnrecognizedOptionException e) {
114:                    usage(e.getMessage(), 1);
115:                }
116:            }
117:
118:            /**
119:             * Print usage then exit.
120:             */
121:            public void usage() {
122:                usage(0);
123:            }
124:
125:            /**
126:             * Print usage then exit.
127:             *
128:             * @param exitCode
129:             */
130:            public void usage(int exitCode) {
131:                usage(null, exitCode);
132:            }
133:
134:            /**
135:             * Print message then usage then exit.
136:             *
137:             * The JVM exits inside in this method.
138:             *
139:             * @param message Message to print before we do usage.
140:             * @param exitCode Exit code to use in call to System.exit.
141:             */
142:            public void usage(String message, int exitCode) {
143:                outputAndExit(message, true, exitCode);
144:            }
145:
146:            /**
147:             * Print message and then exit.
148:             *
149:             * The JVM exits inside in this method.
150:             *
151:             * @param message Message to print before we do usage.
152:             * @param exitCode Exit code to use in call to System.exit.
153:             */
154:            public void message(String message, int exitCode) {
155:                outputAndExit(message, false, exitCode);
156:            }
157:
158:            /**
159:             * Print out optional message an optional usage and then exit.
160:             *
161:             * Private utility method.  JVM exits from inside in this method.
162:             *
163:             * @param message Message to print before we do usage.
164:             * @param doUsage True if we are to print out the usage message.
165:             * @param exitCode Exit code to use in call to System.exit.
166:             */
167:            private void outputAndExit(String message, boolean doUsage,
168:                    int exitCode) {
169:                if (message != null) {
170:                    this .out.println(message);
171:                }
172:
173:                if (doUsage) {
174:                    HeritrixHelpFormatter formatter = new HeritrixHelpFormatter();
175:                    formatter.printHelp(this .out, 80, NAME, "Options:",
176:                            this .options, 1, 2, "Arguments:", false);
177:                    this .out.println(" ORDER.XML       Crawl order to run.\n");
178:                }
179:
180:                // Close printwriter so stream gets flushed.
181:                this .out.close();
182:                System.exit(exitCode);
183:            }
184:
185:            /**
186:             * @return Options passed on the command line.
187:             */
188:            public Option[] getCommandLineOptions() {
189:                return this .commandLine.getOptions();
190:            }
191:
192:            /**
193:             * @return Arguments passed on the command line.
194:             */
195:            public List getCommandLineArguments() {
196:                return this .commandLine.getArgList();
197:            }
198:
199:            /**
200:             * @return Command line.
201:             */
202:            public CommandLine getCommandLine() {
203:                return this .commandLine;
204:            }
205:
206:            /**
207:             * @return Returns the version.
208:             */
209:            public String getVersion() {
210:                return this .version;
211:            }
212:
213:            /**
214:             * Override so can customize usage output.
215:             *
216:             * @author stack
217:             * @version $Id: CommandLineParser.java 4551 2006-08-29 00:47:56Z stack-sf $
218:             */
219:            public class HeritrixHelpFormatter extends HelpFormatter {
220:                public HeritrixHelpFormatter() {
221:                    super ();
222:                }
223:
224:                public void printUsage(PrintWriter pw, int width,
225:                        String cmdLineSyntax) {
226:                    out.println(USAGE + NAME + " --help");
227:                    out.println(USAGE + NAME + " --nowui ORDER.XML");
228:                    out.println(USAGE + NAME + " [--port=#]"
229:                            + " [--run] [--bind=IP,IP...] "
230:                            + "--admin=LOGIN:PASSWORD \\\n\t[ORDER.XML]");
231:                    out.println(USAGE + NAME
232:                            + " [--port=#] --selftest[=TESTNAME]");
233:                    out.println("Version: " + getVersion());
234:                }
235:
236:                public void printUsage(PrintWriter pw, int width, String app,
237:                        Options options) {
238:                    this.printUsage(pw, width, app);
239:                }
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.