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: package org.apache.cocoon.forms.formmodel;
18:
19: import java.util.Iterator;
20:
21: import org.apache.cocoon.forms.FormsConstants;
22: import org.apache.cocoon.forms.event.ActionListener;
23: import org.apache.cocoon.forms.util.DomHelper;
24: import org.w3c.dom.Element;
25:
26: /**
27: * Builds {@link ImageMapDefinition}s.
28: *
29: * @version $Id: ImageMapDefinitionBuilder.java 462520 2006-10-10 19:39:14Z vgritsenko $
30: * @since 2.1.8
31: */
32: public class ImageMapDefinitionBuilder extends
33: AbstractWidgetDefinitionBuilder {
34:
35: public WidgetDefinition buildWidgetDefinition(Element widgetElement)
36: throws Exception {
37: ImageMapDefinition definition = new ImageMapDefinition();
38: setupDefinition(widgetElement, definition);
39: definition.makeImmutable();
40: return definition;
41: }
42:
43: protected void setupDefinition(Element widgetElement,
44: ImageMapDefinition definition) throws Exception {
45: super .setupDefinition(widgetElement, definition);
46:
47: setDisplayData(widgetElement, definition);
48:
49: // Get the "command" optional attribute
50: String actionCommand = DomHelper.getAttribute(widgetElement,
51: ImageMap.COMMAND_AT, null);
52: definition.setActionCommand(actionCommand);
53:
54: Iterator iter = buildEventListeners(widgetElement,
55: ImageMap.ONACTION_EL, ActionListener.class).iterator();
56: while (iter.hasNext()) {
57: definition.addActionListener((ActionListener) iter.next());
58: }
59:
60: // Sets image map source
61: Element imageURIEl = DomHelper.getChildElement(widgetElement,
62: FormsConstants.DEFINITION_NS, ImageMap.VALUE_EL);
63: if (imageURIEl != null) {
64: definition
65: .setImageURI(DomHelper.getElementText(imageURIEl));
66: }
67: }
68: }
|