Skip to content

Commit ab68c6c

Browse files
committed
upgrade herold
1 parent b24dbbf commit ab68c6c

4 files changed

Lines changed: 31 additions & 32 deletions

File tree

‎apache-fop/pom.xml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@
101101
<dependency>
102102
<groupId>org.dbdoclet</groupId>
103103
<artifactId>herold</artifactId>
104-
<version>6.1.0</version>
105-
<scope>system</scope>
106-
<systemPath>${basedir}/src/test/resources/jars/herold.jar</systemPath>
104+
<version>8.0.4</version>
107105
</dependency>
108106

109107
<dependency>

‎apache-fop/src/test/java/org/baeldung/java/ApacheFOPConvertHTMLIntegrationTest.java‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
import org.apache.fop.apps.Fop;
2020
import org.apache.fop.apps.FopFactory;
2121
import org.apache.xmlgraphics.util.MimeConstants;
22-
import org.dbdoclet.trafo.html.docbook.DocBookTransformer;
22+
import org.dbdoclet.trafo.html.docbook.HtmlDocBookTrafo;
2323
import org.dbdoclet.trafo.script.Script;
2424
import org.junit.Test;
2525
import org.w3c.dom.Document;
2626
import org.w3c.tidy.Tidy;
2727

2828
public class ApacheFOPConvertHTMLIntegrationTest {
29-
private String inputFile = "src/test/resources/input.html";
30-
private String style = "src/test/resources/xhtml2fo.xsl";
31-
private String style1 = "src/test/resources/docbook-xsl/fo/docbook.xsl";
32-
private String output_jtidy = "src/test/resources/output_jtidy.pdf";
33-
private String output_html2fo = "src/test/resources/output_html2fo.pdf";
34-
private String output_herold = "src/test/resources/output_herold.pdf";
35-
private String foFile = "src/test/resources/input.fo";
36-
private String xmlFile = "src/test/resources/input.xml";
29+
private final String inputFile = "src/test/resources/input.html";
30+
private final String style = "src/test/resources/xhtml2fo.xsl";
31+
private final String style1 = "src/test/resources/docbook-xsl/fo/docbook.xsl";
32+
private final String output_jtidy = "src/test/resources/output_jtidy.pdf";
33+
private final String output_html2fo = "src/test/resources/output_html2fo.pdf";
34+
private final String output_herold = "src/test/resources/output_herold.pdf";
35+
private final String foFile = "src/test/resources/input.fo";
36+
private final String xmlFile = "src/test/resources/input.xml";
3737

3838
@Test
3939
public void whenTransformHTMLToPDFUsingJTidy_thenCorrect() throws Exception {
@@ -114,8 +114,9 @@ private Document fromXMLFileToFO() throws Exception {
114114

115115
private void fromHTMLTOXMLUsingHerold() throws Exception {
116116
final Script script = new Script();
117-
final DocBookTransformer transformer = new DocBookTransformer();
118-
transformer.setScript(script);
119-
transformer.convert(new FileInputStream(inputFile), new FileOutputStream(xmlFile));
117+
final HtmlDocBookTrafo transformer = new HtmlDocBookTrafo();
118+
transformer.setInputStream(new FileInputStream(inputFile));
119+
transformer.setOutputStream(new FileOutputStream(xmlFile));
120+
transformer.transform(script);
120121
}
121122
}

‎apache-fop/src/test/java/org/baeldung/java/ApacheFOPHeroldLiveTest.java‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.IOException;
1111
import java.io.InputStream;
1212
import java.io.OutputStream;
13+
import java.net.HttpURLConnection;
1314
import java.net.URL;
1415

1516
import javax.xml.transform.Result;
@@ -25,19 +26,15 @@
2526
import org.apache.fop.apps.FopFactory;
2627
import org.apache.xmlgraphics.util.MimeConstants;
2728
import org.dbdoclet.trafo.TrafoScriptManager;
28-
import org.dbdoclet.trafo.html.docbook.DocBookTransformer;
29+
import org.dbdoclet.trafo.html.docbook.HtmlDocBookTrafo;
2930
import org.dbdoclet.trafo.script.Script;
3031
import org.junit.Test;
3132
import org.w3c.dom.Document;
3233

3334
public class ApacheFOPHeroldLiveTest {
34-
private String[] inputUrls = {// @formatter:off
35-
"http://www.baeldung.com/2011/10/20/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1/",
36-
"http://www.baeldung.com/2011/10/25/building-a-restful-web-service-with-spring-3-1-and-java-based-configuration-part-2/",
37-
"http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/",
38-
"http://www.baeldung.com/spring-security-basic-authentication",
39-
"http://www.baeldung.com/spring-security-digest-authentication",
40-
"http://www.baeldung.com/2011/11/20/basic-and-digest-authentication-for-a-restful-service-with-spring-security-3-1/",
35+
private final String[] inputUrls = {// @formatter:off
36+
// "http://www.baeldung.com/spring-security-basic-authentication",
37+
"http://www.baeldung.com/spring-security-digest-authentication"
4138
//"http://www.baeldung.com/spring-httpmessageconverter-rest",
4239
//"http://www.baeldung.com/2011/11/06/restful-web-service-discoverability-part-4/",
4340
//"http://www.baeldung.com/2011/11/13/rest-service-discoverability-with-spring-part-5/",
@@ -49,10 +46,10 @@ public class ApacheFOPHeroldLiveTest {
4946
//"http://www.baeldung.com/2013/01/18/testing-rest-with-multiple-mime-types/"
5047
}; // @formatter:on
5148

52-
private String style_file = "src/test/resources/docbook-xsl/fo/docbook.xsl";
53-
private String output_file = "src/test/resources/final_output.pdf";
54-
private String xmlInput = "src/test/resources/input.xml";
55-
private String xmlOutput = "src/test/resources/output.xml";
49+
private final String style_file = "src/test/resources/docbook-xsl/fo/docbook.xsl";
50+
private final String output_file = "src/test/resources/final_output.pdf";
51+
private final String xmlInput = "src/test/resources/input.xml";
52+
private final String xmlOutput = "src/test/resources/output.xml";
5653

5754
// tests
5855

@@ -75,10 +72,11 @@ private void fromHTMLTOXMLUsingHerold(final String input, final boolean append)
7572
final TrafoScriptManager mgr = new TrafoScriptManager();
7673
final File profileFile = new File("src/test/resources/default.her");
7774
script = mgr.parseScript(profileFile);
78-
final DocBookTransformer transformer = new DocBookTransformer();
79-
transformer.setScript(script);
75+
final HtmlDocBookTrafo transformer = new HtmlDocBookTrafo();
76+
transformer.setInputStream(getInputStream(input));
77+
transformer.setOutputStream(new FileOutputStream(xmlInput, append));
8078

81-
transformer.convert(getInputStream(input), new FileOutputStream(xmlInput, append));
79+
transformer.transform(script);
8280
}
8381

8482
private Document fromXMLFileToFO() throws Exception {
@@ -112,7 +110,9 @@ private Transformer createTransformer(final String styleFile) throws Exception {
112110

113111
private InputStream getInputStream(final String input) throws IOException {
114112
final URL url = new URL(input);
115-
return url.openStream();
113+
final HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
114+
httpcon.addRequestProperty("User-Agent", "Mozilla/4.0");
115+
return httpcon.getInputStream();
116116
}
117117

118118
private void fixXML(final String input, final String output) throws IOException {
@@ -127,7 +127,7 @@ private void fixXML(final String input, final String output) throws IOException
127127

128128
if (line.contains("info>")) {
129129
writer.write(line.replace("info>", "section>"));
130-
} else if (!((line.startsWith("<?xml") || line.startsWith("<article") || line.startsWith("</article")) && count > 4)) {
130+
} else if (!((line.startsWith("<?xml") || line.startsWith("<article") || line.startsWith("</article")) && (count > 4))) {
131131
writer.write(line.replaceAll("xml:id=\"", "xml:id=\"" + count));
132132
}
133133
writer.write("\n");
-828 KB
Binary file not shown.

0 commit comments

Comments
 (0)