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: Pseudo class resolver for CSS Style properties |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.tools.themeinstaller.cssparser; |
|
20 |
|
21 import java.util.Collection; |
|
22 import java.util.Enumeration; |
|
23 import java.util.Hashtable; |
|
24 |
|
25 /** |
|
26 * Resolves pseudo class values by keys. |
|
27 */ |
|
28 public class PseudoClassResolver |
|
29 { |
|
30 |
|
31 // Pseudo class keys |
|
32 public static final int UNKNOWN = -1; |
|
33 public static final int NONE = 0; |
|
34 public static final int FOCUS = 1; |
|
35 public static final int PASSIVE_FOCUS = 2; |
|
36 public static final int ACTIVE = 3; |
|
37 public static final int HOLD = 4; |
|
38 public static final int ENABLED = 5; |
|
39 public static final int DISABLED = 6; |
|
40 public static final int HOVER = 7; |
|
41 public static final int LINK = 8; |
|
42 public static final int VISITED = 9; |
|
43 public static final int EDIT = 10; |
|
44 |
|
45 // Pseudo class values |
|
46 private static final String NONE_VALUE = "none"; |
|
47 private static final String FOCUS_VALUE = "focus"; |
|
48 private static final String PASSIVE_FOCUS_VALUE = "passivefocus"; |
|
49 private static final String ACTIVE_VALUE = "active"; |
|
50 private static final String HOLD_VALUE = "hold"; |
|
51 private static final String ENABLED_VALUE = "enabled"; |
|
52 private static final String DISABLED_VALUE = "disabled"; |
|
53 private static final String HOVER_VALUE = "hover"; |
|
54 private static final String LINK_VALUE = "link"; |
|
55 private static final String VISITED_VALUE = "visited"; |
|
56 private static final String EDIT_VALUE = "edit"; |
|
57 |
|
58 private Hashtable iPseudoClassTable; |
|
59 |
|
60 /** |
|
61 * Constructor. |
|
62 */ |
|
63 public PseudoClassResolver() |
|
64 { |
|
65 iPseudoClassTable = new Hashtable(); |
|
66 iPseudoClassTable.put( new Integer( NONE ), NONE_VALUE ); |
|
67 iPseudoClassTable.put( new Integer( FOCUS ), FOCUS_VALUE ); |
|
68 iPseudoClassTable.put( new Integer( PASSIVE_FOCUS ), PASSIVE_FOCUS_VALUE ); |
|
69 iPseudoClassTable.put( new Integer( ACTIVE ), ACTIVE_VALUE ); |
|
70 iPseudoClassTable.put( new Integer( HOLD ), HOLD_VALUE ); |
|
71 iPseudoClassTable.put( new Integer( ENABLED ), ENABLED_VALUE ); |
|
72 iPseudoClassTable.put( new Integer( DISABLED ), DISABLED_VALUE ); |
|
73 iPseudoClassTable.put( new Integer( HOVER ), HOVER_VALUE ); |
|
74 iPseudoClassTable.put( new Integer( LINK ), LINK_VALUE ); |
|
75 iPseudoClassTable.put( new Integer( VISITED ), VISITED_VALUE ); |
|
76 iPseudoClassTable.put( new Integer( EDIT ), EDIT_VALUE ); |
|
77 } |
|
78 |
|
79 /** |
|
80 * Get pseudo class value by its key. |
|
81 * @param aClassKey Pseudo class key, for example, FOCUS |
|
82 * @return Pseudo class value, for example, "focus". Returns null if |
|
83 * the value can not be resolved. |
|
84 */ |
|
85 public String getValue( Integer aClassKey ) |
|
86 { |
|
87 return ( String ) iPseudoClassTable.get( aClassKey ); |
|
88 } |
|
89 |
|
90 /** |
|
91 * Get pseudo class key by its value. |
|
92 * @param aClassValue Pseudo class value, for example, "focus" |
|
93 * @return Pseudo class key, for example, FOCUS. Returns UNKNOWN if the |
|
94 * value can not be resolved. |
|
95 */ |
|
96 public int getKey( String aClassValue ) |
|
97 { |
|
98 int result = UNKNOWN; |
|
99 |
|
100 Enumeration keys = iPseudoClassTable.keys(); |
|
101 while ( keys.hasMoreElements() ) |
|
102 { |
|
103 int key = ( ( Integer ) keys.nextElement() ).intValue(); |
|
104 if ( aClassValue.equals( getValue( new Integer( key ) ) ) ) |
|
105 { |
|
106 result = key; |
|
107 break; |
|
108 } |
|
109 } |
|
110 |
|
111 return result; |
|
112 } |
|
113 |
|
114 /** |
|
115 * Gets the table of pseudo class values. |
|
116 * |
|
117 * @return The table |
|
118 */ |
|
119 public Collection getPseudoTypes() |
|
120 { |
|
121 return iPseudoClassTable.values(); |
|
122 } |
|
123 |
|
124 } |
|