1 package net.javacoding.jspider.tool.util; 2 3 import net.javacoding.jspider.tool.Tool; 4 import net.javacoding.jspider.tool.impl.*; 5 6 9 public class ToolFactory { 10 11 public static Tool createTool ( String [] args ) { 12 Tool tool = null; 13 String toolName = getToolName ( args ); 14 if( toolName != null ) { 15 tool = getTool ( toolName ); 16 } 17 return tool; 18 } 19 20 protected static String getToolName ( String [] args ) { 21 String toolName = null; 22 for (int i = 0; i < args.length; i++) { 23 String arg = args[i]; 24 if ( ! arg.startsWith("-") ) { 25 toolName = arg; 26 break; 27 } 28 } 29 return toolName; 30 } 31 32 protected static Tool getTool ( String name ) { 33 Tool tool = null; 34 35 if ( "headers".equals ( name ) ) { 36 tool = new HeadersTool(); 37 } else if ( "download".equals ( name ) ) { 38 tool = new DownloadTool(); 39 } else if ( "info".equals ( name ) ) { 40 tool = new InfoTool(); 41 } else if ( "fetch".equals ( name ) ) { 42 tool = new FetchTool(); 43 } else if ( "findlinks".equals ( name ) ) { 44 tool = new FindLinksTool(); 45 } else if ( "email".equals ( name ) ) { 46 tool = new EMailTool(); 47 } 48 49 return tool; 50 } 51 52 } 53 | Popular Tags |