|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Single CSS style rule |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.tools.themeinstaller.cssparser; |
|
20 |
|
21 import java.util.HashMap; |
|
22 |
|
23 import org.w3c.css.sac.Selector; |
|
24 |
|
25 /** |
|
26 * CSSRule contains one style rule parsed from CSS StyleSheet |
|
27 */ |
|
28 public class CSSRule implements Comparable |
|
29 { |
|
30 |
|
31 /** The selector. */ |
|
32 private Selector iSelector; |
|
33 |
|
34 /** Style data for Selector */ |
|
35 private HashMap iStyleMap; |
|
36 |
|
37 /** Is Rule pseudo rule */ |
|
38 private boolean iPseudo; |
|
39 |
|
40 /** The specificity of the rule. */ |
|
41 private CSSSpecificity iSpecificity; |
|
42 |
|
43 /** |
|
44 * Instantiates a new CSS rule. |
|
45 * |
|
46 * @param aSelector Selector parsed from CSS file |
|
47 * @param aStyleMap Style data for Selector |
|
48 */ |
|
49 public CSSRule( Selector aSelector, HashMap aStyleMap ) |
|
50 { |
|
51 iSelector = aSelector; |
|
52 iStyleMap = aStyleMap; |
|
53 iSpecificity = new CSSSpecificity(); |
|
54 |
|
55 if ( CSSSelectorParser.isPseudo( iSelector ) ) |
|
56 { |
|
57 iPseudo = true; |
|
58 } |
|
59 else |
|
60 { |
|
61 iPseudo = false; |
|
62 } |
|
63 |
|
64 } |
|
65 |
|
66 /** |
|
67 * Gets the selector. |
|
68 * |
|
69 * @return the selector |
|
70 */ |
|
71 public Selector getSelector() |
|
72 { |
|
73 return iSelector; |
|
74 } |
|
75 |
|
76 /** |
|
77 * Checks if rule has pseudo condition. |
|
78 * |
|
79 * @return true, if is pseudo |
|
80 */ |
|
81 public boolean isPseudo() |
|
82 { |
|
83 return iPseudo; |
|
84 } |
|
85 |
|
86 /** |
|
87 * Gets the specificity. |
|
88 * |
|
89 * @return the specificity |
|
90 */ |
|
91 public CSSSpecificity getSpecificity() |
|
92 { |
|
93 return iSpecificity; |
|
94 } |
|
95 |
|
96 /** |
|
97 * Reset specificity. |
|
98 */ |
|
99 public void resetSpecificity() |
|
100 { |
|
101 iSpecificity.reset(); |
|
102 } |
|
103 |
|
104 /** |
|
105 * Sets the specificity. |
|
106 * |
|
107 * @param aSpecificity the new specificity |
|
108 */ |
|
109 public void setSpecificity( CSSSpecificity aSpecificity ) |
|
110 { |
|
111 iSpecificity = aSpecificity; |
|
112 } |
|
113 |
|
114 /** |
|
115 * Gets the style map. |
|
116 * |
|
117 * @return the style map |
|
118 */ |
|
119 public HashMap getStyleMap() |
|
120 { |
|
121 return iStyleMap; |
|
122 } |
|
123 |
|
124 /* |
|
125 * (non-Javadoc) |
|
126 * |
|
127 * @see java.lang.Comparable#compareTo(java.lang.Object) |
|
128 */ |
|
129 public int compareTo( Object aRule ) |
|
130 { |
|
131 return iSpecificity.compare( ( ( CSSRule ) aRule ).getSpecificity() ); |
|
132 } |
|
133 } |