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; or background:uri(a.gif) !important;)
Instances of this class are mutable since 3.7.4.
Author:
Philip Helger
  • Field Details

  • Constructor Details

    • 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 be null nor empty. The property value is automatically lowercased!
      aExpression - The value of the property. May not be null.
    • 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 be null nor empty. The property value is automatically lowercased!
      aExpression - The value of the property. May not be null.
      bIsImportant - true if it is important, false if not.
  • Method Details

    • 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 be null.
      Returns:
      true if this declaration has the specified property.
      Since:
      6.0.0
      See Also:
    • 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 be null.
      Returns:
      true if this declaration has the specified property.
      Since:
      6.0.0
      See Also:
    • 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 be null 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 be null.
      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 be null.
      Returns:
      this
      Since:
      3.7.4
    • isImportant

      public final boolean isImportant()
      Returns:
      true if this declaration is important ( !important) or false 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 interface ICSSWriteable
      Parameters:
      aSettings - The settings to be used to format the output. May not be null.
      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 interface ICSSSourceLocationAware
      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 interface ICSSSourceLocationAware
      Parameters:
      aSourceLocation - The source location to use. May be null.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object