Skip to content

Commit 7a03d63

Browse files
committed
Fix a few SpotBugs warnings
1 parent 3fafddc commit 7a03d63

File tree

5 files changed

+8
-40
lines changed

5 files changed

+8
-40
lines changed

findbugs-filter.xml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,4 @@
6767
<Field name="OVERFLOW_VALUES"/>
6868
<Bug pattern="MS_MUTABLE_COLLECTION"/>
6969
</Match>
70-
<Match>
71-
<Class name="com.itextpdf.html2pdf.css.apply.util.BackgroundApplierUtil"/>
72-
<Method
73-
name="applyBackground"
74-
params="java.util.Map, com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.layout.IPropertyContainer"
75-
/>
76-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
77-
</Match>
78-
<Match>
79-
<Class name="com.itextpdf.html2pdf.css.apply.util.FontStyleApplierUtil"/>
80-
<Method
81-
name="applyFontStyles"
82-
params="java.util.Map, com.itextpdf.html2pdf.attach.ProcessorContext, com.itextpdf.styledxmlparser.node.IStylesContainer, com.itextpdf.layout.IPropertyContainer"
83-
/>
84-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
85-
</Match>
86-
<Match>
87-
<Class name="com.itextpdf.html2pdf.css.resolve.DefaultCssResolver"/>
88-
<Method
89-
name="collectCssDeclarations"
90-
params="com.itextpdf.styledxmlparser.node.INode, com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver, com.itextpdf.html2pdf.css.resolve.CssContext"
91-
/>
92-
<Or>
93-
<Bug pattern="DM_DEFAULT_ENCODING"/>
94-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
95-
</Or>
96-
</Match>
97-
<Match>
98-
<Class name="com.itextpdf.html2pdf.html.HtmlUtils"/>
99-
<Method name="isStyleSheetLink" params="com.itextpdf.styledxmlparser.node.IElementNode"/>
100-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
101-
</Match>
10270
</FindBugsFilter>

src/main/java/com/itextpdf/html2pdf/css/apply/util/BackgroundApplierUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public static void applyBackground(Map<String, String> cssProps, ProcessorContex
8585
element.setProperty(Property.BACKGROUND, backgroundColor);
8686
}
8787
String backgroundImageStr = cssProps.get(CssConstants.BACKGROUND_IMAGE);
88-
if (backgroundImageStr != null && !backgroundImageStr.equals(CssConstants.NONE)) {
88+
if (backgroundImageStr != null && !CssConstants.NONE.equals(backgroundImageStr)) {
8989
String backgroundRepeatStr = cssProps.get(CssConstants.BACKGROUND_REPEAT);
9090
PdfXObject image = context.getResourceResolver().retrieveImageExtended(CssUtils.extractUrl(backgroundImageStr));
9191
boolean repeatX = true, repeatY = true;
9292
if (backgroundRepeatStr != null) {
93-
repeatX = backgroundRepeatStr.equals(CssConstants.REPEAT) || backgroundRepeatStr.equals(CssConstants.REPEAT_X);
94-
repeatY = backgroundRepeatStr.equals(CssConstants.REPEAT) || backgroundRepeatStr.equals(CssConstants.REPEAT_Y);
93+
repeatX = CssConstants.REPEAT.equals(backgroundRepeatStr) || CssConstants.REPEAT_X.equals(backgroundRepeatStr);
94+
repeatY = CssConstants.REPEAT.equals(backgroundRepeatStr) || CssConstants.REPEAT_Y.equals(backgroundRepeatStr);
9595
}
9696
if (image != null) {
9797
BackgroundImage backgroundImage = null;

src/main/java/com/itextpdf/html2pdf/css/apply/util/FontStyleApplierUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public static void applyFontStyles(Map<String, String> cssProps, ProcessorContex
194194
}
195195

196196
String letterSpacing = cssProps.get(CssConstants.LETTER_SPACING);
197-
if (letterSpacing != null && !letterSpacing.equals(CssConstants.NORMAL)) {
197+
if (letterSpacing != null && !CssConstants.NORMAL.equals(letterSpacing)) {
198198
UnitValue letterSpacingValue = CssUtils.parseLengthValueToPt(letterSpacing, em, rem);
199199
if (letterSpacingValue.isPointValue()) {
200200
element.setProperty(Property.CHARACTER_SPACING, letterSpacingValue.getValue());

src/main/java/com/itextpdf/html2pdf/css/resolve/DefaultCssResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.html2pdf.attach.ProcessorContext;
4747
import com.itextpdf.html2pdf.css.CssConstants;
4848
import com.itextpdf.html2pdf.css.apply.util.CounterProcessorUtil;
49-
import com.itextpdf.html2pdf.css.apply.util.FontStyleApplierUtil;
5049
import com.itextpdf.html2pdf.exception.Html2PdfException;
5150
import com.itextpdf.html2pdf.html.AttributeConstants;
5251
import com.itextpdf.html2pdf.html.HtmlUtils;
@@ -81,6 +80,7 @@ This file is part of the iText (R) project.
8180

8281
import java.io.ByteArrayInputStream;
8382
import java.io.InputStream;
83+
import java.nio.charset.StandardCharsets;
8484
import java.util.ArrayList;
8585
import java.util.HashSet;
8686
import java.util.LinkedList;
@@ -284,7 +284,7 @@ private void collectCssDeclarations(INode rootNode, ResourceResolver resourceRes
284284
q.removeFirst();
285285
if (currentNode instanceof IElementNode) {
286286
IElementNode headChildElement = (IElementNode) currentNode;
287-
if (headChildElement.name().equals(TagConstants.STYLE)) {
287+
if (TagConstants.STYLE.equals(headChildElement.name())) {
288288
if (currentNode.childNodes().size() > 0 && currentNode.childNodes().get(0) instanceof IDataNode) {
289289
String styleData = ((IDataNode) currentNode.childNodes().get(0)).getWholeData();
290290
checkIfPagesCounterMentioned(styleData, cssContext);
@@ -297,7 +297,7 @@ private void collectCssDeclarations(INode rootNode, ResourceResolver resourceRes
297297
try {
298298
InputStream stream = resourceResolver.retrieveStyleSheet(styleSheetUri);
299299
byte[] bytes = StreamUtil.inputStreamToArray(stream);
300-
checkIfPagesCounterMentioned(new String(bytes), cssContext);
300+
checkIfPagesCounterMentioned(new String(bytes, StandardCharsets.UTF_8), cssContext);
301301
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new ByteArrayInputStream(bytes), resourceResolver.resolveAgainstBaseUri(styleSheetUri).toExternalForm());
302302
styleSheet = wrapStyleSheetInMediaQueryIfNecessary(headChildElement, styleSheet);
303303
cssStyleSheet.appendCssStyleSheet(styleSheet);

src/main/java/com/itextpdf/html2pdf/html/HtmlUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private HtmlUtils() {
6262
* @return true, if the element node represents a style sheet link
6363
*/
6464
public static boolean isStyleSheetLink(IElementNode headChildElement) {
65-
return headChildElement.name().equals(TagConstants.LINK)
65+
return TagConstants.LINK.equals(headChildElement.name())
6666
&& AttributeConstants.STYLESHEET.equals(headChildElement.getAttribute(AttributeConstants.REL));
6767
}
6868

0 commit comments

Comments
 (0)