001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or
005: * without modification, are permitted provided that the following
006: * conditions are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above
012: * copyright notice, this list of conditions and the following
013: * disclaimer in the documentation and/or other materials
014: * provided with the distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
025: * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
026: * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
027: * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
028: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
029: * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
030: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
031: * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
032: * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
033: *
034: * You acknowledge that this software is not designed, licensed or
035: * intended for use in the design, construction, operation or
036: * maintenance of any nuclear facility.
037: */
038:
039: package org.apache.cocoon.faces.samples.components.taglib;
040:
041: import org.apache.cocoon.faces.FacesUtils;
042: import org.apache.cocoon.faces.taglib.UIComponentTag;
043: import org.apache.cocoon.faces.samples.components.components.MapComponent;
044: import org.apache.cocoon.faces.samples.components.renderkit.Util;
045: import org.apache.commons.lang.BooleanUtils;
046:
047: import javax.faces.component.UIComponent;
048: import javax.faces.context.FacesContext;
049: import javax.faces.el.MethodBinding;
050: import javax.faces.el.ValueBinding;
051: import javax.faces.event.ActionEvent;
052:
053: /**
054: * <p>{@link UIComponentTag} for an image map.</p>
055: */
056:
057: public class MapTag extends UIComponentTag {
058:
059: private String current;
060:
061: public void setCurrent(String current) {
062: this .current = current;
063: }
064:
065: private String actionListener;
066:
067: public void setActionListener(String actionListener) {
068: this .actionListener = actionListener;
069: }
070:
071: private String action;
072:
073: public void setAction(String action) {
074: this .action = action;
075: }
076:
077: private String immediate;
078:
079: public void setImmediate(String immediate) {
080: this .immediate = immediate;
081: }
082:
083: private String styleClass;
084:
085: public void setStyleClass(String styleClass) {
086: this .styleClass = styleClass;
087: }
088:
089: public String getComponentType() {
090: return ("DemoMap");
091: }
092:
093: public String getRendererType() {
094: return ("DemoMap");
095: }
096:
097: public void recycle() {
098: super .recycle();
099: current = null;
100: styleClass = null;
101: actionListener = null;
102: action = null;
103: immediate = null;
104: styleClass = null;
105: }
106:
107: protected void setProperties(UIComponent component) {
108: super .setProperties(component);
109: MapComponent map = (MapComponent) component;
110: // if (current != null) {
111: // map.setCurrent(current);
112: // }
113: if (styleClass != null) {
114: if (FacesUtils.isExpression(styleClass)) {
115: ValueBinding vb = FacesContext.getCurrentInstance()
116: .getApplication()
117: .createValueBinding(styleClass);
118: map.setValueBinding("styleClass", vb);
119: } else {
120: map.getAttributes().put("styleClass", styleClass);
121: }
122: }
123: if (actionListener != null) {
124: if (FacesUtils.isExpression(actionListener)) {
125: Class args[] = { ActionEvent.class };
126: MethodBinding mb = FacesContext.getCurrentInstance()
127: .getApplication().createMethodBinding(
128: actionListener, args);
129: map.setActionListener(mb);
130: } else {
131: Object params[] = { actionListener };
132: throw new javax.faces.FacesException();
133: }
134: }
135:
136: if (action != null) {
137: if (FacesUtils.isExpression(action)) {
138: MethodBinding vb = FacesContext.getCurrentInstance()
139: .getApplication().createMethodBinding(action,
140: null);
141: map.setAction(vb);
142: } else {
143: map.setAction(Util.createConstantMethodBinding(action));
144: }
145: }
146: if (immediate != null) {
147: if (FacesUtils.isExpression(immediate)) {
148: ValueBinding vb = FacesContext.getCurrentInstance()
149: .getApplication().createValueBinding(immediate);
150: map.setValueBinding("immediate", vb);
151: } else {
152: map.setImmediate(BooleanUtils.toBoolean(immediate));
153: }
154: }
155:
156: }
157:
158: }
|