Class SafeStylesUtils
- java.lang.Object
-
- com.google.gwt.safecss.shared.SafeStylesUtils
-
public final class SafeStylesUtils extends java.lang.ObjectUtility class containing static methods for creatingSafeStyles.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classSafeStylesUtils.ImplDeprecated.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SafeStylesforBackgroundImage(SafeUri uri)Sets the background-image CSS property.static SafeStylesforBorderStyle(Style.BorderStyle value)Sets the border-style CSS property.static SafeStylesforBorderWidth(double value, Style.Unit unit)Set the border-width css property.static SafeStylesforBottom(double value, Style.Unit unit)Set the bottom css property.static SafeStylesforClear(Style.Clear value)Sets the 'clear' CSS property.static SafeStylesforCursor(Style.Cursor value)Sets the cursor CSS property.static SafeStylesforDisplay(Style.Display value)Sets the display CSS property.static SafeStylesforFloat(Style.Float value)Set the float css property.static SafeStylesforFontSize(double value, Style.Unit unit)Set the font-size css property.static SafeStylesforFontStyle(Style.FontStyle value)Sets the font-style CSS property.static SafeStylesforFontWeight(Style.FontWeight value)Sets the font-weight CSS property.static SafeStylesforHeight(double value, Style.Unit unit)Set the height css property.static SafeStylesforLeft(double value, Style.Unit unit)Set the left css property.static SafeStylesforLineHeight(double value, Style.Unit unit)Set the line-height css property.static SafeStylesforListStyleType(Style.ListStyleType value)Sets the list-style-type CSS property.static SafeStylesforMargin(double value, Style.Unit unit)Set the margin css property.static SafeStylesforMarginBottom(double value, Style.Unit unit)Set the margin-bottom css property.static SafeStylesforMarginLeft(double value, Style.Unit unit)Set the margin-left css property.static SafeStylesforMarginRight(double value, Style.Unit unit)Set the margin-right css property.static SafeStylesforMarginTop(double value, Style.Unit unit)Set the margin-top css property.static SafeStylesforOpacity(double value)Set the opacity css property.static SafeStylesforOutlineStyle(Style.OutlineStyle value)Sets the outline-style CSS property.static SafeStylesforOutlineWidth(double value, Style.Unit unit)Set the outline-width css property.static SafeStylesforOverflow(Style.Overflow value)Sets the overflow CSS property.static SafeStylesforOverflowX(Style.Overflow value)Sets the overflow-x CSS property.static SafeStylesforOverflowY(Style.Overflow value)Sets the overflow-y CSS property.static SafeStylesforPadding(double value, Style.Unit unit)Set the padding css property.static SafeStylesforPaddingBottom(double value, Style.Unit unit)Set the padding-bottom css property.static SafeStylesforPaddingLeft(double value, Style.Unit unit)Set the padding-left css property.static SafeStylesforPaddingRight(double value, Style.Unit unit)Set the padding-right css property.static SafeStylesforPaddingTop(double value, Style.Unit unit)Set the padding-top css property.static SafeStylesforPosition(Style.Position value)Sets the position CSS property.static SafeStylesforRight(double value, Style.Unit unit)Set the right css property.static SafeStylesforTableLayout(Style.TableLayout value)Set the table-layout CSS property.static SafeStylesforTextAlign(Style.TextAlign value)Sets the 'text-align' CSS property.static SafeStylesforTextDecoration(Style.TextDecoration value)Sets the 'text-decoration' CSS property.static SafeStylesforTextIndent(double value, Style.Unit unit)Set the 'text-indent' CSS property.static SafeStylesforTextJustify(Style.TextJustify value)Set the 'text-justify' CSS3 property.static SafeStylesforTextOverflow(Style.TextOverflow value)Set the 'text-overflow' CSS3 property.static SafeStylesforTextTransform(Style.TextTransform value)Set the 'text-transform' CSS property.static SafeStylesforTop(double value, Style.Unit unit)Set the top css property.static SafeStylesforTrustedBackgroundColor(java.lang.String value)Returns aSafeStylesconstructed from a trusted background color, i.e., without escaping the value.static SafeStylesforTrustedBackgroundImage(java.lang.String value)Returns aSafeStylesconstructed from a trusted background image, i.e., without escaping the value.static SafeStylesforTrustedBorderColor(java.lang.String value)Returns aSafeStylesconstructed from a trusted border color, i.e., without escaping the value.static SafeStylesforTrustedColor(java.lang.String value)Returns aSafeStylesconstructed from a trusted font color, i.e., without escaping the value.static SafeStylesforTrustedOutlineColor(java.lang.String value)Returns aSafeStylesconstructed from a trusted outline color, i.e., without escaping the value.static SafeStylesforVerticalAlign(double value, Style.Unit unit)Sets the vertical-align CSS property.static SafeStylesforVerticalAlign(Style.VerticalAlign value)Sets the vertical-align CSS property.static SafeStylesforVisibility(Style.Visibility value)Sets the visibility CSS property.static SafeStylesforWhiteSpace(Style.WhiteSpace value)Set the 'white-space' CSS property.static SafeStylesforWidth(double value, Style.Unit unit)Set the width css property.static SafeStylesforZIndex(int value)Set the z-index css property.static SafeStylesfromTrustedNameAndValue(java.lang.String name, double value, Style.Unit unit)Returns aSafeStylesconstructed from a trusted name and a trusted value, i.e., without escaping the name and value.static SafeStylesfromTrustedNameAndValue(java.lang.String name, java.lang.String value)Returns aSafeStylesconstructed from a trusted name and a trusted value, i.e., without escaping the name and value.static SafeStylesfromTrustedString(java.lang.String s)Returns aSafeStylesconstructed from a trusted string, i.e., without escaping the string.(package private) static voidverifySafeStylesConstraints(java.lang.String styles)Verify that the basic constraints of aSafeStylesare met.
-
-
-
Method Detail
-
forBackgroundImage
public static SafeStyles forBackgroundImage(SafeUri uri)
Sets the background-image CSS property.- Parameters:
uri- the URI of the background image- Returns:
- a
SafeStylesinstance - See Also:
forTrustedBackgroundImage(String)
-
forBorderStyle
public static SafeStyles forBorderStyle(Style.BorderStyle value)
Sets the border-style CSS property.
-
forBorderWidth
public static SafeStyles forBorderWidth(double value, Style.Unit unit)
Set the border-width css property.
-
forBottom
public static SafeStyles forBottom(double value, Style.Unit unit)
Set the bottom css property.
-
forClear
public static SafeStyles forClear(Style.Clear value)
Sets the 'clear' CSS property.
-
forCursor
public static SafeStyles forCursor(Style.Cursor value)
Sets the cursor CSS property.
-
forDisplay
public static SafeStyles forDisplay(Style.Display value)
Sets the display CSS property.
-
forFloat
public static SafeStyles forFloat(Style.Float value)
Set the float css property.
-
forFontSize
public static SafeStyles forFontSize(double value, Style.Unit unit)
Set the font-size css property.
-
forFontStyle
public static SafeStyles forFontStyle(Style.FontStyle value)
Sets the font-style CSS property.
-
forFontWeight
public static SafeStyles forFontWeight(Style.FontWeight value)
Sets the font-weight CSS property.
-
forHeight
public static SafeStyles forHeight(double value, Style.Unit unit)
Set the height css property.
-
forLeft
public static SafeStyles forLeft(double value, Style.Unit unit)
Set the left css property.
-
forLineHeight
public static SafeStyles forLineHeight(double value, Style.Unit unit)
Set the line-height css property.
-
forListStyleType
public static SafeStyles forListStyleType(Style.ListStyleType value)
Sets the list-style-type CSS property.
-
forMargin
public static SafeStyles forMargin(double value, Style.Unit unit)
Set the margin css property.
-
forMarginBottom
public static SafeStyles forMarginBottom(double value, Style.Unit unit)
Set the margin-bottom css property.
-
forMarginLeft
public static SafeStyles forMarginLeft(double value, Style.Unit unit)
Set the margin-left css property.
-
forMarginRight
public static SafeStyles forMarginRight(double value, Style.Unit unit)
Set the margin-right css property.
-
forMarginTop
public static SafeStyles forMarginTop(double value, Style.Unit unit)
Set the margin-top css property.
-
forOpacity
public static SafeStyles forOpacity(double value)
Set the opacity css property.
-
forOutlineStyle
public static SafeStyles forOutlineStyle(Style.OutlineStyle value)
Sets the outline-style CSS property.
-
forOutlineWidth
public static SafeStyles forOutlineWidth(double value, Style.Unit unit)
Set the outline-width css property.
-
forOverflow
public static SafeStyles forOverflow(Style.Overflow value)
Sets the overflow CSS property.
-
forOverflowX
public static SafeStyles forOverflowX(Style.Overflow value)
Sets the overflow-x CSS property.
-
forOverflowY
public static SafeStyles forOverflowY(Style.Overflow value)
Sets the overflow-y CSS property.
-
forPadding
public static SafeStyles forPadding(double value, Style.Unit unit)
Set the padding css property.
-
forPaddingBottom
public static SafeStyles forPaddingBottom(double value, Style.Unit unit)
Set the padding-bottom css property.
-
forPaddingLeft
public static SafeStyles forPaddingLeft(double value, Style.Unit unit)
Set the padding-left css property.
-
forPaddingRight
public static SafeStyles forPaddingRight(double value, Style.Unit unit)
Set the padding-right css property.
-
forPaddingTop
public static SafeStyles forPaddingTop(double value, Style.Unit unit)
Set the padding-top css property.
-
forPosition
public static SafeStyles forPosition(Style.Position value)
Sets the position CSS property.
-
forRight
public static SafeStyles forRight(double value, Style.Unit unit)
Set the right css property.
-
forTableLayout
public static SafeStyles forTableLayout(Style.TableLayout value)
Set the table-layout CSS property.
-
forTextAlign
public static SafeStyles forTextAlign(Style.TextAlign value)
Sets the 'text-align' CSS property.
-
forTextDecoration
public static SafeStyles forTextDecoration(Style.TextDecoration value)
Sets the 'text-decoration' CSS property.
-
forTextIndent
public static SafeStyles forTextIndent(double value, Style.Unit unit)
Set the 'text-indent' CSS property.
-
forTextJustify
public static SafeStyles forTextJustify(Style.TextJustify value)
Set the 'text-justify' CSS3 property.
-
forTextOverflow
public static SafeStyles forTextOverflow(Style.TextOverflow value)
Set the 'text-overflow' CSS3 property.
-
forTextTransform
public static SafeStyles forTextTransform(Style.TextTransform value)
Set the 'text-transform' CSS property.
-
forTop
public static SafeStyles forTop(double value, Style.Unit unit)
Set the top css property.
-
forTrustedBackgroundColor
public static SafeStyles forTrustedBackgroundColor(java.lang.String value)
Returns a
SafeStylesconstructed from a trusted background color, i.e., without escaping the value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.- Parameters:
value- the property value- Returns:
- a
SafeStylesinstance
-
forTrustedBackgroundImage
public static SafeStyles forTrustedBackgroundImage(java.lang.String value)
Returns a
SafeStylesconstructed from a trusted background image, i.e., without escaping the value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.- Parameters:
value- the property value- Returns:
- a
SafeStylesinstance - See Also:
forBackgroundImage(SafeUri)
-
forTrustedBorderColor
public static SafeStyles forTrustedBorderColor(java.lang.String value)
Returns a
SafeStylesconstructed from a trusted border color, i.e., without escaping the value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.- Parameters:
value- the property value- Returns:
- a
SafeStylesinstance
-
forTrustedColor
public static SafeStyles forTrustedColor(java.lang.String value)
Returns a
SafeStylesconstructed from a trusted font color, i.e., without escaping the value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.- Parameters:
value- the property value- Returns:
- a
SafeStylesinstance
-
forTrustedOutlineColor
public static SafeStyles forTrustedOutlineColor(java.lang.String value)
Returns a
SafeStylesconstructed from a trusted outline color, i.e., without escaping the value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.- Parameters:
value- the property value- Returns:
- a
SafeStylesinstance
-
forVerticalAlign
public static SafeStyles forVerticalAlign(double value, Style.Unit unit)
Sets the vertical-align CSS property.
-
forVerticalAlign
public static SafeStyles forVerticalAlign(Style.VerticalAlign value)
Sets the vertical-align CSS property.
-
forVisibility
public static SafeStyles forVisibility(Style.Visibility value)
Sets the visibility CSS property.
-
forWhiteSpace
public static SafeStyles forWhiteSpace(Style.WhiteSpace value)
Set the 'white-space' CSS property.
-
forWidth
public static SafeStyles forWidth(double value, Style.Unit unit)
Set the width css property.
-
forZIndex
public static SafeStyles forZIndex(int value)
Set the z-index css property.
-
fromTrustedNameAndValue
public static SafeStyles fromTrustedNameAndValue(java.lang.String name, double value, Style.Unit unit)
Returns a
SafeStylesconstructed from a trusted name and a trusted value, i.e., without escaping the name and value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.The name should be in hyphenated format, not camelCase format.
- Parameters:
name- the property namevalue- the valueunit- the units of the value- Returns:
- a
SafeStylesinstance
-
fromTrustedNameAndValue
public static SafeStyles fromTrustedNameAndValue(java.lang.String name, java.lang.String value)
Returns a
SafeStylesconstructed from a trusted name and a trusted value, i.e., without escaping the name and value. No checks are performed. The calling code should be carefully reviewed to ensure the argument will satisfy theSafeStylescontract when they are composed into the form: "<name>:<value>;".SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.The name should be in hyphenated format, not camelCase format.
- Parameters:
name- the property namevalue- the property value- Returns:
- a
SafeStylesinstance
-
fromTrustedString
public static SafeStyles fromTrustedString(java.lang.String s)
Returns a
SafeStylesconstructed from a trusted string, i.e., without escaping the string. No checks are performed. The calling code should be carefully reviewed to ensure the argument meets theSafeStylescontract.Generally,
SafeStylesshould be of the formcssPropertyName:value;, where neither the name nor the value contain malicious scripts.SafeStylesmay never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStylesinto a <style> tag (where it can't be HTML escaped). For example, if theSafeStylescontaining "font: 'foo <style><script>evil</script>'" is used in a style sheet in a <style> tag, this could then break out of the style context into HTML.The following example values comply with this type's contract:
width: 1em;height:1em;width: 1em;height: 1em;background:url('http://url');
The following example values do not comply with this type's contract:
background: red(missing a trailing semi-colon)background:(missing a value and a trailing semi-colon)1em(missing an attribute name, which provides context for the value)
- Parameters:
s- the input String- Returns:
- a
SafeStylesinstance
-
verifySafeStylesConstraints
static void verifySafeStylesConstraints(java.lang.String styles)
Verify that the basic constraints of aSafeStylesare met. This method is not a guarantee that the specified css is safe for use in a CSS style attribute. It is a minimal set of assertions to check for common errors.- Parameters:
styles- the CSS properties string- Throws:
java.lang.NullPointerException- if the css is nulljava.lang.AssertionError- if the css does not meet the constraints
-
-