|
Lines 42-51
Link Here
|
| 42 |
|
42 |
|
| 43 |
private static final String ATTR_NAME = "name"; |
43 |
private static final String ATTR_NAME = "name"; |
| 44 |
|
44 |
|
| 45 |
private static final String ATTR_TYPE = "type"; |
|
|
| 46 |
|
| 47 |
private static final String ATTR_DESCRIPTION = "description"; |
| 48 |
|
| 49 |
public static final String TYPE_BOOLEAN = "boolean"; |
45 |
public static final String TYPE_BOOLEAN = "boolean"; |
| 50 |
|
46 |
|
| 51 |
public static final String TYPE_BORDER = "border"; |
47 |
public static final String TYPE_BORDER = "border"; |
|
Lines 128-135
Link Here
|
| 128 |
String name = getAttributeValue( node, ATTR_NAME ); |
124 |
String name = getAttributeValue( node, ATTR_NAME ); |
| 129 |
ThemeCssElement themeElement = new ThemeCssElement( name ); |
125 |
ThemeCssElement themeElement = new ThemeCssElement( name ); |
| 130 |
cssElements.add( themeElement ); |
126 |
cssElements.add( themeElement ); |
| 131 |
String description = getElementOrAttributeValue( node, ATTR_DESCRIPTION ); |
|
|
| 132 |
themeElement.setDescription( description ); |
| 133 |
NodeList childNodes = node.getChildNodes(); |
127 |
NodeList childNodes = node.getChildNodes(); |
| 134 |
for( int i = 0; i < childNodes.getLength(); i++ ) { |
128 |
for( int i = 0; i < childNodes.getLength(); i++ ) { |
| 135 |
Node childNode = childNodes.item( i ); |
129 |
Node childNode = childNodes.item( i ); |
|
Lines 137-193
Link Here
|
| 137 |
if( ELEM_ELEMENT.equals( childNode.getNodeName() ) ) { |
131 |
if( ELEM_ELEMENT.equals( childNode.getNodeName() ) ) { |
| 138 |
readElement( childNode ); |
132 |
readElement( childNode ); |
| 139 |
} else if( ELEM_PROPERTY.equals( childNode.getNodeName() ) ) { |
133 |
} else if( ELEM_PROPERTY.equals( childNode.getNodeName() ) ) { |
| 140 |
themeElement.addProperty( readProperty( childNode ) ); |
134 |
themeElement.addProperty( getAttributeValue( childNode, ATTR_NAME ) ); |
| 141 |
} else if( ELEM_STYLE.equals( childNode.getNodeName() ) ) { |
135 |
} else if( ELEM_STYLE.equals( childNode.getNodeName() ) ) { |
| 142 |
themeElement.addStyle( readStateOrStyle( childNode ) ); |
136 |
themeElement.addStyle( getAttributeValue( childNode, ATTR_NAME ) ); |
| 143 |
} else if( ELEM_STATE.equals( childNode.getNodeName() ) ) { |
137 |
} else if( ELEM_STATE.equals( childNode.getNodeName() ) ) { |
| 144 |
themeElement.addState( readStateOrStyle( childNode ) ); |
138 |
themeElement.addState( getAttributeValue( childNode, ATTR_NAME ) ); |
| 145 |
} |
139 |
} |
| 146 |
} |
140 |
} |
| 147 |
} |
141 |
} |
| 148 |
} |
142 |
} |
| 149 |
|
143 |
|
| 150 |
private IThemeCssProperty readProperty( final Node node ) { |
|
|
| 151 |
String name = getAttributeValue( node, ATTR_NAME ); |
| 152 |
String type = getAttributeValue( node, ATTR_TYPE ); |
| 153 |
if( type == null ) { |
| 154 |
if( "padding".equals( name ) || "margin".equals( name ) ) { |
| 155 |
type = TYPE_BOXDIMENSIONS; |
| 156 |
} else if( "color".equals( name ) || "background-color".equals( name ) ) { |
| 157 |
type = TYPE_COLOR; |
| 158 |
} else if( "font".equals( name ) ) { |
| 159 |
type = TYPE_FONT; |
| 160 |
} else if( "border".equals( name ) ) { |
| 161 |
type = TYPE_BORDER; |
| 162 |
} else if( "spacing".equals( name ) |
| 163 |
|| "width".equals( name ) |
| 164 |
|| "height".equals( name ) ) |
| 165 |
{ |
| 166 |
type = TYPE_DIMENSION; |
| 167 |
} else if( "background-image".equals( name ) ) { |
| 168 |
type = TYPE_IMAGE; |
| 169 |
} else { |
| 170 |
throw new IllegalArgumentException( "type unknown for property " + name ); |
| 171 |
} |
| 172 |
} |
| 173 |
ThemeCssProperty result = new ThemeCssProperty( name, type ); |
| 174 |
String description = getElementOrAttributeValue( node, ATTR_DESCRIPTION ); |
| 175 |
if( description != null ) { |
| 176 |
result.setDescription( description ); |
| 177 |
} |
| 178 |
return result; |
| 179 |
} |
| 180 |
|
| 181 |
private IThemeCssAttribute readStateOrStyle( final Node node ) { |
| 182 |
String name = getAttributeValue( node, ATTR_NAME ); |
| 183 |
ThemeCssAttribute result = new ThemeCssAttribute( name ); |
| 184 |
String description = getElementOrAttributeValue( node, ATTR_DESCRIPTION ); |
| 185 |
if( description != null ) { |
| 186 |
result.setDescription( description ); |
| 187 |
} |
| 188 |
return result; |
| 189 |
} |
| 190 |
|
| 191 |
private Document parseThemeDefinition( final InputStream is ) |
144 |
private Document parseThemeDefinition( final InputStream is ) |
| 192 |
throws SAXException, IOException |
145 |
throws SAXException, IOException |
| 193 |
{ |
146 |
{ |
|
Lines 227-251
Link Here
|
| 227 |
builder.setErrorHandler( new ThemeDefinitionErrorHandler() ); |
180 |
builder.setErrorHandler( new ThemeDefinitionErrorHandler() ); |
| 228 |
return builder.parse( is ); |
181 |
return builder.parse( is ); |
| 229 |
} |
182 |
} |
| 230 |
|
|
|
| 231 |
private static String getElementOrAttributeValue( final Node node, |
| 232 |
final String name ) |
| 233 |
{ |
| 234 |
String result = null; |
| 235 |
NodeList childNodes = node.getChildNodes(); |
| 236 |
int length = childNodes.getLength(); |
| 237 |
for( int i = 0; i < length && result == null; i++ ) { |
| 238 |
Node child = childNodes.item( i ); |
| 239 |
if( name.equals( child.getNodeName() ) ) { |
| 240 |
Node text = child.getFirstChild(); |
| 241 |
result = text.toString().trim(); |
| 242 |
} |
| 243 |
} |
| 244 |
if( result == null ) { |
| 245 |
result = getAttributeValue( node, name ); |
| 246 |
} |
| 247 |
return result; |
| 248 |
} |
| 249 |
|
183 |
|
| 250 |
private static String getAttributeValue( final Node node, final String name ) |
184 |
private static String getAttributeValue( final Node node, final String name ) |
| 251 |
{ |
185 |
{ |