-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to set proxy for HtmlUnit
- Loading branch information
Showing
5 changed files
with
217 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...com/github/hronom/scrape/dat/rooms/view/controllers/BrowserEngineSelectionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.hronom.scrape.dat.rooms.view.controllers; | ||
|
||
import com.github.hronom.scrape.dat.rooms.view.views.ScrapeView; | ||
|
||
import java.awt.event.ItemEvent; | ||
import java.awt.event.ItemListener; | ||
|
||
public class BrowserEngineSelectionController { | ||
private final ScrapeView scrapeView; | ||
|
||
public BrowserEngineSelectionController(ScrapeView scrapeViewArg) { | ||
scrapeView = scrapeViewArg; | ||
if (scrapeView.getSelectedBrowserEngine().equals(ScrapeView.BrowserEngine.HtmlUnit)) { | ||
scrapeView.setProxyHostTextFieldEnabled(true); | ||
scrapeView.setProxyPortTextFieldEnabled(true); | ||
} else { | ||
scrapeView.setProxyHostTextFieldEnabled(false); | ||
scrapeView.setProxyPortTextFieldEnabled(false); | ||
} | ||
|
||
scrapeView.addBrowserEngineItemListener(new ItemListener() { | ||
@Override | ||
public void itemStateChanged(ItemEvent e) { | ||
if (e.getStateChange() == ItemEvent.SELECTED && e.getItem().equals(ScrapeView.BrowserEngine.HtmlUnit)) { | ||
scrapeView.setProxyHostTextFieldEnabled(true); | ||
scrapeView.setProxyPortTextFieldEnabled(true); | ||
} else { | ||
scrapeView.setProxyHostTextFieldEnabled(false); | ||
scrapeView.setProxyPortTextFieldEnabled(false); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../java/com/github/hronom/scrape/dat/rooms/view/controllers/WebsiteUrlTypingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.hronom.scrape.dat.rooms.view.controllers; | ||
|
||
import com.github.hronom.scrape.dat.rooms.view.views.ScrapeView; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import javax.swing.event.DocumentEvent; | ||
import javax.swing.event.DocumentListener; | ||
import javax.swing.text.BadLocationException; | ||
|
||
public class WebsiteUrlTypingController { | ||
private static final Logger logger = LogManager.getLogger(); | ||
|
||
private final ScrapeView scrapeView; | ||
|
||
public WebsiteUrlTypingController(ScrapeView scrapeViewArg) { | ||
scrapeView = scrapeViewArg; | ||
scrapeView.addWebsiteUrlDocumentListener(new DocumentListener() { | ||
@Override | ||
public void insertUpdate(DocumentEvent e) { | ||
try { | ||
String str = e.getDocument().getText(0, e.getDocument().getLength()); | ||
if (str.contains("motel6.com")) { | ||
scrapeView.selectParser(ScrapeView.Parser.Motel6); | ||
} else if (str.contains("redroof.com")) { | ||
scrapeView.selectParser(ScrapeView.Parser.RedRoof); | ||
} else if (str.contains("redlion.com")) { | ||
scrapeView.selectParser(ScrapeView.Parser.RedLion); | ||
} else if (str.contains("ebookers.com")) { | ||
scrapeView.selectParser(ScrapeView.Parser.ebookers); | ||
} | ||
} catch (BadLocationException exception) { | ||
logger.error(exception); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeUpdate(DocumentEvent e) { | ||
} | ||
|
||
@Override | ||
public void changedUpdate(DocumentEvent e) { | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.