View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.shared.renderkit.html;
20  
21  import java.util.HashMap;
22  import java.util.Map;
23  
24  import javax.faces.component.UIComponent;
25  
26  /**
27   * This is a list of the most common properties used by a JSF html
28   * component, organized by interfaces.
29   * 
30   * This is a copy from javax.faces.component._CommonPropertyConstants
31   * and should be synchronized with this copy on shared
32   */
33  public class CommonPropertyConstants
34  {
35      public static final String COMMON_PROPERTIES_MARKED = "oam.COMMON_PROPERTIES_MARKED";
36      
37      //_StyleProperties
38      public static final long STYLE_PROP       = 0x1L;
39      public static final long STYLECLASS_PROP = 0x2L;
40      
41      //_UniversalProperties
42      //_TitleProperty
43      public static final long DIR_PROP         = 0x4L;
44      public static final long LANG_PROP        = 0x8L;
45      public static final long TITLE_PROP       = 0x10L;
46      
47      //_EscapeProperty
48      public static final long ESCAPE_PROP      = 0x20L;
49  
50      //_DisabledClassEnabledClassProperties
51      //_DisabledReadonlyProperties
52      public static final long DISABLED_PROP    = 0x40L;
53      public static final long ENABLED_PROP     = 0x80L;
54      public static final long READONLY_PROP    = 0x100L;
55  
56      //_AccesskeyProperty
57      public static final long ACCESSKEY_PROP  = 0x200L;
58      
59      //_AltProperty
60      public static final long ALT_PROP         = 0x400L;
61      
62      //_ChangeSelectProperties
63      public static final long ONCHANGE_PROP    = 0x800L;
64      public static final long ONSELECT_PROP    = 0x1000L;
65      
66      //_EventProperties
67      public static final long ONCLICK_PROP     = 0x2000L;
68      public static final long ONDBLCLICK_PROP  = 0x4000L;
69      public static final long ONMOUSEDOWN_PROP = 0x8000L;
70      public static final long ONMOUSEUP_PROP   = 0x10000L;
71      public static final long ONMOUSEOVER_PROP = 0x20000L;
72      public static final long ONMOUSEMOVE_PROP = 0x40000L;
73      public static final long ONMOUSEOUT_PROP  = 0x80000L;
74      public static final long ONKEYPRESS_PROP  = 0x100000L;
75      public static final long ONKEYDOWN_PROP   = 0x200000L;
76      public static final long ONKEYUP_PROP     = 0x400000L;
77      
78      //_FocusBlurProperties
79      public static final long ONFOCUS_PROP     = 0x800000L;
80      public static final long ONBLUR_PROP      = 0x1000000L;
81  
82      //_LabelProperty
83      public static final long LABEL_PROP       = 0x2000000L;
84      
85      //_LinkProperties
86      public static final long CHARSET_PROP     = 0x4000000L;
87      public static final long COORDS_PROP      = 0x8000000L;
88      public static final long HREFLANG_PROP    = 0x10000000L;
89      public static final long REL_PROP         = 0x20000000L;
90      public static final long REV_PROP         = 0x40000000L;
91      public static final long SHAPE_PROP       = 0x80000000L;
92      public static final long TARGET_PROP      = 0x100000000L;
93      public static final long TYPE_PROP        = 0x200000000L;
94  
95      //_TabindexProperty
96      public static final long TABINDEX_PROP    = 0x400000000L;
97      
98      //Common to input fields
99      public static final long ALIGN_PROP       = 0x800000000L;
100     public static final long CHECKED_PROP     = 0x1000000000L;
101     public static final long MAXLENGTH_PROP   = 0x2000000000L;
102     public static final long SIZE_PROP        = 0x4000000000L;
103     
104     public static final long ROLE_PROP        = 0x8000000000L;
105     
106     public static final Map<String, Long> COMMON_PROPERTIES_KEY_BY_NAME = new HashMap<String, Long>(64,1);
107     
108     static
109     {
110         COMMON_PROPERTIES_KEY_BY_NAME.put("style",      STYLE_PROP);
111         
112         COMMON_PROPERTIES_KEY_BY_NAME.put("styleClass", STYLECLASS_PROP);
113         
114         //_UniversalProperties
115         //_TitleProperty
116         COMMON_PROPERTIES_KEY_BY_NAME.put("dir",        DIR_PROP);
117         COMMON_PROPERTIES_KEY_BY_NAME.put("lang",       LANG_PROP);
118         COMMON_PROPERTIES_KEY_BY_NAME.put("title",      TITLE_PROP);
119         
120         //_EscapeProperty
121         COMMON_PROPERTIES_KEY_BY_NAME.put("escape",     ESCAPE_PROP);
122 
123         //_DisabledClassEnabledClassProperties
124         //_DisabledReadonlyProperties
125         COMMON_PROPERTIES_KEY_BY_NAME.put("disabled",   DISABLED_PROP);
126         COMMON_PROPERTIES_KEY_BY_NAME.put("enabled",    ENABLED_PROP);
127         COMMON_PROPERTIES_KEY_BY_NAME.put("readonly",   READONLY_PROP);
128 
129         //_AccesskeyProperty
130         COMMON_PROPERTIES_KEY_BY_NAME.put("accesskey",  ACCESSKEY_PROP);
131         
132         //_AltProperty
133         COMMON_PROPERTIES_KEY_BY_NAME.put("alt",        ALT_PROP);
134         
135         //_ChangeSelectProperties
136         COMMON_PROPERTIES_KEY_BY_NAME.put("onchange",   ONCHANGE_PROP);
137         COMMON_PROPERTIES_KEY_BY_NAME.put("onselect",   ONSELECT_PROP);
138         
139         //_EventProperties
140         COMMON_PROPERTIES_KEY_BY_NAME.put("onclick",    ONCLICK_PROP);
141         COMMON_PROPERTIES_KEY_BY_NAME.put("ondblclick", ONDBLCLICK_PROP);
142         COMMON_PROPERTIES_KEY_BY_NAME.put("onmousedown",ONMOUSEDOWN_PROP);
143         COMMON_PROPERTIES_KEY_BY_NAME.put("onmouseup",  ONMOUSEUP_PROP);
144         COMMON_PROPERTIES_KEY_BY_NAME.put("onmouseover",ONMOUSEOVER_PROP);
145         COMMON_PROPERTIES_KEY_BY_NAME.put("onmousemove",ONMOUSEMOVE_PROP);
146         COMMON_PROPERTIES_KEY_BY_NAME.put("onmouseout", ONMOUSEOUT_PROP);
147         COMMON_PROPERTIES_KEY_BY_NAME.put("onkeypress", ONKEYPRESS_PROP);
148         COMMON_PROPERTIES_KEY_BY_NAME.put("onkeydown",  ONKEYDOWN_PROP);
149         COMMON_PROPERTIES_KEY_BY_NAME.put("onkeyup",    ONKEYUP_PROP);
150         
151         //_FocusBlurProperties
152         COMMON_PROPERTIES_KEY_BY_NAME.put("onfocus",    ONFOCUS_PROP);
153         COMMON_PROPERTIES_KEY_BY_NAME.put("onblur",     ONBLUR_PROP);
154 
155         //_LabelProperty
156         COMMON_PROPERTIES_KEY_BY_NAME.put("label",      LABEL_PROP);
157         
158         //_LinkProperties
159         COMMON_PROPERTIES_KEY_BY_NAME.put("charset",    CHARSET_PROP);
160         COMMON_PROPERTIES_KEY_BY_NAME.put("coords",     COORDS_PROP);
161         COMMON_PROPERTIES_KEY_BY_NAME.put("hreflang",   HREFLANG_PROP);
162         COMMON_PROPERTIES_KEY_BY_NAME.put("rel",        REL_PROP);
163         COMMON_PROPERTIES_KEY_BY_NAME.put("rev",        REV_PROP);
164         COMMON_PROPERTIES_KEY_BY_NAME.put("shape",      SHAPE_PROP);
165         COMMON_PROPERTIES_KEY_BY_NAME.put("target",     TARGET_PROP);
166         COMMON_PROPERTIES_KEY_BY_NAME.put("type",       TYPE_PROP);
167 
168         //_TabindexProperty
169         COMMON_PROPERTIES_KEY_BY_NAME.put("tabindex",   TABINDEX_PROP);
170 
171         //Common to input fields
172         COMMON_PROPERTIES_KEY_BY_NAME.put("align",      ALIGN_PROP);
173         COMMON_PROPERTIES_KEY_BY_NAME.put("checked",    CHECKED_PROP);
174         COMMON_PROPERTIES_KEY_BY_NAME.put("maxlength",  MAXLENGTH_PROP);
175         COMMON_PROPERTIES_KEY_BY_NAME.put("size",       SIZE_PROP);
176         
177         // HTML5 role
178         COMMON_PROPERTIES_KEY_BY_NAME.put("role",   ROLE_PROP);
179     }
180     
181     public static void markProperty(UIComponent component, String name)
182     {
183         Long propertyConstant = COMMON_PROPERTIES_KEY_BY_NAME.get(name);
184         if (propertyConstant == null)
185         {
186             return;
187         }
188         Long commonPropertiesSet = (Long) component.getAttributes().get(COMMON_PROPERTIES_MARKED);
189         if (commonPropertiesSet == null)
190         {
191             commonPropertiesSet = 0L;
192         }
193         component.getAttributes().put(COMMON_PROPERTIES_MARKED, commonPropertiesSet | propertyConstant);
194     }
195     
196     public static void markProperty(UIComponent component, long propertyConstant)
197     {
198         Long commonPropertiesSet = (Long) component.getAttributes().get(COMMON_PROPERTIES_MARKED);
199         if (commonPropertiesSet == null)
200         {
201             commonPropertiesSet = 0L;
202         }
203         component.getAttributes().put(COMMON_PROPERTIES_MARKED, commonPropertiesSet | propertyConstant);
204     }
205 }