Skip to content

Commit

Permalink
#339 - Mark JSoup converter module as deprecated and for removal.
Browse files Browse the repository at this point in the history
Upgrade Jsoup dependency for last release of this sub-module. Users should use W3CDom class from Jsoup instead.
  • Loading branch information
danfickle committed Apr 2, 2019
1 parent abe6261 commit 55de574
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
17 changes: 13 additions & 4 deletions openhtmltopdf-jsoup-dom-converter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<packaging>jar</packaging>

<name>Openhtmltopdf Jsoup to DOM Converter</name>
<description>Open HTML to PDF is a CSS 2.1 renderer written in Java. This artifact supports converting a Jsoup HTML5 instance into a DOM supported by Open HTML to PDF.</description>
<description>DEPRECATED MODULE FOR REMOVAL: Use Jsoup provided W3CDom helper class instead. Open HTML to PDF is a CSS 2.1 renderer written in Java. This artifact supports converting a Jsoup HTML5 instance into a DOM supported by Open HTML to PDF.</description>

<licenses>
<license>
Expand All @@ -31,11 +31,20 @@
</distributionManagement>

<dependencies>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.9.1</version>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.jsoup.helper.W3CDom;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
*
* @author <a href="mailto:kasper@dfki.de">Walter Kasper</a>
*
* @deprecated FOR REMOVAL - Use the {@link W3CDom} class from Jsoup instead.
*/
@Deprecated
public class DOMBuilder {
private DOMBuilder() { }

Expand All @@ -25,7 +27,9 @@ private DOMBuilder() { }
* @param jsoupDocument
* The Jsoup document to convert.
* @return A W3C Document.
* @deprecated FOR REMOVAL - Use {@link W3CDom#fromJsoup(org.jsoup.nodes.Document)} instead
*/
@Deprecated
public static Document jsoup2DOM(org.jsoup.nodes.Document jsoupDocument) {

Document document = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.openhtmltopdf;

import org.jsoup.Jsoup;
import org.jsoup.helper.W3CDom;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

public class TestJsoupToDom {
private W3CDom helper = new W3CDom();

private void run(String html) {
org.jsoup.nodes.Document docIn = Jsoup.parse(html);

org.w3c.dom.Document docOut1 = helper.fromJsoup(docIn);
org.w3c.dom.Document docOut2 = DOMBuilder.jsoup2DOM(docIn);

System.out.println();
System.out.println("-----JSOUP Conversion-----");
System.out.println(helper.asString(docOut1));

System.out.println();
System.out.println("-----OpenHTMLToPDF Conversion------");
System.out.println(helper.asString(docOut2));

Assert.assertEquals(helper.asString(docOut1), helper.asString(docOut2));
}

@Test
public void testSimple() {
run("<html><head></head><body style=\"font-size: 12px;\">Some text<img src=\"test.jpg\"></body></html>");
}

@Test
@Ignore // Ours is broken as it strips the xmlns attribute from the svg.
public void testSVG() {
run(
"<html>\n" +
"<body>\n" +
"\n" +
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"100\" width=\"100\">\n" +
" <circle cx=\"50\" cy=\"50\" r=\"40\" stroke=\"black\" stroke-width=\"3\" fill=\"red\" />\n" +
"</svg> \n" +
" \n" +
"</body>\n" +
"</html>"
);
}

}

0 comments on commit 55de574

Please sign in to comment.