Skip to content

Commit 31db62d

Browse files
committed
Upgrade to css4j 5.1
1 parent 3309f59 commit 31db62d

File tree

8 files changed

+181
-114
lines changed

8 files changed

+181
-114
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ java {
2525
dependencies {
2626
api('io.sf.carte:css4j') {
2727
version {
28-
strictly '[4.2.2,)'
29-
prefer '5.0'
28+
strictly '[5.1,)'
29+
prefer '5.1'
3030
}
3131
}
3232
useragentImplementation('io.sf.carte:css4j-agent') {
@@ -48,7 +48,7 @@ dependencies {
4848
xmlpullImplementation 'xmlpull:xmlpull:1.2.0'
4949
xmlpullImplementation 'xpp3:xpp3_min:1.2.0'
5050
testImplementation group: 'io.sf.carte', name: 'css4j', classifier: 'tests',
51-
version: '5.0'
51+
version: '5.1'
5252
testImplementation 'jaxen:jaxen:1.2.0'
5353
testImplementation 'org.slf4j:slf4j-api:2.0.13'
5454
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'

junit/io/sf/carte/doc/dom4j/BaseURLElementTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void attributeSetValue() {
7373
public void childAddedNode() throws Exception {
7474
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
7575
InputSource isrc = new InputSource(re);
76-
CSSDocument xhtmlDoc = XHTMLDocumentFactoryTest.parseXML(isrc);
76+
CSSDocument xhtmlDoc = TestUtil.parseXML(isrc);
7777
re.close();
7878
assertNotNull(xhtmlDoc.getBaseURL());
7979
assertEquals("http://www.example.com/", xhtmlDoc.getBaseURL().toExternalForm());
@@ -82,7 +82,7 @@ public void childAddedNode() throws Exception {
8282
@Test
8383
public void childAddedNodeXPP3() throws Exception {
8484
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
85-
CSSDocument xhtmlDoc = XHTMLDocumentFactoryTest.parseXPP3(re);
85+
CSSDocument xhtmlDoc = TestUtil.parseXPP3(re);
8686
assertNotNull(xhtmlDoc.getBaseURL());
8787
assertEquals("http://www.example.com/", xhtmlDoc.getBaseURL().toExternalForm());
8888
re.close();

junit/io/sf/carte/doc/dom4j/CSSStylableElementTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CSSStylableElementTest {
4242
public void setUp() throws Exception {
4343
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
4444
InputSource isrc = new InputSource(re);
45-
xhtmlDoc = XHTMLDocumentFactoryTest.parseXML(isrc);
45+
xhtmlDoc = TestUtil.parseXML(isrc);
4646
xhtmlDoc.setTargetMedium("screen");
4747
re.close();
4848
}

junit/io/sf/carte/doc/dom4j/DOM4JCSSStyleDeclarationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static void setUpBeforeClass() throws IOException {
5858

5959
@BeforeEach
6060
public void setUp() throws Exception {
61-
xhtmlDoc = XHTMLDocumentFactoryTest.sampleXHTML();
61+
xhtmlDoc = TestUtil.sampleXHTML();
6262
}
6363

6464
@Test
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
3+
Copyright (c) 2005-2025, Carlos Amengual.
4+
5+
SPDX-License-Identifier: BSD-3-Clause
6+
7+
Licensed under a BSD-style License. You can find the license here:
8+
https://css4j.github.io/LICENSE.txt
9+
10+
*/
11+
12+
package io.sf.carte.doc.dom4j;
13+
14+
import java.io.IOException;
15+
import java.io.Reader;
16+
17+
import org.dom4j.DocumentException;
18+
import org.dom4j.io.SAXReader;
19+
import org.dom4j.io.XPP3Reader;
20+
import org.xml.sax.InputSource;
21+
import org.xml.sax.SAXException;
22+
23+
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
24+
import io.sf.carte.doc.xml.dtd.DefaultEntityResolver;
25+
26+
public class TestUtil {
27+
28+
private static TestDocumentFactory factoryUASheet;
29+
30+
static {
31+
factoryUASheet = new TestDocumentFactory();
32+
factoryUASheet.getStyleSheetFactory().setDefaultHTMLUserAgentSheet();
33+
}
34+
35+
private TestUtil() {
36+
}
37+
38+
public static XHTMLDocument parseXML(InputSource is) throws DocumentException, SAXException {
39+
SAXReader reader = new SAXReader(factoryUASheet);
40+
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);
41+
reader.setEntityResolver(new DefaultEntityResolver());
42+
XHTMLDocument document = (XHTMLDocument) reader.read(is);
43+
return document;
44+
}
45+
46+
public static XHTMLDocument parseXPP3(Reader re) throws Exception {
47+
TestDocumentFactory factory = new TestDocumentFactory();
48+
XPP3Reader reader = new XPP3Reader(factory);
49+
XHTMLDocument document = (XHTMLDocument) reader.read(re);
50+
return document;
51+
}
52+
53+
public static XHTMLDocument sampleXHTML() throws DocumentException, SAXException, IOException {
54+
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
55+
InputSource isrc = new InputSource(re);
56+
XHTMLDocument xhtmlDoc = parseXML(isrc);
57+
re.close();
58+
return xhtmlDoc;
59+
}
60+
61+
}

junit/io/sf/carte/doc/dom4j/XHTMLDocumentFactoryTest.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
import java.net.URLConnection;
2424
import java.nio.charset.StandardCharsets;
2525

26-
import org.dom4j.DocumentException;
2726
import org.dom4j.io.SAXReader;
28-
import org.dom4j.io.XPP3Reader;
2927
import org.junit.jupiter.api.BeforeAll;
3028
import org.junit.jupiter.api.Test;
3129
import org.w3c.dom.DocumentType;
3230
import org.w3c.dom.Node;
3331
import org.w3c.dom.NodeList;
3432
import org.xml.sax.InputSource;
35-
import org.xml.sax.SAXException;
3633

3734
import io.sf.carte.doc.style.css.CSSDocument;
3835
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
@@ -46,7 +43,7 @@ public class XHTMLDocumentFactoryTest {
4643
public static void setUpBeforeClass() throws Exception {
4744
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
4845
InputSource isrc = new InputSource(re);
49-
xhtmlDoc = parseXML(isrc);
46+
xhtmlDoc = TestUtil.parseXML(isrc);
5047
re.close();
5148
}
5249

@@ -154,29 +151,4 @@ public void testEntities2() throws Exception {
154151
assertEquals("ítem", ent0.getNodeValue());
155152
}
156153

157-
public static XHTMLDocument parseXML(InputSource is) throws DocumentException, SAXException {
158-
TestDocumentFactory factory = new TestDocumentFactory();
159-
factory.getStyleSheetFactory().setDefaultHTMLUserAgentSheet();
160-
SAXReader reader = new SAXReader(factory);
161-
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);
162-
reader.setEntityResolver(new DefaultEntityResolver());
163-
XHTMLDocument document = (XHTMLDocument) reader.read(is);
164-
return document;
165-
}
166-
167-
public static XHTMLDocument parseXPP3(Reader re) throws Exception {
168-
TestDocumentFactory factory = new TestDocumentFactory();
169-
XPP3Reader reader = new XPP3Reader(factory);
170-
XHTMLDocument document = (XHTMLDocument) reader.read(re);
171-
return document;
172-
}
173-
174-
public static XHTMLDocument sampleXHTML() throws DocumentException, SAXException, IOException {
175-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
176-
InputSource isrc = new InputSource(re);
177-
XHTMLDocument xhtmlDoc = parseXML(isrc);
178-
re.close();
179-
return xhtmlDoc;
180-
}
181-
182154
}

0 commit comments

Comments
 (0)