Skip to content

Commit ca70ad3

Browse files
committed
use our own string functions
1 parent 49f4d68 commit ca70ad3

35 files changed

+156
-142
lines changed

src/main/java/org/htmlunit/DefaultPageCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
import java.util.Locale;
2222

2323
import org.apache.commons.lang3.ArrayUtils;
24-
import org.apache.commons.lang3.StringUtils;
2524
import org.htmlunit.html.DomElement;
2625
import org.htmlunit.html.Html;
2726
import org.htmlunit.html.HtmlPage;
2827
import org.htmlunit.html.XHtmlPage;
2928
import org.htmlunit.html.parser.HTMLParser;
3029
import org.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser;
3130
import org.htmlunit.util.MimeType;
31+
import org.htmlunit.util.StringUtils;
3232
import org.htmlunit.xml.XmlPage;
3333

3434
/**
@@ -156,7 +156,7 @@ public static PageType determinePageType(final String contentType) {
156156
*/
157157
public static PageType determinePageType(final WebResponse webResponse) throws IOException {
158158
final String contentType = webResponse.getContentType();
159-
if (!StringUtils.isEmpty(contentType)) {
159+
if (!StringUtils.isEmptyOrNull(contentType)) {
160160
return determinePageType(contentType);
161161
}
162162

src/main/java/org/htmlunit/attachment/DownloadingAttachmentHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import java.nio.file.Paths;
2323

2424
import org.apache.commons.io.FileUtils;
25-
import org.apache.commons.lang3.StringUtils;
2625
import org.apache.commons.logging.Log;
2726
import org.apache.commons.logging.LogFactory;
2827
import org.htmlunit.Page;
2928
import org.htmlunit.WebResponse;
29+
import org.htmlunit.util.StringUtils;
3030

3131
/**
3232
* Implementation of an {@link AttachmentHandler} that mimics how browsers handle attachments, specifically
@@ -98,12 +98,12 @@ public void handleAttachment(final Page page, final String attachmentFilename) {
9898
private Path determineDestionationFile(final Page page, final String attachmentFilename) {
9999
String fileName = attachmentFilename;
100100

101-
if (StringUtils.isAllBlank(fileName)) {
101+
if (StringUtils.isBlank(fileName)) {
102102
final String file = page.getWebResponse().getWebRequest().getUrl().getFile();
103103
fileName = file.substring(file.lastIndexOf('/') + 1);
104104
}
105105

106-
if (StringUtils.isAllBlank(fileName)) {
106+
if (StringUtils.isBlank(fileName)) {
107107
fileName = "download";
108108
}
109109

src/main/java/org/htmlunit/css/AbstractCssStyleDeclaration.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ public boolean isComputed() {
265265
*/
266266
public String getBackgroundAttachment() {
267267
String value = getStyleAttribute(Definition.BACKGROUND_ATTACHMENT, false);
268-
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
268+
if (StringUtils.isBlank(value)) {
269269
final String bg = getStyleAttribute(Definition.BACKGROUND, true);
270-
if (org.apache.commons.lang3.StringUtils.isNotBlank(bg)) {
270+
if (StringUtils.isNotBlank(bg)) {
271271
value = findAttachment(bg);
272272
if (value == null) {
273273
if (hasFeature(CSS_BACKGROUND_INITIAL) && !isComputed()) {
@@ -289,9 +289,9 @@ public String getBackgroundAttachment() {
289289
*/
290290
public String getBackgroundColor() {
291291
String value = getStyleAttribute(Definition.BACKGROUND_COLOR, false);
292-
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
292+
if (StringUtils.isBlank(value)) {
293293
final String bg = getStyleAttribute(Definition.BACKGROUND, false);
294-
if (org.apache.commons.lang3.StringUtils.isBlank(bg)) {
294+
if (StringUtils.isBlank(bg)) {
295295
return "";
296296
}
297297
value = findColor(bg);
@@ -309,7 +309,7 @@ public String getBackgroundColor() {
309309
}
310310
return value;
311311
}
312-
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
312+
if (StringUtils.isBlank(value)) {
313313
return "";
314314
}
315315
return value;
@@ -321,9 +321,9 @@ public String getBackgroundColor() {
321321
*/
322322
public String getBackgroundImage() {
323323
String value = getStyleAttribute(Definition.BACKGROUND_IMAGE, false);
324-
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
324+
if (StringUtils.isBlank(value)) {
325325
final String bg = getStyleAttribute(Definition.BACKGROUND, false);
326-
if (org.apache.commons.lang3.StringUtils.isNotBlank(bg)) {
326+
if (StringUtils.isNotBlank(bg)) {
327327
value = findImageUrl(bg);
328328
final boolean backgroundInitial = hasFeature(CSS_BACKGROUND_INITIAL);
329329
if (value == null) {
@@ -357,12 +357,12 @@ public String getBackgroundPosition() {
357357
if (value == null) {
358358
return null;
359359
}
360-
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
360+
if (StringUtils.isBlank(value)) {
361361
final String bg = getStyleAttribute(Definition.BACKGROUND, false);
362362
if (bg == null) {
363363
return null;
364364
}
365-
if (org.apache.commons.lang3.StringUtils.isNotBlank(bg)) {
365+
if (StringUtils.isNotBlank(bg)) {
366366
value = findPosition(bg);
367367
final boolean isInitial = hasFeature(CSS_BACKGROUND_INITIAL);
368368
if (value == null) {
@@ -419,9 +419,9 @@ public String getBackgroundPosition() {
419419
*/
420420
public String getBackgroundRepeat() {
421421
String value = getStyleAttribute(Definition.BACKGROUND_REPEAT, false);
422-
if (org.apache.commons.lang3.StringUtils.isBlank(value)) {
422+
if (StringUtils.isBlank(value)) {
423423
final String bg = getStyleAttribute(Definition.BACKGROUND, false);
424-
if (org.apache.commons.lang3.StringUtils.isNotBlank(bg)) {
424+
if (StringUtils.isNotBlank(bg)) {
425425
value = findRepeat(bg);
426426
if (value == null) {
427427
if (hasFeature(CSS_BACKGROUND_INITIAL) && !isComputed()) {
@@ -545,7 +545,7 @@ private String getBorderWidth(final Definition borderSideWidth, final Definition
545545
value = findBorderWidth(getStyleAttribute(borderSide, false));
546546
if (value == null) {
547547
final String borderWidth = getStyleAttribute(Definition.BORDER_WIDTH, false);
548-
if (!org.apache.commons.lang3.StringUtils.isEmpty(borderWidth)) {
548+
if (!StringUtils.isEmptyOrNull(borderWidth)) {
549549
final String[] values = StringUtils.splitAtJavaWhitespace(borderWidth);
550550
int index = values.length;
551551
if (borderSideWidth.name().contains("TOP")) {

src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.util.SortedMap;
4444
import java.util.TreeMap;
4545

46-
import org.apache.commons.lang3.StringUtils;
4746
import org.htmlunit.BrowserVersion;
4847
import org.htmlunit.BrowserVersionFeatures;
4948
import org.htmlunit.Page;
@@ -148,6 +147,7 @@
148147
import org.htmlunit.html.HtmlVariable;
149148
import org.htmlunit.html.HtmlWordBreak;
150149
import org.htmlunit.platform.Platform;
150+
import org.htmlunit.util.StringUtils;
151151

152152
/**
153153
* An object for a CSSStyleDeclaration, which is computed.
@@ -274,7 +274,7 @@ public String getStyleAttribute(final String name) {
274274
final String value = element.getValue();
275275
if (!"content".equals(name)
276276
&& !value.contains("url")) {
277-
return org.htmlunit.util.StringUtils.toRootLowerCase(value);
277+
return StringUtils.toRootLowerCase(value);
278278
}
279279
return value;
280280
}
@@ -411,7 +411,7 @@ public String getWidth() {
411411
@Override
412412
public String get(final ComputedCssStyleDeclaration style) {
413413
final String value = style.getStyleAttribute(Definition.WIDTH, true);
414-
if (StringUtils.isEmpty(value)) {
414+
if (StringUtils.isEmptyOrNull(value)) {
415415
final String position = getStyleAttribute(Definition.POSITION, true);
416416
if (ABSOLUTE.equals(position) || FIXED.equals(position)) {
417417
final String content = domElem.getVisibleText();
@@ -534,7 +534,7 @@ public String getBackgroundColor() {
534534
}
535535

536536
final String value = super.getBackgroundColor();
537-
if (StringUtils.isEmpty(value)) {
537+
if (StringUtils.isEmptyOrNull(value)) {
538538
return Definition.BACKGROUND_COLOR.getDefaultComputedValue(getBrowserVersion());
539539
}
540540
return CssColors.toRGBColor(value);
@@ -583,7 +583,7 @@ public String getBlockSize() {
583583
@Override
584584
public String get(final ComputedCssStyleDeclaration style) {
585585
final String value = style.getStyleAttribute(Definition.HEIGHT, true);
586-
if (StringUtils.isEmpty(value)) {
586+
if (StringUtils.isEmptyOrNull(value)) {
587587
final String content = domElem.getVisibleText();
588588
// do this only for small content
589589
// at least for empty div's this is more correct
@@ -737,7 +737,7 @@ public String getDisplay() {
737737
// don't use defaultIfEmpty for performance
738738
// (no need to calculate the default if not empty)
739739
final String value = getStyleAttribute(Definition.DISPLAY.getAttributeName());
740-
if (StringUtils.isEmpty(value)) {
740+
if (StringUtils.isEmptyOrNull(value)) {
741741
if (domElem instanceof HtmlElement) {
742742
return ((HtmlElement) domElem).getDefaultStyleDisplay().value();
743743
}
@@ -1570,7 +1570,8 @@ private int getCalculatedWidth() {
15701570
final DomNode parent = element.getParentNode();
15711571

15721572
// width is ignored for inline elements
1573-
if ((INLINE.equals(display) || StringUtils.isEmpty(styleWidth)) && parent instanceof HtmlElement) {
1573+
if ((INLINE.equals(display) || StringUtils.isEmptyOrNull(styleWidth))
1574+
&& parent instanceof HtmlElement) {
15741575
// hack: TODO find a way to specify default values for different tags
15751576
if (element instanceof HtmlCanvas) {
15761577
return 300;
@@ -1962,11 +1963,11 @@ else if (element instanceof HtmlHeading6) {
19621963
defaultHeight *= lineCount;
19631964
}
19641965
else {
1965-
if (element instanceof HtmlSpan && StringUtils.isEmpty(content)) {
1966+
if (element instanceof HtmlSpan && StringUtils.isEmptyOrNull(content)) {
19661967
defaultHeight = 0;
19671968
}
19681969
else {
1969-
defaultHeight *= StringUtils.countMatches(content, '\n') + 1;
1970+
defaultHeight *= org.apache.commons.lang3.StringUtils.countMatches(content, '\n') + 1;
19701971
}
19711972
}
19721973

@@ -2082,23 +2083,23 @@ private boolean isScrollable(final DomElement element, final boolean horizontal,
20822083
String overflow;
20832084
if (horizontal) {
20842085
overflow = getStyleAttribute(Definition.OVERFLOW_X_, false);
2085-
if (StringUtils.isEmpty(overflow)) {
2086+
if (StringUtils.isEmptyOrNull(overflow)) {
20862087
overflow = getStyleAttribute(Definition.OVERFLOW_X, false);
20872088
}
20882089
// fall back to default
2089-
if (StringUtils.isEmpty(overflow)) {
2090+
if (StringUtils.isEmptyOrNull(overflow)) {
20902091
overflow = getStyleAttribute(Definition.OVERFLOW, true);
20912092
}
20922093
scrollable = (element instanceof HtmlBody || SCROLL.equals(overflow) || AUTO.equals(overflow))
20932094
&& (ignoreSize || getContentWidth() > getCalculatedWidth());
20942095
}
20952096
else {
20962097
overflow = getStyleAttribute(Definition.OVERFLOW_Y_, false);
2097-
if (StringUtils.isEmpty(overflow)) {
2098+
if (StringUtils.isEmptyOrNull(overflow)) {
20982099
overflow = getStyleAttribute(Definition.OVERFLOW_Y, false);
20992100
}
21002101
// fall back to default
2101-
if (StringUtils.isEmpty(overflow)) {
2102+
if (StringUtils.isEmptyOrNull(overflow)) {
21022103
overflow = getStyleAttribute(Definition.OVERFLOW, true);
21032104
}
21042105

src/main/java/org/htmlunit/css/CssStyleSheet.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.regex.Pattern;
3939

4040
import org.apache.commons.io.IOUtils;
41-
import org.apache.commons.lang3.StringUtils;
4241
import org.apache.commons.lang3.math.NumberUtils;
4342
import org.apache.commons.logging.Log;
4443
import org.apache.commons.logging.LogFactory;
@@ -101,6 +100,7 @@
101100
import org.htmlunit.javascript.host.css.MediaList;
102101
import org.htmlunit.javascript.host.dom.Document;
103102
import org.htmlunit.util.MimeType;
103+
import org.htmlunit.util.StringUtils;
104104
import org.htmlunit.util.UrlUtils;
105105

106106
/**
@@ -352,7 +352,7 @@ public static CssStyleSheet loadStylesheet(final HtmlElement element, final Html
352352

353353
final CssStyleSheet sheet;
354354
final String contentType = response.getContentType();
355-
if (StringUtils.isEmpty(contentType) || MimeType.TEXT_CSS.equals(contentType)) {
355+
if (StringUtils.isEmptyOrNull(contentType) || MimeType.TEXT_CSS.equals(contentType)) {
356356
try (InputStream in = response.getContentAsStreamWithBomIfApplicable()) {
357357
if (in == null) {
358358
if (LOG.isWarnEnabled()) {
@@ -562,33 +562,33 @@ static boolean selects(final BrowserVersion browserVersion,
562562
final AttributeCondition prefixAttributeCondition = (AttributeCondition) condition;
563563
final String prefixValue = prefixAttributeCondition.getValue();
564564
if (prefixAttributeCondition.isCaseInSensitive()) {
565-
return !org.htmlunit.util.StringUtils.isEmptyString(prefixValue)
566-
&& org.htmlunit.util.StringUtils.startsWithIgnoreCase(
565+
return !StringUtils.isEmptyString(prefixValue)
566+
&& StringUtils.startsWithIgnoreCase(
567567
element.getAttribute(prefixAttributeCondition.getLocalName()), prefixValue);
568568
}
569-
return !org.htmlunit.util.StringUtils.isEmptyString(prefixValue)
569+
return !StringUtils.isEmptyString(prefixValue)
570570
&& element.getAttribute(prefixAttributeCondition.getLocalName()).startsWith(prefixValue);
571571

572572
case SUFFIX_ATTRIBUTE_CONDITION:
573573
final AttributeCondition suffixAttributeCondition = (AttributeCondition) condition;
574574
final String suffixValue = suffixAttributeCondition.getValue();
575575
if (suffixAttributeCondition.isCaseInSensitive()) {
576-
return !org.htmlunit.util.StringUtils.isEmptyString(suffixValue)
577-
&& org.htmlunit.util.StringUtils.endsWithIgnoreCase(
576+
return !StringUtils.isEmptyString(suffixValue)
577+
&& StringUtils.endsWithIgnoreCase(
578578
element.getAttribute(suffixAttributeCondition.getLocalName()), suffixValue);
579579
}
580-
return !org.htmlunit.util.StringUtils.isEmptyString(suffixValue)
580+
return !StringUtils.isEmptyString(suffixValue)
581581
&& element.getAttribute(suffixAttributeCondition.getLocalName()).endsWith(suffixValue);
582582

583583
case SUBSTRING_ATTRIBUTE_CONDITION:
584584
final AttributeCondition substringAttributeCondition = (AttributeCondition) condition;
585585
final String substringValue = substringAttributeCondition.getValue();
586586
if (substringAttributeCondition.isCaseInSensitive()) {
587-
return !org.htmlunit.util.StringUtils.isEmptyString(substringValue)
588-
&& org.htmlunit.util.StringUtils.containsIgnoreCase(
587+
return !StringUtils.isEmptyString(substringValue)
588+
&& StringUtils.containsIgnoreCase(
589589
element.getAttribute(substringAttributeCondition.getLocalName()), substringValue);
590590
}
591-
return !org.htmlunit.util.StringUtils.isEmptyString(substringValue)
591+
return !StringUtils.isEmptyString(substringValue)
592592
&& element.getAttribute(substringAttributeCondition.getLocalName()).contains(substringValue);
593593

594594
case BEGIN_HYPHEN_ATTRIBUTE_CONDITION:
@@ -597,8 +597,8 @@ static boolean selects(final BrowserVersion browserVersion,
597597
final String a = element.getAttribute(beginHyphenAttributeCondition.getLocalName());
598598
if (beginHyphenAttributeCondition.isCaseInSensitive()) {
599599
return selectsHyphenSeparated(
600-
org.htmlunit.util.StringUtils.toRootLowerCase(v),
601-
org.htmlunit.util.StringUtils.toRootLowerCase(a));
600+
StringUtils.toRootLowerCase(v),
601+
StringUtils.toRootLowerCase(a));
602602
}
603603
return selectsHyphenSeparated(v, a);
604604

@@ -608,8 +608,8 @@ static boolean selects(final BrowserVersion browserVersion,
608608
final String a2 = element.getAttribute(oneOfAttributeCondition.getLocalName());
609609
if (oneOfAttributeCondition.isCaseInSensitive()) {
610610
return selectsOneOf(
611-
org.htmlunit.util.StringUtils.toRootLowerCase(v2),
612-
org.htmlunit.util.StringUtils.toRootLowerCase(a2));
611+
StringUtils.toRootLowerCase(v2),
612+
StringUtils.toRootLowerCase(a2));
613613
}
614614
return selectsOneOf(v2, a2);
615615

@@ -865,8 +865,8 @@ private static boolean selectsPseudoClass(final BrowserVersion browserVersion,
865865

866866
case "placeholder-shown":
867867
return element instanceof HtmlInput
868-
&& StringUtils.isEmpty(((HtmlInput) element).getValue())
869-
&& StringUtils.isNotEmpty(((HtmlInput) element).getPlaceholder());
868+
&& StringUtils.isEmptyOrNull(((HtmlInput) element).getValue())
869+
&& !StringUtils.isEmptyOrNull(((HtmlInput) element).getPlaceholder());
870870

871871
default:
872872
if (value.startsWith("nth-child(")) {
@@ -938,7 +938,7 @@ private static boolean getNthElement(final String nth, final int index) {
938938
int denominator = 0;
939939
if (nIndex != -1) {
940940
String value = nth.substring(0, nIndex).trim();
941-
if (org.htmlunit.util.StringUtils.equalsChar('-', value)) {
941+
if (StringUtils.equalsChar('-', value)) {
942942
denominator = -1;
943943
}
944944
else {
@@ -1135,7 +1135,8 @@ private static boolean isValidCondition(final Condition condition, final DomNode
11351135
}
11361136

11371137
if ("nth-child()".equals(value)) {
1138-
final String arg = StringUtils.substringBetween(condition.getValue(), "(", ")").trim();
1138+
final String arg = org.apache.commons.lang3.StringUtils
1139+
.substringBetween(condition.getValue(), "(", ")").trim();
11391140
return "even".equalsIgnoreCase(arg) || "odd".equalsIgnoreCase(arg)
11401141
|| NTH_NUMERIC.matcher(arg).matches()
11411142
|| NTH_COMPLEX.matcher(arg).matches();
@@ -1546,7 +1547,7 @@ private List<CSSStyleSheetImpl.SelectorEntry> selects(
15461547

15471548
if (isActive(index.getMediaList(), element.getPage().getEnclosingWindow())) {
15481549
final String elementName = element.getLowercaseName();
1549-
final String[] classes = org.htmlunit.util.StringUtils.splitAtJavaWhitespace(
1550+
final String[] classes = StringUtils.splitAtJavaWhitespace(
15501551
element.getAttributeDirect("class"));
15511552
final Iterator<CSSStyleSheetImpl.SelectorEntry> iter =
15521553
index.getSelectorEntriesIteratorFor(elementName, classes);

0 commit comments

Comments
 (0)