Class SvgDataUriGenerator
- java.lang.Object
-
- org.kie.workbench.common.stunner.core.client.util.SvgDataUriGenerator
-
@ApplicationScoped public class SvgDataUriGenerator extends Object
An util class that consumes and generates an SVG data-uri, but it performs additional operations.
-
-
Field Summary
Fields Modifier and Type Field Description static StringSVG_CONTENT_TYPEstatic StringSVG_DATA_URI_BASE64static StringSVG_DATA_URI_UTF8
-
Constructor Summary
Constructors Constructor Description SvgDataUriGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringencodeBase64(String dataUriDecoded)Encodes the specified data-uri string in XML/Base64 format.static StringencodeUtf8(String dataUriDecoded)Encodes the specified data-uri string in XML/UTF8 format.Stringgenerate(com.google.gwt.safehtml.shared.SafeUri svgUri)Generates an SVG data-uri with no external resource references, if any.Stringgenerate(com.google.gwt.safehtml.shared.SafeUri svgUri, Collection<com.google.gwt.safehtml.shared.SafeUri> svgDefs, Collection<String> validUseRefIds)Generates a single SVG data-uri from different input SVG declarations.
-
-
-
Field Detail
-
SVG_CONTENT_TYPE
public static final String SVG_CONTENT_TYPE
- See Also:
- Constant Field Values
-
SVG_DATA_URI_BASE64
public static final String SVG_DATA_URI_BASE64
- See Also:
- Constant Field Values
-
SVG_DATA_URI_UTF8
public static final String SVG_DATA_URI_UTF8
- See Also:
- Constant Field Values
-
-
Method Detail
-
encodeUtf8
public static String encodeUtf8(String dataUriDecoded)
Encodes the specified data-uri string in XML/UTF8 format.
-
encodeBase64
public static String encodeBase64(String dataUriDecoded)
Encodes the specified data-uri string in XML/Base64 format.
-
generate
public String generate(com.google.gwt.safehtml.shared.SafeUri svgUri)
Generates an SVG data-uri with no external resource references, if any. GWT DataResource does not support external references, used for example by theuseelement.
-
generate
public String generate(com.google.gwt.safehtml.shared.SafeUri svgUri, Collection<com.google.gwt.safehtml.shared.SafeUri> svgDefs, Collection<String> validUseRefIds)
Generates a single SVG data-uri from different input SVG declarations. As GWT DataResource does not like SVG external references, this is an alternative solution that creates a composite SVG declaration by joining each SVG declaration given from the arguments. Given a parent SVG declaration, which contain external resource references to other SVG declarations, and its given SVG referenced declarations, it aggregates the referenced elements in a SVGDefelement, and generates a composite SVG which encapsulates the parent and referenced ones in a single declaration. It also handles the external resource references, within the parent SVG, in order to match the actual content, and removes the invalid references. It generates a valid SVG declaration as:- Parameters:
svgUri- The parent SVG declaration data-uri, which may contain external resource references.svgDefs- The external resources which are referenced in the parent SVG declaration, given by thesvgUriargument.validUseRefIds- The valid external reference identifiers to keep in the resulting declaration. Usually those are the SVG identifiers for each of the declarations given by thesvgDefsargument.
-
-