de.enough.polish.preprocess.css
Class Style

java.lang.Object
  extended by de.enough.polish.preprocess.css.Style

public class Style
extends Object

Represents a CSS-style-definition.

Copyright Enough Software 2004 - 2011

 history
        01-Mar-2004 - rob creation
 

Author:
Robert Virkus, robert@enough.de

Constructor Summary
Style(String selector, String styleName, boolean isDynamic, String parent, CssBlock cssBlock)
           
Style(Style style)
          Creates a new Style.
 
Method Summary
 void add(CssBlock cssBlock)
          Adds the given CSS declarations to this style.
 void add(Style style)
          Adds another style to this one.
 void addAttribute(String attributeName, String attributeValue)
          Adds the specified attribute to this style
 void addGroup(String groupName, AttributesGroup group)
          Adds a group to this style.
 void addReferencedStyle(Style referencedStyle)
          Adds a referenced style.
 String getAbbreviation()
          Retrieves the abbreviation of this style.
 String getAttributeValue(String attributeName)
          Retrieves the value for a given named attribute.
 CssDeclarationBlock[] getDeclarationBlocksEndingWith(String attributeBlockEnding)
          Gets all CSS declaration blocks ending with the specified name.
 String[] getDefinedAttributes(Device device)
          Retrieves the names of all defined attributes of this style.
 AttributesGroup getGroup(String groupName)
          Retrieves the group with the specified name.
 String[] getGroupNames()
          Retrieves the names of all stored groups.
 String getParentName()
           
 String[] getReferencedStyleNames(CssAttributesManager attributesManager)
          Retrieves the names of styles which are referenced by the this style.
 Style[] getReferencedStyles()
           
 String getSelector()
          Retrieves the name of this style.
 String getStyleName()
           
 String getValue(String groupName, String key)
          Retrieves a value from the specified group
 boolean hasReferences()
           
 boolean isDynamic()
           
 boolean isReferenced()
           
 boolean referencesStyle(String styleSelector)
          Checks if the specified style is referenced by this style
 CssDeclarationBlock[] removeDeclarationBlocksEndingWith(String attributeBlockEnding)
          Extracts all CSS declaration blocks ending with the specified name.
 AttributesGroup removeGroup(String groupName)
          Removes the group with the specified name from this style.
 void removeReferences(CssDeclarationBlock block)
          Removes references in the CSS groups for the given block
 void setAbbreviation(String abbreviation)
          Sets the abbreviation of this style.
 void setHasReferences(boolean hasReferences)
           
 void setIsReferenced(boolean isReferenced)
           
 void setParent(Style parent)
          Sets all style declarations of the parent.
 void setSelector(String selector)
          Changes the selector of this style.
 String toString()
          Creates String representation of this style.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Style

public Style(String selector,
             String styleName,
             boolean isDynamic,
             String parent,
             CssBlock cssBlock)

Style

public Style(Style style)
Creates a new Style.

Parameters:
style - the base style.
Method Detail

getParentName

public String getParentName()

setParent

public void setParent(Style parent)
Sets all style declarations of the parent. All styles implicitly extend the default-style. They also can extend another style explicitly with the "extends" keyword.

Parameters:
parent - the parent of this style.

referencesStyle

public boolean referencesStyle(String styleSelector)
Checks if the specified style is referenced by this style

Parameters:
styleSelector - the selector of the possibly referenced style
Returns:
true when it is referenced

add

public void add(CssBlock cssBlock)
Adds the given CSS declarations to this style.

Parameters:
cssBlock - the CSS declarations

add

public void add(Style style)
Adds another style to this one. Existing properties will be overwritten.

Parameters:
style - the style

getGroup

public AttributesGroup getGroup(String groupName)
Retrieves the group with the specified name.

Parameters:
groupName - the name of the group
Returns:
the map containing all defined attributes of the group

removeGroup

public AttributesGroup removeGroup(String groupName)
Removes the group with the specified name from this style.

Parameters:
groupName - the name of the group
Returns:
the map containing all defined attributes of the group

getGroupNames

public String[] getGroupNames()
Retrieves the names of all stored groups.

Returns:
an array with the names of all included groups.

getSelector

public String getSelector()
Retrieves the name of this style.

Returns:
the name of this style.

setSelector

public void setSelector(String selector)
Changes the selector of this style.

Parameters:
selector - the new selector

addGroup

public void addGroup(String groupName,
                     AttributesGroup group)
Adds a group to this style.

Parameters:
groupName - the name of the group
group - the group

toString

public String toString()
Creates String representation of this style. Is used for debugging purposes only,

Overrides:
toString in class Object
Returns:
the buffer plus contents as a string

isDynamic

public boolean isDynamic()
Returns:
Returns true when this style is a dynamic one

getStyleName

public String getStyleName()
Returns:
Returns the name of this style, which can be used instead of the selector for java-variables.

getDefinedAttributes

public String[] getDefinedAttributes(Device device)
Retrieves the names of all defined attributes of this style.

Parameters:
device - the current device
Returns:
a String array with all names of defined attributes. One attribute-name can appear several times.

getAbbreviation

public String getAbbreviation()
Retrieves the abbreviation of this style.

Returns:
the abbreviation of this style

setAbbreviation

public void setAbbreviation(String abbreviation)
Sets the abbreviation of this style.

Parameters:
abbreviation - the new abbreviation of this style

getReferencedStyleNames

public String[] getReferencedStyleNames(CssAttributesManager attributesManager)
Retrieves the names of styles which are referenced by the this style.

Parameters:
attributesManager - the attribute manager
Returns:
an array with names of referenced styles. Can be empty but not null.

setIsReferenced

public void setIsReferenced(boolean isReferenced)

isReferenced

public boolean isReferenced()

setHasReferences

public void setHasReferences(boolean hasReferences)

hasReferences

public boolean hasReferences()

addReferencedStyle

public void addReferencedStyle(Style referencedStyle)
Adds a referenced style.

Parameters:
referencedStyle - the style which is referenced by this style

getReferencedStyles

public Style[] getReferencedStyles()

getAttributeValue

public String getAttributeValue(String attributeName)
Retrieves the value for a given named attribute.

Parameters:
attributeName - the name of the attribute
Returns:
the value of the attribute

addAttribute

public void addAttribute(String attributeName,
                         String attributeValue)
Adds the specified attribute to this style

Parameters:
attributeName - the attribute name
attributeValue - the value

getDeclarationBlocksEndingWith

public CssDeclarationBlock[] getDeclarationBlocksEndingWith(String attributeBlockEnding)
Gets all CSS declaration blocks ending with the specified name.

Parameters:
attributeBlockEnding - the desired ending, e.g. "-animation"
Returns:
all matching declaration blocks

removeDeclarationBlocksEndingWith

public CssDeclarationBlock[] removeDeclarationBlocksEndingWith(String attributeBlockEnding)
Extracts all CSS declaration blocks ending with the specified name. This is used for extracting animations from the normal processing, for example. References within the normal CSS groups are removed afterwards.

Parameters:
attributeBlockEnding - the desired ending, e.g. "-animation"
Returns:
all matching declaration blocks

removeReferences

public void removeReferences(CssDeclarationBlock block)
Removes references in the CSS groups for the given block

Parameters:
block - the CSS declaration block

getValue

public String getValue(String groupName,
                       String key)
Retrieves a value from the specified group

Parameters:
groupName - the name of the group, e.g. "background"
key - the attribute key, e.g. "type"
Returns:
the associated value or null when the group does not exist or when the key is not registered