diff --git a/pom.xml b/pom.xml
index 8e0560a..694b8e2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.github.hronom
scrape-dat-website
- 1.0.2
+ 1.0.3
jar
scrape-dat-website
diff --git a/src/main/java/com/github/hronom/scrape/dat/website/ScrapeDatWebsiteApp.java b/src/main/java/com/github/hronom/scrape/dat/website/ScrapeDatWebsiteApp.java
index 9b2e0e5..5d5d664 100644
--- a/src/main/java/com/github/hronom/scrape/dat/website/ScrapeDatWebsiteApp.java
+++ b/src/main/java/com/github/hronom/scrape/dat/website/ScrapeDatWebsiteApp.java
@@ -7,11 +7,32 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import java.io.File;
+
public class ScrapeDatWebsiteApp {
private static final Logger logger = LogManager.getLogger();
public static void main(String[] args) {
logger.info(ScrapeDatWebsiteApp.class.getSimpleName());
+ // Total number of processors or cores available to the JVM.
+ logger.info("Available processors (cores): " + Runtime.getRuntime().availableProcessors());
+ // Total amount of free memory available to the JVM.
+ logger.info("Free memory (bytes): " + Runtime.getRuntime().freeMemory());
+ // This will return Long.MAX_VALUE if there is no preset limit.
+ long maxMemory = Runtime.getRuntime().maxMemory();
+ // Maximum amount of memory the JVM will attempt to use.
+ logger.info("Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
+ // Total memory currently in use by the JVM.
+ logger.info("Total memory (bytes): " + Runtime.getRuntime().totalMemory());
+ // Get a list of all filesystem roots on this system.
+ File[] roots = File.listRoots();
+ // For each filesystem root, print some info.
+ for (File root : roots) {
+ logger.info("File system root: " + root.getAbsolutePath());
+ logger.info("Total space (bytes): " + root.getTotalSpace());
+ logger.info("Free space (bytes): " + root.getFreeSpace());
+ logger.info("Usable space (bytes): " + root.getUsableSpace());
+ }
ScrapeView scrapeView = new ScrapeView();
new ScrapeButtonController(scrapeView);
diff --git a/src/main/java/com/github/hronom/scrape/dat/website/controllers/ScrapeButtonController.java b/src/main/java/com/github/hronom/scrape/dat/website/controllers/ScrapeButtonController.java
index fa0ac01..e22d0be 100644
--- a/src/main/java/com/github/hronom/scrape/dat/website/controllers/ScrapeButtonController.java
+++ b/src/main/java/com/github/hronom/scrape/dat/website/controllers/ScrapeButtonController.java
@@ -53,43 +53,55 @@ public ActionListener createScrapeButtonActionListener() {
public void actionPerformed(ActionEvent event) {
Executors.newSingleThreadExecutor().submit(new Runnable() {
public void run() {
+ logger.info("Start processing...");
+ long beginTime = System.currentTimeMillis();
+
+ // Output input parameters.
if (!scrapeView.getWebsiteUrl().isEmpty() &&
!scrapeView.getSelector().isEmpty()) {
logger.info("Input parameters: " +
scrapeView.getWebsiteUrl() + ", " +
scrapeView.getSelector());
}
- long beginTime = System.currentTimeMillis();
+ // Disable fields in view.
scrapeView.setWebsiteUrlTextFieldEnabled(false);
scrapeView.setSelectorTextFieldEnabled(false);
scrapeView.setScrapeButtonEnabled(false);
scrapeView.setWorkInProgress(true);
- try {
- scrapeView.setOutput("");
+ scrapeView.setOutput("");
+ // Process.
+ try {
URL url = new URL(scrapeView.getWebsiteUrl());
+ logger.info("Requesting page...");
HtmlPage page = webClient.getPage(url);
+ logger.info("Requesting of page completed.");
+
+ logger.info("View page as XML");
String xml = page.asXml();
// Unescape html.
+ logger.info("Unescape html");
xml = StringEscapeUtils.unescapeHtml4(xml);
+ logger.info("Get selector");
String selector = scrapeView.getSelector();
if (!xml.isEmpty() && !selector.isEmpty()) {
+ logger.info("Parse XML");
Document doc = Jsoup.parse(xml);
Elements selectedElements = doc.select(selector);
+
if (!selectedElements.isEmpty()) {
+ logger.info("Parse extracted elements");
StringBuilder sb = new StringBuilder();
-
for (Element element : selectedElements) {
String body = element.html();
sb.append(body);
sb.append("\n");
sb.append("\n");
}
-
scrapeView.setOutput(sb.toString());
}
}
@@ -97,8 +109,10 @@ public void run() {
logger.error(e);
}
+ logger.info("Close WebClient.");
webClient.close();
+ // Enable fields in view.
scrapeView.setWorkInProgress(false);
scrapeView.setScrapeButtonEnabled(true);
scrapeView.setSelectorTextFieldEnabled(true);
@@ -106,6 +120,7 @@ public void run() {
long endTime = System.currentTimeMillis();
logger.info("Process time: " + (endTime - beginTime) + " ms.");
+ logger.info("Processing complete.");
}
});
}
diff --git a/src/main/java/com/github/hronom/scrape/dat/website/views/ScrapeView.java b/src/main/java/com/github/hronom/scrape/dat/website/views/ScrapeView.java
index 8b773a8..8c49b9d 100644
--- a/src/main/java/com/github/hronom/scrape/dat/website/views/ScrapeView.java
+++ b/src/main/java/com/github/hronom/scrape/dat/website/views/ScrapeView.java
@@ -115,7 +115,7 @@ public ScrapeView() {
{
progressBar = new JProgressBar();
- progressBar.setString("Working...");
+ progressBar.setString("Working, please wait...");
progressBar.setStringPainted(true);
progressBar.setIndeterminate(true);
progressBar.setVisible(false);