01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: * $Header:$
18: */
19: package org.apache.beehive.netui.tags.rendering;
20:
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: /**
25: * This class extends the <code>AbstractAttributeState</code> to add support for HTML.
26: * This class add support for the <code>id</code>, <code>style</code>, and <code>class</code>
27: * attributes. In addition, there is a <code>Map</code> that supports the JavaScript
28: * event attributes.
29: */
30: public class AbstractHtmlState extends AbstractAttributeState {
31: /**
32: * Define the Attribute Map for the JavaScript event handler attributes.
33: */
34: public static final int ATTR_JAVASCRIPT = 12;
35:
36: /**
37: * The HTML <code>id</code> attribute.
38: */
39: public String id;
40:
41: /**
42: * The HTML <code>style</code> attribute.
43: */
44: public String style;
45:
46: /**
47: * The HTML <code>class</code> attribute.
48: */
49: public String styleClass;
50:
51: private HashMap _jsMap = null; // Map used to hold the registered JavaScript attributes.
52:
53: /**
54: * Return the Map Containing the JavaScript entries.
55: * @return a <code>Map</code> of the JavaScript attributes.
56: */
57: public HashMap getEventMap() {
58: return _jsMap;
59: }
60:
61: /**
62: * Initialize the state.
63: */
64: public void clear() {
65: super .clear();
66:
67: if (_jsMap != null)
68: _jsMap.clear();
69:
70: id = null;
71: style = null;
72: styleClass = null;
73: }
74:
75: /**
76: * This method will return the map that represents the passed in <code>type</code>. The boolean flag
77: * </code>createIfNull</code> indicates that the map should be created or not if it's null. This
78: * class defines two maps defined by <code>@see #ATTR_STYLE</code> and <code>ATTR_JAVASCRIPT</code>
79: * @param type <code>integer</code> type indentifying the map to be created.
80: * @param createIfNull <code>boolean</code> flag indicating if the map should be created if it doesn't exist.
81: * @return The map or null
82: * @see #ATTR_JAVASCRIPT
83: */
84: public Map selectMap(int type, boolean createIfNull) {
85: if (type == ATTR_JAVASCRIPT) {
86: if (_jsMap == null && createIfNull)
87: _jsMap = new HashMap();
88: return _jsMap;
89: }
90: return super.selectMap(type, createIfNull);
91: }
92: }
|