Class CSSClass


  • public class CSSClass
    extends java.lang.Object
    Class representing a single CSS class.
    Since:
    0.2
    Author:
    Erich Schubert
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CSSClass.InvalidCSS
      Exception class thrown when encountering invalid CSS.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String name
      CSS class name
      private java.lang.ref.WeakReference<java.lang.Object> owner
      Owner.
      private java.util.Collection<Pair<java.lang.String,​java.lang.String>> statements
      Actual CSS statements
    • Constructor Summary

      Constructors 
      Constructor Description
      CSSClass​(java.lang.Object owner, java.lang.String name)
      Simplified constructor, empty statements list.
      CSSClass​(java.lang.Object owner, java.lang.String name, CSSClass other)
      Cloning constructor
      CSSClass​(java.lang.Object owner, java.lang.String name, java.util.Collection<Pair<java.lang.String,​java.lang.String>> statements)
      Full constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendCSSDefinition​(java.lang.StringBuilder buf)
      Append CSS definition to a stream
      static boolean checkCSSStatement​(java.lang.String key, java.lang.String value)
      Validate a single CSS statement.
      static boolean checkCSSStatements​(java.util.Collection<Pair<java.lang.String,​java.lang.String>> statements)
      Validate a set of CSS statements.
      static boolean checkName​(java.lang.String name)
      Verify that the name is an admissible CSS class name.
      java.lang.String getName()
      Get the class name.
      java.lang.Object getOwner()
      Get class owner.
      java.lang.String getStatement​(java.lang.String key)
      Get the current value of a particular CSS statement.
      java.util.Collection<Pair<java.lang.String,​java.lang.String>> getStatements()
      Get read-only collection access to all statements.
      java.lang.String inlineCSS()
      Render CSS class to inline formatting
      void removeStatement​(java.lang.String key)
      Remove a CSS statement.
      static java.lang.String sanitizeName​(java.lang.String name)
      Return a sanitized version of the given string.
      void setName​(java.lang.String name)
      Set the class name.
      void setStatement​(java.lang.String key, double value)
      Set a CSS statement.
      void setStatement​(java.lang.String key, int value)
      Set a CSS statement.
      void setStatement​(java.lang.String key, java.lang.String value)
      Set a CSS statement.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • name

        private java.lang.String name
        CSS class name
      • statements

        private java.util.Collection<Pair<java.lang.String,​java.lang.String>> statements
        Actual CSS statements
      • owner

        private java.lang.ref.WeakReference<java.lang.Object> owner
        Owner.
    • Constructor Detail

      • CSSClass

        public CSSClass​(java.lang.Object owner,
                        java.lang.String name,
                        java.util.Collection<Pair<java.lang.String,​java.lang.String>> statements)
        Full constructor
        Parameters:
        owner - Class owner (to detect conflicts)
        name - Class name
        statements - Collection of CSS statements
      • CSSClass

        public CSSClass​(java.lang.Object owner,
                        java.lang.String name)
        Simplified constructor, empty statements list.
        Parameters:
        owner - Class owner.
        name - Class name.
      • CSSClass

        public CSSClass​(java.lang.Object owner,
                        java.lang.String name,
                        CSSClass other)
        Cloning constructor
        Parameters:
        owner - Class owner.
        name - Class name.
        other - Class to clone
    • Method Detail

      • checkName

        public static boolean checkName​(java.lang.String name)
        Verify that the name is an admissible CSS class name. TODO: implement.
        Parameters:
        name - name to use
        Returns:
        true if valid CSS class name
      • sanitizeName

        public static java.lang.String sanitizeName​(java.lang.String name)
        Return a sanitized version of the given string. TODO: implement extensive checks.
        Parameters:
        name - name to sanitize
        Returns:
        Sanitized version.
      • checkCSSStatement

        public static boolean checkCSSStatement​(java.lang.String key,
                                                java.lang.String value)
        Validate a single CSS statement. TODO: implement extensive checks.
        Parameters:
        key - Key
        value - Value
        Returns:
        true if valid statement.
      • checkCSSStatements

        public static boolean checkCSSStatements​(java.util.Collection<Pair<java.lang.String,​java.lang.String>> statements)
        Validate a set of CSS statements. TODO: checks are currently not very extensive.
        Parameters:
        statements - Statements to check
        Returns:
        true if valid
      • getName

        public java.lang.String getName()
        Get the class name.
        Returns:
        class name.
      • setName

        public void setName​(java.lang.String name)
        Set the class name.
        Parameters:
        name - new class name.
      • getOwner

        public java.lang.Object getOwner()
        Get class owner.
        Returns:
        class owner.
      • getStatement

        public java.lang.String getStatement​(java.lang.String key)
        Get the current value of a particular CSS statement.
        Parameters:
        key - statement key.
        Returns:
        current value or null.
      • getStatements

        public java.util.Collection<Pair<java.lang.String,​java.lang.String>> getStatements()
        Get read-only collection access to all statements.
        Returns:
        Collection
      • setStatement

        public void setStatement​(java.lang.String key,
                                 java.lang.String value)
        Set a CSS statement.
        Parameters:
        key - Statement key.
        value - Value or null (to unset)
      • setStatement

        public void setStatement​(java.lang.String key,
                                 int value)
        Set a CSS statement.
        Parameters:
        key - Statement key.
        value - Value
      • setStatement

        public void setStatement​(java.lang.String key,
                                 double value)
        Set a CSS statement.
        Parameters:
        key - Statement key.
        value - Value
      • removeStatement

        public void removeStatement​(java.lang.String key)
        Remove a CSS statement.
        Parameters:
        key - Statement key.
      • appendCSSDefinition

        public void appendCSSDefinition​(java.lang.StringBuilder buf)
        Append CSS definition to a stream
        Parameters:
        buf - String buffer to append to.
      • inlineCSS

        public java.lang.String inlineCSS()
        Render CSS class to inline formatting
        Returns:
        string rendition of CSS for inline use