Package com.helger.css.decl
Class CSSDeclaration
java.lang.Object
com.helger.css.decl.CSSDeclaration
- All Implemented Interfaces:
ICSSPageRuleMember,ICSSSourceLocationAware,ICSSWriteable
@NotThreadSafe
public class CSSDeclaration
extends Object
implements ICSSSourceLocationAware, ICSSPageRuleMember
Represents a single element in a CSS style rule. (eg.
Instances of this class are mutable since 3.7.4.
color:red;
or background:uri(a.gif) !important;)Instances of this class are mutable since 3.7.4.
- Author:
- Philip Helger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCSSDeclaration(String sProperty, CSSExpression aExpression) Constructor for non-important values.CSSDeclaration(String sProperty, CSSExpression aExpression, boolean bIsImportant) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleangetAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel) Get the contents of this object as a serialized CSS string for writing to an output.final CSSExpressionfinal StringGet the CSS expression, but without an eventual `!final Stringfinal CSSSourceLocationinthashCode()final booleanhasProperty(ECSSProperty eProperty) Check if this declaration has the specified property.final booleanhasProperty(String sProperty) Check if this declaration has the specified property.final booleanfinal CSSDeclarationsetExpression(CSSExpression aExpression) Set the expression (= value) of this declaration.final CSSDeclarationsetImportant(boolean bIsImportant) Set the important flag of this value.final CSSDeclarationsetProperty(ECSSProperty eProperty) Set the property of this CSS value (e.g.final CSSDeclarationsetProperty(String sProperty) Set the property of this CSS value (e.g.final voidsetSourceLocation(CSSSourceLocation aSourceLocation) Set the source location of the object, determined while parsing.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.css.ICSSWriteable
getAsCSSString, getAsCSSString
-
Field Details
-
DEFAULT_IMPORTANT
public static final boolean DEFAULT_IMPORTANT- See Also:
-
-
Constructor Details
-
CSSDeclaration
Constructor for non-important values.- Parameters:
sProperty- The name of the property. E.g. "color". May neither benullnor empty. The property value is automatically lowercased!aExpression- The value of the property. May not benull.
-
CSSDeclaration
public CSSDeclaration(@Nonnull @Nonempty String sProperty, @Nonnull CSSExpression aExpression, boolean bIsImportant) Constructor.- Parameters:
sProperty- The name of the property. E.g. "color". May neither benullnor empty. The property value is automatically lowercased!aExpression- The value of the property. May not benull.bIsImportant-trueif it is important,falseif not.
-
-
Method Details
-
getProperty
- Returns:
- The property of this declaration (e.g. "color" or "margin-top").
The string is always lowercase. Never
null.
-
hasProperty
Check if this declaration has the specified property. The comparison is case insensitive!- Parameters:
sProperty- The property to check. May not benull.- Returns:
trueif this declaration has the specified property.- Since:
- 6.0.0
- See Also:
-
hasProperty
Check if this declaration has the specified property. The comparison is case insensitive!- Parameters:
eProperty- The property to check. May not benull.- Returns:
trueif this declaration has the specified property.- Since:
- 6.0.0
- See Also:
-
setProperty
Set the property of this CSS value (e.g.background-color).- Parameters:
sProperty- The CSS property name to set. May neither benullnor empty. The property value is automatically lowercased!- Returns:
- this
- Since:
- 3.7.4
-
setProperty
Set the property of this CSS value (e.g.background-color).- Parameters:
eProperty- The CSS property to set. May not benull.- Returns:
- this
- Since:
- 3.7.4
-
getExpression
- Returns:
- The expression of this declaration (e.g. "red" or "25px" or "25px
10px 25px 9px") as a structured value. Never
null.
-
getExpressionAsCSSString
Get the CSS expression, but without an eventual `!important` indicator!- Returns:
- The CSS expression as a parsable String. Never
null.
-
setExpression
Set the expression (= value) of this declaration.- Parameters:
aExpression- The value of the property. May not benull.- Returns:
- this
- Since:
- 3.7.4
-
isImportant
public final boolean isImportant()- Returns:
trueif this declaration is important (!important) orfalseif not.
-
setImportant
Set the important flag of this value.- Parameters:
bIsImportant-trueto mark it important,falseto remove it.- Returns:
- this
- Since:
- 3.7.4
-
getAsCSSString
@Nonnull @Nonempty public String getAsCSSString(@Nonnull ICSSWriterSettings aSettings, @Nonnegative int nIndentLevel) Description copied from interface:ICSSWriteableGet the contents of this object as a serialized CSS string for writing to an output.- Specified by:
getAsCSSStringin interfaceICSSWriteable- Parameters:
aSettings- The settings to be used to format the output. May not benull.nIndentLevel- The current indentation level- Returns:
- The content of this object as CSS string. Never
null.
-
getSourceLocation
- Specified by:
getSourceLocationin interfaceICSSSourceLocationAware- Returns:
- The source location of this object when it was read by the parser.
May be
nullif an object was not read but manually created.
-
setSourceLocation
Description copied from interface:ICSSSourceLocationAwareSet the source location of the object, determined while parsing.- Specified by:
setSourceLocationin interfaceICSSSourceLocationAware- Parameters:
aSourceLocation- The source location to use. May benull.
-
equals
-
hashCode
public int hashCode() -
toString
-