1 changed files with 0 additions and 46 deletions
@ -1,46 +0,0 @@ |
|||||
package com.example.datacollect.command; |
|
||||
|
|
||||
import com.example.datacollect.model.Article; |
|
||||
import com.example.datacollect.view.ConsoleView; |
|
||||
import java.util.List; |
|
||||
import java.util.regex.Pattern; |
|
||||
|
|
||||
public class CrawlCommand implements Command { |
|
||||
private static final String URL_REGEX = "^(https?|ftp)://[\\w\\-]+(\\.[\\w\\-]+)+([:\\d+])?(\\/[^\\s]*)?$"; |
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(URL_REGEX); |
|
||||
|
|
||||
private final ConsoleView view; |
|
||||
|
|
||||
public CrawlCommand(ConsoleView view) { |
|
||||
this.view = view; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public String getName() { |
|
||||
return "crawl"; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public void execute(String[] args, List<Article> articles) { |
|
||||
if (args.length < 2) { |
|
||||
view.printError("Usage: crawl <url>"); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
String url = args[1]; |
|
||||
if (!isValidUrl(url)) { |
|
||||
view.printError("Invalid URL format: " + url); |
|
||||
view.printInfo("Please enter a valid URL (e.g., http://example.com)"); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
view.printInfo("Stub: would crawl " + url); |
|
||||
} |
|
||||
|
|
||||
private boolean isValidUrl(String url) { |
|
||||
if (url == null || url.isEmpty()) { |
|
||||
return false; |
|
||||
} |
|
||||
return URL_PATTERN.matcher(url).matches(); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue