de.enough.polish.preprocess.css
Class Converter

java.lang.Object
  extended by de.enough.polish.preprocess.css.Converter
Direct Known Subclasses:
BackgroundConverter, BorderConverter, CssConverter, FontConverter, ParameterizedAttributeConverter

public class Converter
extends Object

Base class for several Creator classes.

Copyright Enough Software 2004 - 2011

 history
        10-Mar-2004 - rob creation
 

Author:
Robert Virkus, robert@enough.de

Field Summary
static Map<String,String> ANCHORS
           
protected  ColorConverter colorConverter
           
protected static String STANDALONE_MODIFIER
           
protected static String STANDALONE_MODIFIER_NON_FINAL
           
 
Constructor Summary
Converter()
          Creates a new instance.
 
Method Summary
static String getUrl(String url)
          Extracts the correct url from the given resource URL.
 boolean isAlphaColor(String color)
          Determines whether the given color has a defined alpha channel.
 String parseAnchor(String styleName, String groupName, String attributeName, String anchorValue)
          Parses the given anchor value.
 boolean parseBoolean(String styleName, String groupName, String name, String value)
          Parses the given boolean value.
 String parseColor(String value)
          Parses the given color.
 float parseFloat(String styleName, String groupName, String name, String value)
          Parse the given number into a float.
static int parseInt(String styleName, String groupName, String name, String value)
          Parses the given integer.
 int parseInt(String styleName, String groupName, String name, String value, int relativeValue)
          Parses the given number which can be a percentage value.
 String parseStroke(String styleName, String groupName, String name, String value)
          Parse the given stroke setting
 void print(Map attributes)
          Prints the specified attributes for logging purposes
 void setColorConverter(ColorConverter colorConverter)
          Sets the color converter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDALONE_MODIFIER

protected static final String STANDALONE_MODIFIER
See Also:
Constant Field Values

STANDALONE_MODIFIER_NON_FINAL

protected static final String STANDALONE_MODIFIER_NON_FINAL
See Also:
Constant Field Values

colorConverter

protected ColorConverter colorConverter

ANCHORS

public static final Map<String,String> ANCHORS
Constructor Detail

Converter

public Converter()
Creates a new instance.

Method Detail

setColorConverter

public void setColorConverter(ColorConverter colorConverter)
Sets the color converter.

Parameters:
colorConverter - the initialised color converter

parseInt

public static final int parseInt(String styleName,
                                 String groupName,
                                 String name,
                                 String value)
Parses the given integer.

Parameters:
styleName - the style name
groupName - the name of the group
name - the name of the field
value - the int value as a String
Returns:
the int value.
Throws:
BuildException - when the value could not be parsed.

parseBoolean

public boolean parseBoolean(String styleName,
                            String groupName,
                            String name,
                            String value)
Parses the given boolean value.

Parameters:
styleName - the style name
groupName - the name of the group
name - the name of the field
value - the boolean value as a String
Returns:
the boolean value.
Throws:
BuildException - when the value could not be parsed.

parseInt

public int parseInt(String styleName,
                    String groupName,
                    String name,
                    String value,
                    int relativeValue)
Parses the given number which can be a percentage value. If the number is a percentage value,

Parameters:
styleName - the style name
groupName - the name of the group
name - the name of the field
value - the int or percentage value as a String. A percentage value needs to end with a "%" character.
relativeValue - the number representing 100% if a percentage value is given.
Returns:
the resulting int value
Throws:
BuildException - when the value could not be parsed or when a percentage value is given and the given relativeValue is -1.

parseFloat

public float parseFloat(String styleName,
                        String groupName,
                        String name,
                        String value)
Parse the given number into a float.

Parameters:
styleName - the style name
groupName - the name of the group
name - the name of the field
value - the float value as a String.
Returns:
the resulting float value
Throws:
BuildException - when the value could not be parsed.

parseStroke

public String parseStroke(String styleName,
                          String groupName,
                          String name,
                          String value)
Parse the given stroke setting

Parameters:
styleName - the style name
groupName - the name of the group
name - the name of the field
value - the float value as a String.
Returns:
the resulting stroke value, either "Graphics.SOLID" or "Graphics.DOTTED"
Throws:
BuildException - when the value could not be parsed.

getUrl

public static final String getUrl(String url)
Extracts the correct url from the given resource URL.

Parameters:
url - the URL of the resource, e.g. "url( myPic.png )"
Returns:
the clean J2ME url, e.g. "/myPic.png"
Throws:
NullPointerException - when the url is null

parseColor

public String parseColor(String value)
Parses the given color.

Parameters:
value - the color, e.g. "rgb( 12, 12, 12 )" or "red"
Returns:
the color in a hexadecimal representation.

parseAnchor

public String parseAnchor(String styleName,
                          String groupName,
                          String attributeName,
                          String anchorValue)
Parses the given anchor value.

Parameters:
styleName - the name of the style
groupName - the name of the group
attributeName - the name of the attribute
anchorValue - the actual value, e.g. "top | left"
Returns:
a string containing the correct Java code, e.g. "Graphics.TOP | Graphics.LEFT"

isAlphaColor

public boolean isAlphaColor(String color)
Determines whether the given color has a defined alpha channel.

Parameters:
color - the color as a hexadecimal value
Returns:
true when the color has an alpha channel defined.

print

public void print(Map attributes)
Prints the specified attributes for logging purposes

Parameters:
attributes - the attributes that should be printed