1 changed files with 0 additions and 42 deletions
@ -1,42 +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)://[^\\s/$.?#].[^\\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); |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
view.printInfo("Stub: would crawl " + url); |
|
||||
} |
|
||||
|
|
||||
private boolean isValidUrl(String url) { |
|
||||
return url != null && URL_PATTERN.matcher(url).matches(); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue