1010import java.io.IOException;
1111import java.io.InputStream;
1212import java.io.OutputStream;
13+ import java.net.HttpURLConnection;
1314import java.net.URL;
1415
1516import javax.xml.transform.Result;
2526import org.apache.fop.apps.FopFactory;
2627import org.apache.xmlgraphics.util.MimeConstants;
2728import org.dbdoclet.trafo.TrafoScriptManager;
28- import org.dbdoclet.trafo.html.docbook.DocBookTransformer ;
29+ import org.dbdoclet.trafo.html.docbook.HtmlDocBookTrafo ;
2930import org.dbdoclet.trafo.script.Script;
3031import org.junit.Test;
3132import org.w3c.dom.Document;
3233
3334public 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");
0 commit comments