Skip to content

Commit

Permalink
Improves Parser api
Browse files Browse the repository at this point in the history
  • Loading branch information
Trundicho committed Oct 20, 2018
1 parent 19f1d0f commit 67444bc
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package de.trundicho.warp.reader.core.view.api;


import de.trundicho.warp.reader.core.view.api.widgets.InputTextWidget;

public interface WebsiteParserAndWarper {

void parseWebsiteAndStartWarping(InputTextWidget textArea);
void parseWebsiteAndStartWarping(String url);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import de.trundicho.warp.reader.core.controller.WarpInitializer;
import de.trundicho.warp.reader.core.view.api.WebsiteParserAndWarper;
import de.trundicho.warp.reader.core.view.api.widgets.InputTextWidget;

public final class TextAreaParser {

Expand All @@ -15,14 +14,12 @@ public TextAreaParser(WarpInitializer warpInitializer,
this.websiteParserAndWarper = websiteParserAndWarper;
}

public void parseInputTextAndStartWarping(InputTextWidget textArea) {
String text = textArea.getText();
public void parseInputTextAndStartWarping(String text) {
if (text != null && !text.isEmpty()) {
if (text.startsWith("http")) {
websiteParserAndWarper.parseWebsiteAndStartWarping(textArea);
websiteParserAndWarper.parseWebsiteAndStartWarping(text);
} else {
warpInitializer.initAndStartWarping(text);
textArea.setText("");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ private void initUiAndRegisterListeners(WarpReaderViewModel uiModel, WpmSpeedExc
WarpInitializer warpTextAreaInitializer = new WarpInitializer(warpTextLabelUpdater, speedModel,
playModeModel, speedWeightModel, textSplitter, playModel, durationWidget, warpTimerFactory);

WebsiteParserAndWarper websiteParserAndWarper = new WebsiteParserAndWarperImpl(warpTextAreaInitializer);
WebsiteParserAndWarper websiteParserAndWarper = new WebsiteParserAndWarperImpl(warpTextAreaInitializer, inputTextWidget);
TextAreaParser textAreaParser = new TextAreaParser(warpTextAreaInitializer, websiteParserAndWarper);
Timer textAreaParserTimer = new Timer() {

@Override
public void run() {
textAreaParser.parseInputTextAndStartWarping(inputTextWidget);
textAreaParser.parseInputTextAndStartWarping(inputTextWidget.getText());
inputTextWidget.setText("");
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
public class WebsiteParserAndWarperImpl implements WebsiteParserAndWarper {
private final TextFromWebUrlParserServiceAsync boilerplateService = GWT.create(TextFromWebUrlParserService.class);
private final WarpInitializer warpTextAreaInitializer;
private final InputTextWidget textArea;

public WebsiteParserAndWarperImpl(WarpInitializer warpTextAreaInitializer) {
public WebsiteParserAndWarperImpl(WarpInitializer warpTextAreaInitializer, InputTextWidget textArea) {
this.warpTextAreaInitializer = warpTextAreaInitializer;
this.textArea = textArea;
}

@Override
public void parseWebsiteAndStartWarping(InputTextWidget textArea) {
String text = textArea.getText();
public void parseWebsiteAndStartWarping(String text) {
AsyncCallback<String> boilerpipeAsyncCallback = new BoilerpipeAsyncCallback(textArea, text,
warpTextAreaInitializer);
boilerplateService.parseTextFromWebsite(text, boilerpipeAsyncCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ private void initUiAndRegisterListeners(WarpReaderViewModel uiModel, WpmSpeedExc
WarpInitializer warpInitializer = new WarpInitializer(warpTextLabelUpdater, speedModel,
playModeModel, speedWeightModel, textSplitter, playModel, durationWidget, warpTimerFactory);

TextAreaParserTimerBuilder textAreaParserTimerBuilder = new TextAreaParserTimerBuilder(warpInitializer, i18nLocalizer);
TextAreaParserTimerBuilder textAreaParserTimerBuilder = new TextAreaParserTimerBuilder(warpInitializer, i18nLocalizer,
inputTextWidget);
Timer textAreaParserTimer = textAreaParserTimerBuilder.buildTextAreaParserTimer(inputTextWidget);
textAreaParserTimer.scheduleRepeatable(TEXT_AREA_PARSER_DELAY);
addExtension(textAreaParserTimer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ public class TextAreaParserTimerBuilder {

private final TextAreaParser textAreaParser;

public TextAreaParserTimerBuilder(WarpInitializer warpInitializer, I18nLocalizer i18nLocalizer) {
WebsiteParserAndWarper websiteParserAndWarper = new WebsiteParserAndWarperImpl(warpInitializer, i18nLocalizer);
public TextAreaParserTimerBuilder(WarpInitializer warpInitializer, I18nLocalizer i18nLocalizer,
InputTextWidget inputTextWidget) {
WebsiteParserAndWarper websiteParserAndWarper = new WebsiteParserAndWarperImpl(warpInitializer, i18nLocalizer,
inputTextWidget);
this.textAreaParser = new TextAreaParser(warpInitializer, websiteParserAndWarper);
}

public Timer buildTextAreaParserTimer(InputTextWidget inputTextWidget) {
Timer textAreaParserTimer = new Timer();
textAreaParserTimer.run(() ->
textAreaParser.parseInputTextAndStartWarping(inputTextWidget));
{
textAreaParser.parseInputTextAndStartWarping(inputTextWidget.getText());
inputTextWidget.setText("");
}
);
return textAreaParserTimer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ public class WebsiteParserAndWarperImpl implements WebsiteParserAndWarper {
private final TextFromWebUrlParserService boilerplateService;
private final WarpInitializer warpInitializer;
private final I18nLocalizer i18nLocalizer;
private final InputTextWidget textArea;
private final String errorText;

public WebsiteParserAndWarperImpl(WarpInitializer warpInitializer, I18nLocalizer i18nLocalizer) {
public WebsiteParserAndWarperImpl(WarpInitializer warpInitializer, I18nLocalizer i18nLocalizer,
InputTextWidget textArea) {
this.warpInitializer = warpInitializer;
this.i18nLocalizer = i18nLocalizer;
this.textArea = textArea;
this.errorText = "Error occured: Please try other URL.";
this.boilerplateService = new TextFromWebUrlParserService();
}

public void parseWebsiteAndStartWarping(InputTextWidget textArea) {
String text = textArea.getText();
public void parseWebsiteAndStartWarping(String text) {
try {
final String textFromWebsite = boilerplateService.parseTextFromWebsite(text);
boolean error = false;
Expand Down

0 comments on commit 67444bc

Please sign in to comment.