Skip to content

Commit 8b3e03f

Browse files
committed
Updated deprecated methods
1 parent c3f0607 commit 8b3e03f

File tree

10 files changed

+80
-61
lines changed

10 files changed

+80
-61
lines changed

ph-css/src/main/java/com/helger/css/reader/CSSReader.java

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,21 @@ public static boolean isValidCSS (@Nonnull @WillClose final Reader aReader)
334334
}
335335
}
336336

337+
/**
338+
* Read the CSS from the passed String using a character stream. An eventually contained
339+
* <code>@charset</code> rule is ignored.
340+
*
341+
* @param sCSS
342+
* The source string containing the CSS to be parsed. May not be <code>null</code>.
343+
* @return <code>null</code> if reading failed, the CSS declarations otherwise.
344+
* @since 3.7.3
345+
*/
346+
@Nullable
347+
public static CascadingStyleSheet readFromString (@Nonnull final String sCSS)
348+
{
349+
return readFromStringReader (sCSS, new CSSReaderSettings ());
350+
}
351+
337352
/**
338353
* Read the CSS from the passed String using a byte stream.
339354
*
@@ -456,13 +471,16 @@ public static CascadingStyleSheet readFromStringStream (@Nonnull final String sC
456471
*
457472
* @param sCSS
458473
* The source string containing the CSS to be parsed. May not be <code>null</code>.
474+
* @param aSettings
475+
* The settings to be used for reading the CSS. May not be <code>null</code>.
459476
* @return <code>null</code> if reading failed, the CSS declarations otherwise.
460-
* @since 3.7.3
477+
* @since 3.8.2
461478
*/
462479
@Nullable
463-
public static CascadingStyleSheet readFromString (@Nonnull final String sCSS)
480+
public static CascadingStyleSheet readFromStringReader (@Nonnull final String sCSS,
481+
@Nonnull final CSSReaderSettings aSettings)
464482
{
465-
return readFromStringReader (sCSS, new CSSReaderSettings ());
483+
return readFromReader (new StringReaderProvider (sCSS), aSettings);
466484
}
467485

468486
/**
@@ -535,21 +553,16 @@ public static CascadingStyleSheet readFromString (@Nonnull final String sCSS,
535553
}
536554

537555
/**
538-
* Read the CSS from the passed String using a character stream. An eventually contained
539-
* <code>@charset</code> rule is ignored.
556+
* Read the CSS from the passed File.
540557
*
541-
* @param sCSS
542-
* The source string containing the CSS to be parsed. May not be <code>null</code>.
543-
* @param aSettings
544-
* The settings to be used for reading the CSS. May not be <code>null</code>.
558+
* @param aFile
559+
* The file containing the CSS to be parsed. May not be <code>null</code>.
545560
* @return <code>null</code> if reading failed, the CSS declarations otherwise.
546-
* @since 3.8.2
547561
*/
548562
@Nullable
549-
public static CascadingStyleSheet readFromStringReader (@Nonnull final String sCSS,
550-
@Nonnull final CSSReaderSettings aSettings)
563+
public static CascadingStyleSheet readFromFile (@Nonnull final File aFile)
551564
{
552-
return readFromReader (new StringReaderProvider (sCSS), aSettings);
565+
return readFromFile (aFile, new CSSReaderSettings ());
553566
}
554567

