A DESCRIPTION OF THE PROBLEM :
JDK-8267563 added support for stylesheets in the data-uri format to JavaFX. However, creating such stylesheets can still be a bit of a chore. Given that Java has supported multiline string literals since OpenJDK 15, it would be very convenient to have a utility method that accepts the CSS code and returns the corresponding stylesheet in the data-uri format. This would allow for seamless integration with Java code. Additionally, such a utility could be helpful when submitting CSS-related bug reports.
There is a public javafx.css.Stylesheet class, so adding a small helper method to it might be a good idea.
Draft:
public static final String DATA_URI_PREFIX = "data:base64,";
public static String toDataURI(String css) {
if (css == null) {
return "";
}
return DATA_URI_PREFIX + new String(Base64.getEncoder().encode(css.getBytes(UTF_8)), UTF_8);
}
There is a public javafx.css.Stylesheet class, so adding a small helper method to it might be a good idea.
Draft:
public static final String DATA_URI_PREFIX = "data:base64,";
public static String toDataURI(String css) {
if (css == null) {
return "";
}
return DATA_URI_PREFIX + new String(Base64.getEncoder().encode(css.getBytes(UTF_8)), UTF_8);
}