Skip to content

Commit bda03d8

Browse files
committed
Usage: small improvements & clarifications
1 parent b25c18d commit bda03d8

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

usage.html

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -958,10 +958,15 @@ <h2>Parsing a style sheet</h2>
958958
</code></pre>
959959
<p>When the second argument is <a class="codeitem" href="api/latest/io.sf.carte.css4j/io/sf/carte/doc/style/css/CSSStyleSheet.html#COMMENTS_IGNORE">COMMENTS_IGNORE</a>, the comments in the source stream are ignored when parsing
960960
(see <a href="#sheetcomments"><em>Accessing Style Sheet Comments</em></a>).</p>
961-
<p>The new CSS rules found in the source stream are added to the already present ones, <em>i.e.</em> the sheet is not reset by this method
961+
<p>Important notes:</p>
962+
<ul>
963+
<li>Parsing a style sheet won't produce a <code>DOMException</code> unless the error handler (which you can
964+
customize) does raise it.</li>
965+
<li><p>The new CSS rules found in the source stream are added to the already present ones, <em>i.e.</em> the sheet is not reset by this method
962966
(although the error handler is), so if you want to refill a sheet you need to clear the rules before parsing:</p>
963967
<pre class="code"><code class="language-java">sheet.getCssRules().clear();
964-
</code></pre>
968+
</code></pre></li>
969+
</ul>
965970
</div>
966971
<div class="tema" id="securitymodel">
967972
<h2>Security model</h2>
@@ -1061,11 +1066,16 @@ <h2>Minification</h2>
10611066
// Create an empty style sheet
10621067
AbstractCSSStyleSheet sheet = cssFactory.createStyleSheet(null, null);
10631068
// Parse and check for return value
1064-
if (sheet.parseStyleSheet(new StringReader(css),
1065-
CSSStyleSheet.COMMENTS_IGNORE)) {
1066-
// Parsed without errors
1067-
return sheet.toMinifiedString();
1068-
} // Error detected, return the source
1069+
try {
1070+
if (sheet.parseStyleSheet(new StringReader(css),
1071+
CSSStyleSheet.COMMENTS_IGNORE)) {
1072+
// Parsed without errors
1073+
return sheet.toMinifiedString();
1074+
}
1075+
} catch (IOException e) {
1076+
// Cannot happen with StringReader
1077+
}
1078+
// Error detected, return the source
10691079
return css;
10701080
}
10711081
</code></pre>

0 commit comments

Comments
 (0)