555568
/**
@@ -666,6 +679,22 @@ public static CascadingStyleSheet readFromFile (@Nonnull final File aFile, @Nonn
666679
return readFromStream (new FileSystemResource (aFile), aSettings);
667680
}
668681

682+
/**
683+
* Read the CSS from the passed {@link IHasInputStream}. If the CSS contains an explicit charset,
684+
* the whole CSS is parsed again, with the charset found inside the file, so the passed
685+
* {@link IHasInputStream} must be able to create a new input stream on second invocation!
686+
*
687+
* @param aISP
688+
* The input stream provider to use. Must be able to create new input streams on every
689+
* invocation, in case an explicit charset node was found. May not be <code>null</code>.
690+
* @return <code>null</code> if reading failed, the CSS declarations otherwise.
691+
*/
692+
@Nullable
693+
public static CascadingStyleSheet readFromStream (@Nonnull final IHasInputStream aISP)
694+
{
695+
return readFromStream (aISP, new CSSReaderSettings ());
696+
}
697+
669698
/**
670699
* Read the CSS from the passed {@link IHasInputStream}. If the CSS contains an explicit charset,
671700
* the whole CSS is parsed again, with the charset found inside the file, so the passed
@@ -815,6 +844,8 @@ public static Charset getCharsetDeclaredInCSS (@Nonnull final IHasInputStream aI
815844
* @return <code>null</code> if reading failed, the CSS declarations otherwise.
816845
*/
817846
@Nullable
847+
@Deprecated (forRemoval = true, since = "8.0.0")
848+
@DevelopersNote ("Use the version with CSSReaderSettings instead")
818849
public static CascadingStyleSheet readFromStream (@Nonnull final IHasInputStream aISP,
819850
@Nonnull final Charset aFallbackCharset,
820851
@Nullable final ICSSParseExceptionCallback aCustomExceptionHandler)
@@ -844,6 +875,8 @@ public static CascadingStyleSheet readFromStream (@Nonnull final IHasInputStream
844875
* @return <code>null</code> if reading failed, the CSS declarations otherwise.
845876
*/
846877
@Nullable
878+
@Deprecated (forRemoval = true, since = "8.0.0")
879+
@DevelopersNote ("Use the version with CSSReaderSettings instead")
847880
public static CascadingStyleSheet readFromStream (@Nonnull final IHasInputStream aISP,
848881
@Nonnull final Charset aFallbackCharset,
849882
@Nullable final ICSSParseErrorHandler aCustomErrorHandler,
@@ -973,6 +1006,8 @@ public static CascadingStyleSheet readFromStream (@Nonnull final IHasInputStream
9731006
* @since 3.7.3
9741007
*/
9751008
@Nullable
1009+
@Deprecated (forRemoval = true, since = "8.0.0")
1010+
@DevelopersNote ("Use the version with CSSReaderSettings instead")
9761011
public static CascadingStyleSheet readFromReader (@Nonnull final IHasReader aRP,
9771012
@Nullable final ICSSParseErrorHandler aCustomErrorHandler,
9781013
@Nullable final ICSSParseExceptionCallback aCustomExceptionHandler)

ph-css/src/test/java/com/helger/css/reader/CSSReaderFuncTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public void testReadSpecialGood ()
109109
{
110110
final Charset aCharset = StandardCharsets.UTF_8;
111111
final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/hacks2.css");
112-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
112+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile,
113+
new CSSReaderSettings ().setFallbackCharset (aCharset));
113114
assertNotNull (aCSS);
114115

115116
final String sCSS = new CSSWriter (false).getCSSAsString (aCSS);
@@ -124,7 +125,8 @@ public void testReadExpressions ()
124125
final CSSWriterSettings aCSSWS = new CSSWriterSettings (false);
125126
final Charset aCharset = StandardCharsets.UTF_8;
126127
final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/test-expression.css");
127-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
128+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile,
129+
new CSSReaderSettings ().setFallbackCharset (aCharset));
128130
assertNotNull (aCSS);
129131
assertEquals (1, aCSS.getRuleCount ());
130132
assertEquals (1, aCSS.getStyleRuleCount ());

ph-css/src/test/java/com/helger/css/reader/CSSReaderSpecialFuncTest.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ public final class CSSReaderSpecialFuncTest
5959
@Test
6060
public void testReadSpecialGood ()
6161
{
62-
final Charset aCharset = StandardCharsets.UTF_8;
6362
final File aFile = new File ("src/test/resources/testfiles/css30/good/issue63.css");
64-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
63+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
6564
assertNotNull (aCSS);
6665

6766
assertEquals ("--a", aCSS.getStyleRuleAtIndex (0).getDeclarationAtIndex (0).getProperty ());
@@ -84,7 +83,8 @@ public void testReadExpressions ()
8483
final CSSWriterSettings aCSSWS = new CSSWriterSettings (false);
8584
final Charset aCharset = StandardCharsets.UTF_8;
8685
final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/test-expression.css");
87-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
86+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile,
87+
new CSSReaderSettings ().setFallbackCharset (aCharset));
8888
assertNotNull (aCSS);
8989
assertEquals (1, aCSS.getRuleCount ());
9090
assertEquals (1, aCSS.getStyleRuleCount ());
@@ -305,8 +305,8 @@ public void testReadSpecialBadButRecoverable ()
305305
final Charset aCharset = StandardCharsets.UTF_8;
306306
final File aFile = new File ("src/test/resources/testfiles/css30/bad_but_recoverable_and_browsercompliant/test-string.css");
307307
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile,
308-
aCharset,
309-
aErrors.and (new LoggingCSSParseErrorHandler ()));
308+
new CSSReaderSettings ().setFallbackCharset (aCharset)
309+
.setCustomErrorHandler (aErrors.and (new LoggingCSSParseErrorHandler ())));
310310
assertNotNull (aFile.getAbsolutePath (), aCSS);
311311
}
312312

@@ -321,8 +321,8 @@ public void testReadWithBOM ()
321321
{
322322
final CascadingStyleSheet aCSS = CSSReader.readFromStream (new ByteArrayInputStreamProvider (ArrayHelper.getConcatenated (eBOM.getAllBytes (),
323323
sCSSBase.getBytes (aDeterminedCharset))),
324-
aDeterminedCharset,
325-
new DoNothingCSSParseErrorHandler ());
324+
new CSSReaderSettings ().setFallbackCharset (aDeterminedCharset)
325+
.setCustomErrorHandler (new DoNothingCSSParseErrorHandler ()));
326326
assertNotNull ("Failed to read with BOM " + eBOM, aCSS);
327327
assertEquals (".class{color:red}.class{color:blue}", new CSSWriter (true).getCSSAsString (aCSS));
328328
}
@@ -332,9 +332,8 @@ public void testReadWithBOM ()
332332
@Test
333333
public void testReadSingleLineComments ()
334334
{
335-
final Charset aCharset = StandardCharsets.UTF_8;
336335
final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/test-singleline-comments.css");
337-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
336+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
338337
assertNotNull (aCSS);
339338
assertEquals (24, aCSS.getRuleCount ());
340339
assertEquals (24, aCSS.getStyleRuleCount ());
@@ -361,9 +360,8 @@ public void testReadSingleLineComments ()
361360
@Test
362361
public void testReadFootnote ()
363362
{
364-
final Charset aCharset = StandardCharsets.UTF_8;
365363
final File aFile = new File ("src/test/resources/testfiles/css30/good/artificial/test-footnotes.css");
366-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
364+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
367365
assertNotNull (aCSS);
368366
assertEquals (5, aCSS.getRuleCount ());
369367
assertEquals (3, aCSS.getStyleRuleCount ());
@@ -380,9 +378,8 @@ public void testReadFootnote ()
380378
@Test
381379
public void testIssue101 ()
382380
{
383-
final Charset aCharset = StandardCharsets.UTF_8;
384381
final File aFile = new File ("src/test/resources/testfiles/css30/good/issue101.css");
385-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
382+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
386383
assertNotNull (aCSS);
387384
assertEquals (17, aCSS.getRuleCount ());
388385
assertEquals (17, aCSS.getStyleRuleCount ());
@@ -391,9 +388,8 @@ public void testIssue101 ()
391388
@Test
392389
public void testIssue110 ()
393390
{
394-
final Charset aCharset = StandardCharsets.UTF_8;
395391
final File aFile = new File ("src/test/resources/testfiles/css30/good/issue110.css");
396-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
392+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
397393
assertNotNull (aCSS);
398394
assertEquals (1, aCSS.getRuleCount ());
399395
assertEquals (1, aCSS.getStyleRuleCount ());
@@ -404,9 +400,8 @@ public void testIssue110 ()
404400
@Test
405401
public void testIssue112 ()
406402
{
407-
final Charset aCharset = StandardCharsets.UTF_8;
408403
final File aFile = new File ("src/test/resources/testfiles/css30/good/issue112.css");
409-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, aCharset);
404+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
410405
assertNotNull (aCSS);
411406
assertEquals (1, aCSS.getRuleCount ());
412407
assertEquals (1, aCSS.getStyleRuleCount ());

ph-css/src/test/java/com/helger/css/supplementary/issues/Issue4Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.helger.css.decl.CascadingStyleSheet;
2727
import com.helger.css.reader.CSSReader;
28+
import com.helger.css.reader.CSSReaderSettings;
2829
import com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler;
2930
import com.helger.css.writer.CSSWriter;
3031
import com.helger.io.resource.ClassPathResource;
@@ -43,9 +44,8 @@ public void testIssue4 ()
4344
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue4.css");
4445
assertTrue (aRes.exists ());
4546
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
46-
StandardCharsets.UTF_8,
47-
48-
new LoggingCSSParseErrorHandler ());
47+
new CSSReaderSettings ().setFallbackCharset (StandardCharsets.UTF_8)
48+
.setCustomErrorHandler (new LoggingCSSParseErrorHandler ()));
4949
assertNotNull (aCSS);
5050
if (false)
5151
System.out.println (new CSSWriter ().getCSSAsString (aCSS));

ph-css/src/test/java/com/helger/css/supplementary/issues/Issue8Test.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertTrue;
2222

23-
import java.nio.charset.StandardCharsets;
24-
2523
import org.junit.Test;
2624

2725
import com.helger.css.decl.CSSStyleRule;
2826
import com.helger.css.decl.CascadingStyleSheet;
2927
import com.helger.css.reader.CSSReader;
28+
import com.helger.css.reader.CSSReaderSettings;
3029
import com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler;
3130
import com.helger.io.resource.ClassPathResource;
3231
import com.helger.io.resource.IReadableResource;
@@ -44,9 +43,7 @@ public void testIssue8 ()
4443
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue8.css");
4544
assertTrue (aRes.exists ());
4645
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
47-
StandardCharsets.UTF_8,
48-
49-
new LoggingCSSParseErrorHandler ());
46+
new CSSReaderSettings ().setCustomErrorHandler (new LoggingCSSParseErrorHandler ()));
5047
assertNotNull (aCSS);
5148

