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.color:red;
orbackground:uri(a.gif) !important;
)
Instances of this class are mutable since 3.7.4.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_IMPORTANT
-
Constructor Summary
Constructors Constructor Description CSSDeclaration(String sProperty, CSSExpression aExpression)
Constructor for non-important values.CSSDeclaration(String sProperty, CSSExpression aExpression, boolean bIsImportant)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
String
getAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel)
Get the contents of this object as a serialized CSS string for writing to an output.CSSExpression
getExpression()
String
getExpressionAsCSSString()
Get the CSS expression, but without an eventual `!String
getProperty()
CSSSourceLocation
getSourceLocation()
int
hashCode()
boolean
hasProperty(ECSSProperty eProperty)
Check if this declaration has the specified property.boolean
hasProperty(String sProperty)
Check if this declaration has the specified property.boolean
isImportant()
CSSDeclaration
setExpression(CSSExpression aExpression)
Set the expression (= value) of this declaration.CSSDeclaration
setImportant(boolean bIsImportant)
Set the important flag of this value.CSSDeclaration
setProperty(ECSSProperty eProperty)
Set the property of this CSS value (e.g.CSSDeclaration
setProperty(String sProperty)
Set the property of this CSS value (e.g.void
setSourceLocation(CSSSourceLocation aSourceLocation)
Set the source location of the object, determined while parsing.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.css.ICSSWriteable
getAsCSSString, getAsCSSString
-
-
-
-
Field Detail
-
DEFAULT_IMPORTANT
public static final boolean DEFAULT_IMPORTANT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CSSDeclaration
public CSSDeclaration(@Nonnull @Nonempty String sProperty, @Nonnull CSSExpression aExpression)
Constructor for non-important values.- Parameters:
sProperty
- The name of the property. E.g. "color". May neither benull
nor 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 benull
nor empty. The property value is automatically lowercased!aExpression
- The value of the property. May not benull
.bIsImportant
-true
if it is important,false
if not.
-
-
Method Detail
-
getProperty
@Nonnull @Nonempty public final String getProperty()
- Returns:
- The property of this declaration (e.g. "color" or "margin-top").
The string is always lowercase. Never
null
.
-
hasProperty
public final boolean hasProperty(@Nonnull String sProperty)
Check if this declaration has the specified property. The comparison is case insensitive!- Parameters:
sProperty
- The property to check. May not benull
.- Returns:
true
if this declaration has the specified property.- Since:
- 6.0.0
- See Also:
hasProperty(ECSSProperty)
-
hasProperty
public final boolean hasProperty(@Nonnull ECSSProperty eProperty)
Check if this declaration has the specified property. The comparison is case insensitive!- Parameters:
eProperty
- The property to check. May not benull
.- Returns:
true
if this declaration has the specified property.- Since:
- 6.0.0
- See Also:
hasProperty(String)
-
setProperty
@Nonnull public final CSSDeclaration setProperty(@Nonnull @Nonempty String sProperty)
Set the property of this CSS value (e.g.background-color
).- Parameters:
sProperty
- The CSS property name to set. May neither benull
nor empty. The property value is automatically lowercased!- Returns:
- this
- Since:
- 3.7.4
-
setProperty
@Nonnull public final CSSDeclaration setProperty(@Nonnull ECSSProperty eProperty)
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
@Nonnull @ReturnsMutableObject public final CSSExpression getExpression()
- Returns:
- The expression of this declaration (e.g. "red" or "25px" or "25px
10px 25px 9px") as a structured value. Never
null
.
-
getExpressionAsCSSString
@Nonnull public final String getExpressionAsCSSString()
Get the CSS expression, but without an eventual `!important` indicator!- Returns:
- The CSS expression as a parsable String. Never
null
.
-
setExpression
@Nonnull public final CSSDeclaration setExpression(@Nonnull CSSExpression aExpression)
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:
true
if this declaration is important (!important
) orfalse
if not.
-
setImportant
@Nonnull public final CSSDeclaration setImportant(boolean bIsImportant)
Set the important flag of this value.- Parameters:
bIsImportant
-true
to mark it important,false
to remove it.- Returns:
- this
- Since:
- 3.7.4
-
getAsCSSString
@Nonnull @Nonempty public String getAsCSSString(@Nonnull ICSSWriterSettings aSettings, @Nonnegative int nIndentLevel)
Description copied from interface:ICSSWriteable
Get the contents of this object as a serialized CSS string for writing to an output.- Specified by:
getAsCSSString
in 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
@Nullable public final CSSSourceLocation getSourceLocation()
- Specified by:
getSourceLocation
in interfaceICSSSourceLocationAware
- Returns:
- The source location of this object when it was read by the parser.
May be
null
if an object was not read but manually created.
-
setSourceLocation
public final void setSourceLocation(@Nullable CSSSourceLocation aSourceLocation)
Description copied from interface:ICSSSourceLocationAware
Set the source location of the object, determined while parsing.- Specified by:
setSourceLocation
in interfaceICSSSourceLocationAware
- Parameters:
aSourceLocation
- The source location to use. May benull
.
-
-