| 1 package net.javacoding.jspider; 2 3 import net.javacoding.jspider.core.impl.CLI; 4 import net.javacoding.jspider.core.util.config.ConfigurationFactory; 5 import net.javacoding.jspider.tool.*; 6 import net.javacoding.jspider.tool.util.*; 7 8 import java.net.URL ; 9 10 13 public class JSpiderTool { 14 15 public static Tool tool; 16 protected Flags flags; 17 protected Parameters params; 18 protected String url; 19 20 JSpiderTool(String url, Flags flags, Parameters params, Tool tool) { 21 this.flags = flags; 22 this.params = params; 23 this.tool = tool; 24 this.url = url; 25 } 26 27 void execute() throws Exception { 28 ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_TOOL); 29 JSpider jspider = new JSpider(new URL (url)); 30 jspider.start(); 31 } 32 33 34 public static void main(String [] args) throws Exception { 35 36 if (args.length < 2) { 37 38 CLI.printSignature(); 39 System.out.println(); 40 System.out.println("Usage: jspider-tool [toolName] [URL] [params...]"); 41 42 } else { 43 44 Flags flags = FlagsFactory.createFlags(args); 45 Parameters params = ParametersFactory.createParameters(args); 46 Tool tool = ToolFactory.createTool(args); 47 String url = URLFactory.createURL(args); 48 49 if (tool != null) { 50 51 int expectedParams = tool.getParameterCount(); 52 int actualParams = params.getValues().length; 53 54 if (expectedParams == actualParams) { 55 tool.setParameters(params); 56 JSpiderTool jspiderTool = new JSpiderTool(url, flags, params, tool); 57 jspiderTool.execute(); 58 } else { 59 System.out.println("Usage: jspider-tool " + tool.getName() + " [url] " + tool.getUsage()); 60 } 61 } else { 62 System.err.println("Tool with specified name not found"); 63 } 64 } 65 } 66 67 } 68 | Popular Tags |