5249
assertEquals (1, aCSS.getStyleRuleCount ());

ph-css/src/test/java/com/helger/css/supplementary/issues/Issue9Test.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
import static org.junit.Assert.assertNull;
2020
import static org.junit.Assert.assertTrue;
2121

22-
import java.nio.charset.StandardCharsets;
23-
2422
import org.junit.Test;
2523

2624
import com.helger.css.decl.CascadingStyleSheet;
2725
import com.helger.css.reader.CSSReader;
26+
import com.helger.css.reader.CSSReaderSettings;
2827
import com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler;
2928
import com.helger.io.resource.ClassPathResource;
3029
import com.helger.io.resource.IReadableResource;
@@ -43,9 +42,7 @@ public void testIssue9 ()
4342
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/bad/issue9.css");
4443
assertTrue (aRes.exists ());
4544
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
46-
StandardCharsets.UTF_8,
47-
48-
new LoggingCSSParseErrorHandler ());
45+
new CSSReaderSettings ().setCustomErrorHandler (new LoggingCSSParseErrorHandler ()));
4946
assertNull (aCSS);
5047
}
5148

@@ -56,9 +53,7 @@ public void testIssue9b ()
5653
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/bad/issue9b.css");
5754
assertTrue (aRes.exists ());
5855
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
59-
StandardCharsets.UTF_8,
60-
61-
new LoggingCSSParseErrorHandler ());
56+
new CSSReaderSettings ().setCustomErrorHandler (new LoggingCSSParseErrorHandler ()));
6257
assertNull (aCSS);
6358
}
6459
}

ph-css/src/test/java/com/helger/css/supplementary/issues/IssueGC22Test.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
import static org.junit.Assert.assertNotNull;
2020
import static org.junit.Assert.assertTrue;
2121

22-
import java.nio.charset.StandardCharsets;
23-
2422
import org.junit.Test;
2523

2624
import com.helger.css.decl.CascadingStyleSheet;
2725
import com.helger.css.reader.CSSReader;
26+
import com.helger.css.reader.CSSReaderSettings;
2827
import com.helger.css.reader.errorhandler.LoggingCSSParseErrorHandler;
2928
import com.helger.css.writer.CSSWriter;
3029
import com.helger.io.resource.ClassPathResource;
@@ -43,9 +42,7 @@ public void testIssue22 ()
4342
final IReadableResource aRes = new ClassPathResource ("testfiles/css30/good/issue-gc-22.css");
4443
assertTrue (aRes.exists ());
4544
final CascadingStyleSheet aCSS = CSSReader.readFromStream (aRes,
46-
StandardCharsets.UTF_8,
47-
48-
new LoggingCSSParseErrorHandler ());
45+
new CSSReaderSettings ().setCustomErrorHandler (new LoggingCSSParseErrorHandler ()));
4946
assertNotNull (aCSS);
5047
if (false)
5148
System.out.println (new CSSWriter ().getCSSAsString (aCSS));

ph-css/src/test/java/com/helger/css/supplementary/main/MainReadAllCSSOnDisc.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.helger.css.supplementary.main;
1818

1919
import java.io.File;
20-
import java.nio.charset.StandardCharsets;
2120
import java.util.Map;
2221

2322
import org.slf4j.Logger;
@@ -30,6 +29,7 @@
3029
import com.helger.css.handler.ICSSParseExceptionCallback;
3130
import com.helger.css.parser.ParseException;
3231
import com.helger.css.reader.CSSReader;
32+
import com.helger.css.reader.CSSReaderSettings;
3333
import com.helger.io.file.FileSystemRecursiveIterator;
3434
import com.helger.io.file.IFileFilter;
3535

@@ -54,7 +54,8 @@ public static void main (final String [] args)
5454
if (false)
5555
LOGGER.info (aFile.getAbsolutePath ());
5656
aCurrentFile.set (aFile);
57-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8, aHdl);
57+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile,
58+
new CSSReaderSettings ().setCustomExceptionHandler (aHdl));
5859
if (aCSS == null)
5960
{
6061
nFilesError++;

ph-css/src/test/java/com/helger/css/supplementary/wiki/WikiReadCSS.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.helger.css.supplementary.wiki;
1818

1919
import java.io.File;
20-
import java.nio.charset.StandardCharsets;
2120

2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
@@ -44,7 +43,7 @@ public final class WikiReadCSS
4443
public static CascadingStyleSheet readCSS30 (final File aFile)
4544
{
4645
// UTF-8 is the fallback if neither a BOM nor @charset rule is present
47-
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile, StandardCharsets.UTF_8);
46+
final CascadingStyleSheet aCSS = CSSReader.readFromFile (aFile);
4847
if (aCSS == null)
4948
{
5049
// Most probably a syntax error

0 commit comments

Comments
 (0)