java.lang.Object
io.sf.carte.doc.style.css.util.Minify
Minify a CSS style sheet.
The regular minification methods first attempt a full minification by using the CSS parser, but in case that an unrecognized syntax is found, a safe, shallow minified serialization is used (with no CSS parsing involved).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConfiguration of normal minification.static interfaceConfiguration common to shallow and normal minification. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidPrints to standard output a minification of the CSS style sheet located at the supplied URI.static StringMinifies a CSS style sheet.static StringminifyCSS(String css, Minify.Config config, PrintStream err) Minifies a CSS style sheet and prints parsing errors to a stream.static booleanminifyCSS(URL url, Minify.Config config, StringBuilder buffer, PrintStream err) Minifies a CSS style sheet.static StringMinifies a CSS style sheet.static booleanminifyCSS(Path cssPath, Minify.Config config, StringBuilder buffer) Minifies a CSS style sheet.static booleanminifyCSS(Path cssPath, Minify.Config config, StringBuilder buffer, PrintStream err) Minifies a CSS style sheet.static voidshallowMinify(Reader cssReader, Minify.ShallowConfig config, StringBuilder buffer) Perform a safe, shallow minification that does not attempt to minify values nor media features.static voidshallowMinify(Reader cssReader, StringBuilder buffer) Perform a safe, shallow minification that does not attempt to minify values nor media features.
-
Constructor Details
-
Minify
public Minify()
-
-
Method Details
-
main
public static void main(String[] args) throws URISyntaxException, IllegalArgumentException, IOException Prints to standard output a minification of the CSS style sheet located at the supplied URI.The argument array must contain the style sheet path or URI, and any additional configuration:
--charset, followed by a valid character set name.--disable-shorthand. If followed by a comma-separated list of shorthand names, it disables the advanced minification for those shorthands. If alone, all advanced shorthand minification is disabled (same as--disable-shorthand all).--preserve-comment-char, followed by the character that marks the beginning of a comment that should be kept. Default is"!".--validateenables value validation.
If the configuration options are invalid, exits with a status code of
2.If the given sheet contains error(s), a shallower minification is performed and the process exits with a status of
1.- Parameters:
args- the arguments, including at least the URI or path to a style sheet.- Throws:
URISyntaxException- if the URI has wrong syntax.IllegalArgumentException- if the URI is otherwise incorrect.IOException- if an I/O error happened.
-
minifyCSS
Minifies a CSS style sheet.- Parameters:
css- the serialized style sheet.- Returns:
- the minified serialization.
-
minifyCSS
Minifies a CSS style sheet and prints parsing errors to a stream.- Parameters:
css- the serialized style sheet.config- the minification configuration, ornullif defaults should be used.err- the error reporting stream, ornullif no stream.- Returns:
- the minified serialization.
-
minifyCSS
Minifies a CSS style sheet.- Parameters:
cssPath- the path to autf-8-encoded style sheet.- Returns:
- the minified serialization.
- Throws:
IOException
-
minifyCSS
public static boolean minifyCSS(Path cssPath, Minify.Config config, StringBuilder buffer) throws IOException Minifies a CSS style sheet.- Parameters:
cssPath- the path to the style sheet.config- the minification configuration, ornullif defaults should be used.buffer- the buffer to write the minified serialization, or the original file if an error is found.- Returns:
trueif the style sheet was fully minified,falseif an error was found and the minification was shallow.- Throws:
IOException
-
minifyCSS
public static boolean minifyCSS(Path cssPath, Minify.Config config, StringBuilder buffer, PrintStream err) throws IOException Minifies a CSS style sheet.- Parameters:
cssPath- the path to the style sheet.config- the minification configuration, ornullif defaults should be used.buffer- the buffer to write the minified serialization.err- the error reporting stream, ornullif no stream.- Returns:
trueif the style sheet was fully minified,falseif a syntax error was found and the minification was shallow.- Throws:
IOException
-
minifyCSS
public static boolean minifyCSS(URL url, Minify.Config config, StringBuilder buffer, PrintStream err) throws IOException Minifies a CSS style sheet.- Parameters:
url- the url to the style sheet.config- the minification configuration, ornullif defaults should be used.buffer- the buffer to write the minified serialization.err- the error reporting stream, ornullif no stream.- Returns:
trueif the style sheet was fully minified,falseif a syntax error was found and the minification was shallow.- Throws:
IOException
-
shallowMinify
Perform a safe, shallow minification that does not attempt to minify values nor media features.- Parameters:
cssReader- theReaderwith the style sheet.buffer- the output buffer.- Throws:
IOException- if an I/O error happened reading the style sheet.
-
shallowMinify
public static void shallowMinify(Reader cssReader, Minify.ShallowConfig config, StringBuilder buffer) throws IOException Perform a safe, shallow minification that does not attempt to minify values nor media features.- Parameters:
cssReader- theReaderwith the style sheet.config- the minification configuration, ornullif defaults should be used.buffer- the output buffer.- Throws:
IOException- if an I/O error happened reading the style sheet.
-