Skip to content

Commit 08a5247

Browse files
committed
Upgrade to css4j and css4j-agent 6.0
1 parent a5fc076 commit 08a5247

12 files changed

+64
-39
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ java {
2525
dependencies {
2626
api('io.sf.carte:css4j') {
2727
version {
28-
strictly '[5.3,)'
29-
prefer '5.3.1'
28+
strictly '[6.0,)'
29+
prefer '6.0'
3030
}
3131
}
3232
useragentImplementation('io.sf.carte:css4j-agent') {
3333
version {
3434
strictly '[3.4.0,)'
35-
prefer '5.3'
35+
prefer '6.0'
3636
}
3737
}
3838
/*
@@ -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.3.1'
51+
version: '6.0'
5252
testImplementation 'jaxen:jaxen:2.0.0'
5353
testImplementation 'org.slf4j:slf4j-api:2.0.17'
5454
testImplementation 'org.junit.jupiter:junit-jupiter:5.12.2'

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.xml.sax.InputSource;
2525

2626
import io.sf.carte.doc.style.css.CSSDocument;
27-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
27+
import io.sf.carte.doc.style.css.om.SampleCSS;
2828

2929
public class BaseURLElementTest {
3030

@@ -71,7 +71,7 @@ public void attributeSetValue() {
7171

7272
@Test
7373
public void childAddedNode() throws Exception {
74-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
74+
Reader re = SampleCSS.sampleHTMLReader();
7575
InputSource isrc = new InputSource(re);
7676
CSSDocument xhtmlDoc = TestUtil.parseXML(isrc);
7777
re.close();
@@ -81,7 +81,7 @@ public void childAddedNode() throws Exception {
8181

8282
@Test
8383
public void childAddedNodeXPP3() throws Exception {
84-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
84+
Reader re = SampleCSS.sampleHTMLReader();
8585
CSSDocument xhtmlDoc = TestUtil.parseXPP3(re);
8686
assertNotNull(xhtmlDoc.getBaseURL());
8787
assertEquals("http://www.example.com/", xhtmlDoc.getBaseURL().toExternalForm());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232

3333
import io.sf.carte.doc.style.css.CSSMediaException;
3434
import io.sf.carte.doc.style.css.CSSStyleDeclaration;
35-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
35+
import io.sf.carte.doc.style.css.om.SampleCSS;
3636

3737
public class CSSStylableElementTest {
3838

3939
XHTMLDocument xhtmlDoc;
4040

4141
@BeforeEach
4242
public void setUp() throws Exception {
43-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
43+
Reader re = SampleCSS.sampleHTMLReader();
4444
InputSource isrc = new InputSource(re);
4545
xhtmlDoc = TestUtil.parseXML(isrc);
4646
xhtmlDoc.setTargetMedium("screen");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@
2222
import io.sf.carte.doc.style.css.nsac.CSSException;
2323
import io.sf.carte.doc.style.css.om.AbstractCSSStyleSheet;
2424
import io.sf.carte.doc.style.css.om.CSSRuleArrayList;
25-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
25+
import io.sf.carte.doc.style.css.om.SampleCSS;
2626

2727
public class DOM4JCSSStyleSheetTest {
2828

2929
@Test
3030
public void testParseCSSStyleSheet() throws CSSException, IOException {
3131
AbstractCSSStyleSheet css = XHTMLDocumentFactory.getInstance().getStyleSheetFactory()
3232
.createStyleSheet(null, null);
33-
Reader re = DOMCSSStyleSheetFactoryTest.loadSampleCSSReader();
33+
Reader re = SampleCSS.loadSampleCSSReader();
3434
css.parseStyleSheet(re);
3535
re.close();
3636
CSSRuleArrayList rules = css.getCssRules();
37-
assertEquals(DOMCSSStyleSheetFactoryTest.RULES_IN_SAMPLE_CSS, rules.getLength());
37+
assertEquals(SampleCSS.RULES_IN_SAMPLE_CSS, rules.getLength());
3838
assertFalse(css.getErrorHandler().hasSacErrors());
3939
}
4040

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import io.sf.carte.doc.style.css.nsac.SelectorList;
24-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
24+
import io.sf.carte.doc.style.css.om.SampleCSS;
2525
import io.sf.carte.doc.style.css.parser.CSSParser;
2626

2727
public class DirMatcherTest {
@@ -30,7 +30,7 @@ public class DirMatcherTest {
3030

3131
@BeforeEach
3232
public void setUp() throws IOException, DocumentException {
33-
document = TestDocumentFactory.loadDocument(DOMCSSStyleSheetFactoryTest.directionalityHTMLReader());
33+
document = TestDocumentFactory.loadDocument(SampleCSS.directionalityHTMLReader());
3434
}
3535

3636
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.xml.sax.InputSource;
2121
import org.xml.sax.SAXException;
2222

23-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
23+
import io.sf.carte.doc.style.css.om.SampleCSS;
2424
import io.sf.carte.doc.xml.dtd.DefaultEntityResolver;
2525

2626
public class TestUtil {
@@ -51,7 +51,7 @@ public static XHTMLDocument parseXPP3(Reader re) throws Exception {
5151
}
5252

5353
public static XHTMLDocument sampleXHTML() throws DocumentException, SAXException, IOException {
54-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
54+
Reader re = SampleCSS.sampleHTMLReader();
5555
InputSource isrc = new InputSource(re);
5656
XHTMLDocument xhtmlDoc = parseXML(isrc);
5757
re.close();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.xml.sax.InputSource;
3232

3333
import io.sf.carte.doc.style.css.CSSDocument;
34-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
34+
import io.sf.carte.doc.style.css.om.SampleCSS;
3535
import io.sf.carte.doc.xml.dtd.DefaultEntityResolver;
3636

3737
public class XHTMLDocumentFactoryTest {
@@ -40,7 +40,7 @@ public class XHTMLDocumentFactoryTest {
4040

4141
@BeforeAll
4242
public static void setUpBeforeClass() throws Exception {
43-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
43+
Reader re = SampleCSS.sampleHTMLReader();
4444
InputSource isrc = new InputSource(re);
4545
xhtmlDoc = TestUtil.parseXML(isrc);
4646
re.close();
@@ -92,7 +92,7 @@ public void testEntities1() throws Exception {
9292
// First, check plain dom4j behaviour
9393
SAXReader reader = new SAXReader();
9494
reader.setEntityResolver(new DefaultEntityResolver());
95-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
95+
Reader re = SampleCSS.sampleHTMLReader();
9696
org.dom4j.Document dom4jdocument = reader.read(re);
9797
re.close();
9898
org.dom4j.Element dom4jelm = dom4jdocument.elementByID("entity");
@@ -123,7 +123,7 @@ public void testEntities2PlainDom4j() throws Exception {
123123
SAXReader reader = new SAXReader();
124124
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", true);
125125
reader.setEntityResolver(new DefaultEntityResolver());
126-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
126+
Reader re = SampleCSS.sampleHTMLReader();
127127
org.dom4j.Document document = reader.read(re);
128128
re.close();
129129
org.dom4j.Element dom4jelm = document.elementByID("entiacute");

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static org.junit.jupiter.api.Assertions.assertFalse;
1616
import static org.junit.jupiter.api.Assertions.assertNotNull;
1717
import static org.junit.jupiter.api.Assertions.assertNull;
18+
import static org.junit.jupiter.api.Assertions.assertThrows;
1819
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

2021
import java.io.IOException;
@@ -56,9 +57,9 @@
5657
import io.sf.carte.doc.style.css.om.CSSOMParser;
5758
import io.sf.carte.doc.style.css.om.CSSRuleArrayList;
5859
import io.sf.carte.doc.style.css.om.ComputedCSSStyle;
59-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
6060
import io.sf.carte.doc.style.css.om.MediaRule;
6161
import io.sf.carte.doc.style.css.om.PropertyCountVisitor;
62+
import io.sf.carte.doc.style.css.om.SampleCSS;
6263
import io.sf.carte.doc.style.css.om.StyleCountVisitor;
6364
import io.sf.carte.doc.style.css.om.StyleRule;
6465
import io.sf.carte.doc.style.css.om.StyleSheetList;
@@ -72,7 +73,7 @@ public class XHTMLDocumentTest {
7273

7374
@BeforeEach
7475
public void setUp() throws Exception {
75-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
76+
Reader re = SampleCSS.sampleHTMLReader();
7677
org.xml.sax.InputSource isrc = new org.xml.sax.InputSource(re);
7778
xhtmlDoc = TestUtil.parseXML(isrc);
7879
re.close();
@@ -489,7 +490,7 @@ public void testComputedStyleAttr() {
489490
/*
490491
* attr() value, string expected type, do not reparse.
491492
*/
492-
elm.getOverrideStyle(null).setCssText("margin-left:attr(leftmargin string)");
493+
elm.getOverrideStyle(null).setCssText("margin-left:attr(leftmargin raw-string)");
493494
style = elm.getComputedStyle(null);
494495
marginLeft = (CSSTypedValue) style.getPropertyCSSValue("margin-left");
495496
assertEquals(CSSValue.Type.STRING, marginLeft.getPrimitiveType());
@@ -954,7 +955,7 @@ public void testCompatComputedStyle() {
954955

955956
@Test
956957
public void testCascade() throws IOException {
957-
Reader re = DOMCSSStyleSheetFactoryTest.loadSampleUserCSSReader();
958+
Reader re = SampleCSS.loadSampleUserCSSReader();
958959
xhtmlDoc.getDocumentFactory().getStyleSheetFactory().setUserStyleSheet(re);
959960
re.close();
960961
CSSElement elm = xhtmlDoc.getElementById("para1");
@@ -1088,6 +1089,32 @@ public void testBaseElement() throws MalformedURLException {
10881089
CSSElement base = (CSSElement) xhtmlDoc.getElementsByTagName("base").item(0);
10891090
base.setAttribute("href", "http://www.example.com/newbase/");
10901091
assertEquals("http://www.example.com/newbase/", xhtmlDoc.getBaseURI());
1092+
1093+
// Check that getURL works
1094+
assertEquals("http://www.example.com/newbase/b?e=f&g=h",
1095+
xhtmlDoc.getURL("b?e=f&g=h").toExternalForm());
1096+
1097+
assertEquals(
1098+
"https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Raleway:wght@200&display=swap",
1099+
xhtmlDoc.getURL(
1100+
"https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Raleway:wght@200&display=swap")
1101+
.toExternalForm());
1102+
1103+
// Web browsers admit the following
1104+
assertEquals(
1105+
"https://fonts.googleapis.com/css?family=Roboto+Slab:400,700,300%7CRoboto:400,500,700,300,900&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic",
1106+
xhtmlDoc.getURL(
1107+
"https://fonts.googleapis.com/css?family=Roboto+Slab:400,700,300|Roboto:400,500,700,300,900&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic")
1108+
.toExternalForm());
1109+
1110+
assertThrows(MalformedURLException.class, () -> xhtmlDoc.getURL("https:||www.example.com/"));
1111+
1112+
assertThrows(MalformedURLException.class,
1113+
() -> xhtmlDoc.getURL("https://www.example.com/a?b=c\\d"));
1114+
1115+
assertThrows(MalformedURLException.class,
1116+
() -> xhtmlDoc.getURL("https://www.example.com/a?b=\"c\""));
1117+
10911118
// Wrong URL
10921119
base.setAttribute("href", "http//");
10931120
assertNull(xhtmlDoc.getBaseURI());
@@ -1119,6 +1146,7 @@ public void testBaseElement2() throws MalformedURLException {
11191146
// Set documentURI and then unsafe attribute
11201147
xhtmlDoc.setDocumentURI("http://www.example.com/doc-uri");
11211148
CSSElement base = (CSSElement) xhtmlDoc.getElementsByTagName("base").item(0);
1149+
11221150
// Relative URL
11231151
base.setAttribute("href", "foo");
11241152
assertEquals("foo", base.getAttribute("href"));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
import org.junit.jupiter.api.Test;
2222
import org.xmlpull.v1.XmlPullParserException;
2323

24-
import io.sf.carte.doc.style.css.om.DOMCSSStyleSheetFactoryTest;
24+
import io.sf.carte.doc.style.css.om.SampleCSS;
2525

2626
public class XPP3Test {
2727

2828
@Test
2929
public void parseXPP3() throws DocumentException, IOException, XmlPullParserException {
3030
XHTMLDocumentFactory factory = XHTMLDocumentFactory.getInstance();
3131
XPP3Reader reader = new XPP3Reader(factory);
32-
Reader re = DOMCSSStyleSheetFactoryTest.sampleHTMLReader();
32+
Reader re = SampleCSS.sampleHTMLReader();
3333
XHTMLDocument document = (XHTMLDocument) reader.read(re);
3434
re.close();
3535
assertEquals("html", document.getRootElement().getName());

src/io/sf/carte/doc/dom4j/DOM4JCSSStyleSheet.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424

2525
/**
2626
* CSS Style Sheet for DOM4J.
27-
*
28-
* @author Carlos Amengual
29-
*
3027
*/
3128
abstract class DOM4JCSSStyleSheet extends BaseCSSStyleSheet implements Cloneable {
3229

33-
private static final long serialVersionUID = 1L;
30+
private static final long serialVersionUID = 2L;
3431

3532
Node ownerNode;
3633

3734
public DOM4JCSSStyleSheet(String title, Node ownerNode, MediaQueryList media, AbstractCSSRule ownerRule,
38-
byte origin) {
35+
int origin) {
3936
super(title, media, ownerRule, origin);
4037
this.ownerNode = ownerNode;
4138
}

src/io/sf/carte/doc/dom4j/DOM4JDocumentCSSStyleSheet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ abstract class DOM4JDocumentCSSStyleSheet extends BaseDocumentCSSStyleSheet {
3131

3232
private XHTMLDocument ownerElement = null;
3333

34-
DOM4JDocumentCSSStyleSheet(byte origin) {
34+
DOM4JDocumentCSSStyleSheet(int origin) {
3535
super(null, origin);
3636
}
3737

38-
protected DOM4JDocumentCSSStyleSheet(String medium, byte origin) {
38+
protected DOM4JDocumentCSSStyleSheet(String medium, int origin) {
3939
super(medium, origin);
4040
}
4141

src/io/sf/carte/doc/dom4j/XHTMLDocumentFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public AbstractCSSStyleDeclaration createAnonymousStyleDeclaration(Node node) {
330330
}
331331

332332
@Override
333-
protected BaseDocumentCSSStyleSheet createDocumentStyleSheet(byte origin) {
333+
protected BaseDocumentCSSStyleSheet createDocumentStyleSheet(int origin) {
334334
return new MyDOM4JDocumentCSSStyleSheet(null, origin);
335335
}
336336

@@ -346,19 +346,19 @@ protected BaseCSSStyleSheet createLinkedStyleSheet(Node ownerNode, String title,
346346
}
347347

348348
DOM4JCSSStyleSheet createCSSStyleSheet(String title, Node ownerNode, MediaQueryList media,
349-
AbstractCSSRule ownerRule, byte origin) {
349+
AbstractCSSRule ownerRule, int origin) {
350350
return new MyDOM4JCSSStyleSheet(title, ownerNode, media, ownerRule, origin);
351351
}
352352

353-
DOM4JDocumentCSSStyleSheet createDocumentStyleSheet(String targetMedium, byte origin) {
353+
DOM4JDocumentCSSStyleSheet createDocumentStyleSheet(String targetMedium, int origin) {
354354
return new MyDOM4JDocumentCSSStyleSheet(targetMedium, origin);
355355
}
356356

357357
private class MyDOM4JDocumentCSSStyleSheet extends DOM4JDocumentCSSStyleSheet {
358358

359359
private static final long serialVersionUID = 1L;
360360

361-
public MyDOM4JDocumentCSSStyleSheet(String targetMedium, byte origin) {
361+
public MyDOM4JDocumentCSSStyleSheet(String targetMedium, int origin) {
362362
super(targetMedium, origin);
363363
}
364364

@@ -375,10 +375,10 @@ public DOM4JCSSStyleSheetFactory getStyleSheetFactory() {
375375

376376
private class MyDOM4JCSSStyleSheet extends DOM4JCSSStyleSheet {
377377

378-
private static final long serialVersionUID = 1L;
378+
private static final long serialVersionUID = 2L;
379379

380380
public MyDOM4JCSSStyleSheet(String title, Node ownerNode, MediaQueryList media, AbstractCSSRule ownerRule,
381-
byte origin) {
381+
int origin) {
382382
super(title, ownerNode, media, ownerRule, origin);
383383
}
384384

0 commit comments

Comments
 (0)