Class SafeStylesBuilder
SafeStyles
. It is used essentially like a StringBuilder
,
but access SafeStyles
instead of Strings.
The accumulated XSS-safe SafeStyles
can be obtained in the form of a
SafeStyles
via the toSafeStyles()
method.
This class is not thread-safe.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionappend
(SafeStyles styles) Appends the contents of anotherSafeStyles
object, without applying any escaping or sanitization to it.appendTrustedString
(String styles) AppendsSafeStyles
constructed from a trusted string, i.e., without escaping the string.backgroundImage
(SafeUri uri) Append the background-image CSS property.borderStyle
(Style.BorderStyle value) Append the border-style CSS property.borderWidth
(double value, Style.Unit unit) Append the border-width css property.bottom
(double value, Style.Unit unit) Append the bottom css property.clear
(Style.Clear value) Append the 'clear' CSS property.cursor
(Style.Cursor value) Append the cursor CSS property.display
(Style.Display value) Append the display CSS property.floatprop
(Style.Float value) Append the float css property.fontSize
(double value, Style.Unit unit) Append the font-size css property.fontStyle
(Style.FontStyle value) Append the font-style CSS property.fontWeight
(Style.FontWeight value) Append the font-weight CSS property.height
(double value, Style.Unit unit) Append the height css property.left
(double value, Style.Unit unit) Append the left css property.listStyleType
(Style.ListStyleType value) Append the list-style-type CSS property.margin
(double value, Style.Unit unit) Append the margin css property.marginBottom
(double value, Style.Unit unit) Append the margin-bottom css property.marginLeft
(double value, Style.Unit unit) Append the margin-left css property.marginRight
(double value, Style.Unit unit) Append the margin-right css property.marginTop
(double value, Style.Unit unit) Append the margin-top css property.opacity
(double value) Append the opacity css property.overflow
(Style.Overflow value) Append the overflow CSS property.overflowX
(Style.Overflow value) Append the overflow-x CSS property.overflowY
(Style.Overflow value) Append the overflow-y CSS property.padding
(double value, Style.Unit unit) Append the padding css property.paddingBottom
(double value, Style.Unit unit) Append the padding-bottom css property.paddingLeft
(double value, Style.Unit unit) Append the padding-left css property.paddingRight
(double value, Style.Unit unit) Append the padding-right css property.paddingTop
(double value, Style.Unit unit) Append the padding-top css property.position
(Style.Position value) Append the position CSS property.right
(double value, Style.Unit unit) Append the right css property.tableLayout
(Style.TableLayout value) Append the table-layout CSS property.textAlign
(Style.TextAlign value) Append the 'text-align' CSS property.Append the text-decoration CSS property.textIndent
(double value, Style.Unit unit) Append the 'text-indent' CSS property.textJustify
(Style.TextJustify value) Append the 'text-justify' CSS3 property.textOverflow
(Style.TextOverflow value) Append the 'text-overflow' CSS3 property.textTransform
(Style.TextTransform value) Append the 'text-transform' CSS property.top
(double value, Style.Unit unit) Append the top css property.Returns the safe CSS properties accumulated in the builder as aSafeStyles
.trustedBackgroundColor
(String value) Append the trusted background color, i.e., without escaping the value.trustedBackgroundImage
(String value) Append the trusted background image, i.e., without escaping the value.trustedBorderColor
(String value) Append the trusted border color, i.e., without escaping the value.trustedColor
(String value) Append the trusted font color, i.e., without escaping the value.trustedNameAndValue
(String name, double value, Style.Unit unit) Append aSafeStyles
constructed from a trusted name and a trusted value, i.e., without escaping the name and value.trustedNameAndValue
(String name, String value) Append aSafeStyles
constructed from a trusted name and a trusted value, i.e., without escaping the name and value.verticalAlign
(double value, Style.Unit unit) Append the vertical-align CSS property.verticalAlign
(Style.VerticalAlign value) Append the vertical-align CSS property.visibility
(Style.Visibility value) Append the visibility CSS property.whiteSpace
(Style.WhiteSpace whiteSpace) Append the 'white-space' CSS property.width
(double value, Style.Unit unit) Append the width css property.zIndex
(int value) Append the z-index css property.
-
Constructor Details
-
SafeStylesBuilder
public SafeStylesBuilder()Constructs an emptySafeStylesBuilder
.
-
-
Method Details
-
appendTrustedString
Appends
SafeStyles
constructed from a trusted string, i.e., without escaping the string. Only minimal checks are performed. The calling code should be carefully reviewed to ensure the argument meets theSafeStyles
contract.Generally,
SafeStyles
should be of the formcssPropertyName:value;
, where neither the name nor the value contain malicious scripts.SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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:
styles
- the input String- Returns:
- a
SafeStyles
instance
-
borderStyle
Append the border-style CSS property. -
borderWidth
Append the border-width css property. -
bottom
Append the bottom css property. -
clear
Append the 'clear' CSS property. -
cursor
Append the cursor CSS property. -
display
Append the display CSS property. -
floatprop
Append the float css property.Note: This method has the suffix "prop" to avoid Java compilation errors. The term "float" is a reserved word in Java representing the primitive float.
-
fontSize
Append the font-size css property. -
fontStyle
Append the font-style CSS property. -
fontWeight
Append the font-weight CSS property. -
height
Append the height css property. -
left
Append the left css property. -
listStyleType
Append the list-style-type CSS property. -
margin
Append the margin css property. -
marginBottom
Append the margin-bottom css property. -
marginLeft
Append the margin-left css property. -
marginRight
Append the margin-right css property. -
marginTop
Append the margin-top css property. -
opacity
Append the opacity css property. -
overflow
Append the overflow CSS property. -
overflowX
Append the overflow-x CSS property. -
overflowY
Append the overflow-y CSS property. -
padding
Append the padding css property. -
paddingBottom
Append the padding-bottom css property. -
paddingLeft
Append the padding-left css property. -
paddingRight
Append the padding-right css property. -
paddingTop
Append the padding-top css property. -
position
Append the position CSS property. -
right
Append the right css property. -
tableLayout
Append the table-layout CSS property. -
textAlign
Append the 'text-align' CSS property. -
textDecoration
Append the text-decoration CSS property. -
textIndent
Append the 'text-indent' CSS property. -
textJustify
Append the 'text-justify' CSS3 property. -
textOverflow
Append the 'text-overflow' CSS3 property. -
textTransform
Append the 'text-transform' CSS property. -
top
Append the top css property. -
toSafeStyles
Returns the safe CSS properties accumulated in the builder as aSafeStyles
.- Returns:
- a
SafeStyles
instance
-
trustedBackgroundColor
Append the 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 the
SafeStyles
contract when they are composed into the form: "<name>:<value>;".SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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
SafeStyles
instance
-
trustedBackgroundImage
Append the 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 the
SafeStyles
contract when they are composed into the form: "<name>:<value>;".SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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
SafeStyles
instance - See Also:
-
trustedBorderColor
Append the 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 the
SafeStyles
contract when they are composed into the form: "<name>:<value>;".SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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
SafeStyles
instance
-
trustedColor
Append the 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 the
SafeStyles
contract when they are composed into the form: "<name>:<value>;".SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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
SafeStyles
instance
-
trustedNameAndValue
Append a
SafeStyles
constructed 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 theSafeStyles
contract when they are composed into the form: "<name>:<value>;".SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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
SafeStyles
instance
-
trustedNameAndValue
Append a
SafeStyles
constructed 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 theSafeStyles
contract when they are composed into the form: "<name>:<value>;".SafeStyles
may never contain literal angle brackets. Otherwise, it could be unsafe to place aSafeStyles
into a <style> tag (where it can't be HTML escaped). For example, if theSafeStyles
containing "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
SafeStyles
instance
-
verticalAlign
Append the vertical-align CSS property. -
verticalAlign
Append the vertical-align CSS property. -
visibility
Append the visibility CSS property. -
whiteSpace
Append the 'white-space' CSS property. -
width
Append the width css property. -
zIndex
Append the z-index css property.