Skip to content

Commit

Permalink
Optimize converters
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Jun 21, 2015
1 parent 5e44807 commit 8f36bc3
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 372 deletions.
Expand Up @@ -2,7 +2,7 @@


import com.kodcu.other.Current; import com.kodcu.other.Current;
import com.kodcu.other.IOHelper; import com.kodcu.other.IOHelper;
import com.kodcu.service.convert.SlideConverter; import com.kodcu.service.convert.slide.SlideConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kodcu/controller/SlideController.java
Expand Up @@ -2,7 +2,7 @@


import com.kodcu.other.Current; import com.kodcu.other.Current;
import com.kodcu.other.IOHelper; import com.kodcu.other.IOHelper;
import com.kodcu.service.convert.SlideConverter; import com.kodcu.service.convert.slide.SlideConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/kodcu/other/ConverterResult.java
@@ -1,5 +1,7 @@
package com.kodcu.other; package com.kodcu.other;


import netscape.javascript.JSObject;

import java.util.Objects; import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;


Expand All @@ -11,6 +13,16 @@ public class ConverterResult {
private String backend; private String backend;
private String doctype; private String doctype;


public ConverterResult(JSObject jsObject) {
String rendered = (String) jsObject.getMember("rendered");
String backend = (String) jsObject.getMember("backend");
String doctype = (String) jsObject.getMember("doctype");

setRendered(rendered);
setBackend(backend);
setDoctype(doctype);
}

public void setRendered(String rendered) { public void setRendered(String rendered) {
this.rendered = rendered; this.rendered = rendered;
} }
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/kodcu/service/convert/LivePreviewService.java

This file was deleted.

This file was deleted.

Expand Up @@ -5,20 +5,18 @@
import com.kodcu.other.Current; import com.kodcu.other.Current;
import com.kodcu.other.IOHelper; import com.kodcu.other.IOHelper;
import com.kodcu.other.XMLHelper; import com.kodcu.other.XMLHelper;
import com.kodcu.service.MarkdownService; import com.kodcu.service.convert.markdown.MarkdownService;
import com.kodcu.service.ThreadService; import com.kodcu.service.ThreadService;
import com.kodcu.service.convert.DocumentConverter; import com.kodcu.service.convert.DocumentConverter;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import netscape.javascript.JSObject;
import org.joox.Match; import org.joox.Match;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;


import java.io.StringReader; import java.io.StringReader;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.function.Consumer; import java.util.function.Consumer;


import static org.joox.JOOX.$; import static org.joox.JOOX.$;
Expand All @@ -29,18 +27,22 @@
@Component @Component
public class DocBookConverter implements DocbookTraversable, DocumentConverter<String> { public class DocBookConverter implements DocbookTraversable, DocumentConverter<String> {


private Logger logger = LoggerFactory.getLogger(DocBookConverter.class);

private final Current current; private final Current current;
private final ThreadService threadService; private final ThreadService threadService;
private final MarkdownService markdownService; private final MarkdownService markdownService;
private final ApplicationController controller; private final ApplicationController controller;
private final DocbookValidator docbookValidator;
private final HtmlPane htmlPane; private final HtmlPane htmlPane;


@Autowired @Autowired
public DocBookConverter(final Current current, ThreadService threadService, MarkdownService markdownService, ApplicationController controller, HtmlPane htmlPane) { public DocBookConverter(final Current current, ThreadService threadService, MarkdownService markdownService, ApplicationController controller, DocbookValidator docbookValidator, HtmlPane htmlPane) {
this.current = current; this.current = current;
this.threadService = threadService; this.threadService = threadService;
this.markdownService = markdownService; this.markdownService = markdownService;
this.controller = controller; this.controller = controller;
this.docbookValidator = docbookValidator;
this.htmlPane = htmlPane; this.htmlPane = htmlPane;
} }


Expand All @@ -53,45 +55,42 @@ public void convert(boolean askPath, Consumer<String>... nextStep) {
Path currentTabPath = current.currentPath().get(); Path currentTabPath = current.currentPath().get();
Path currentTabPathDir = currentTabPath.getParent(); Path currentTabPathDir = currentTabPath.getParent();


StringBuffer stringBuffer = new StringBuffer(); String asciidoc = current.currentEditorValue();

// DocbookTraversable.super.traverseLines(Arrays.asList(current.currentEditorValue().split("\\r?\\n")), stringBuffer, currentTabPathDir);


String text = current.currentEditorValue(); threadService.runActionLater(() -> {


markdownService.convert(text, asciidoc -> { String rendered = htmlPane.convertDocbook(asciidoc).getRendered();
threadService.runActionLater(() -> {


String rendered = htmlPane.convertDocbook(asciidoc, true); docbookValidator.validateDocbook(rendered);


rendered = rendered.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.1\" encoding=\"UTF-8\"?>"); rendered = rendered.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.1\" encoding=\"UTF-8\"?>");


StringReader bookReader = new StringReader(rendered); StringReader bookReader = new StringReader(rendered);
Match rootDocument = IOHelper.$(new InputSource(bookReader)); Match rootDocument = IOHelper.$(new InputSource(bookReader));
bookReader.close(); bookReader.close();


// // makes figure centering // // makes figure centering
rootDocument.find("figure").find("imagedata").attr("align", "center"); rootDocument.find("figure").find("imagedata").attr("align", "center");


// remove callout's duplicated refs and pick last // remove callout's duplicated refs and pick last
rootDocument.find("callout").forEach(elem -> { rootDocument.find("callout").forEach(elem -> {
String arearefs = $(elem).attr("arearefs"); String arearefs = $(elem).attr("arearefs");
String[] cos = arearefs.split(" "); String[] cos = arearefs.split(" ");
if (cos.length > 1) if (cos.length > 1)
$(elem).attr("arearefs", cos[cos.length - 1]); $(elem).attr("arearefs", cos[cos.length - 1]);
}); });


String result = XMLHelper.nodeToString(rootDocument.document(), false); String result = XMLHelper.nodeToString(rootDocument.document(), false);
result = result.replace("00HEADER00COLON00", ":"); result = result.replace("00HEADER00COLON00", ":");


for (Consumer<String> step : nextStep) { for (Consumer<String> step : nextStep) {
step.accept(result); step.accept(result);
} }


// htmlPane.stopProgressBar(); // htmlPane.stopProgressBar();

});
}); });
} }




} }

This file was deleted.

0 comments on commit 8f36bc3

Please sign in to comment.