001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.rave.web.ui.component.util.descriptors;
042:
043: import com.sun.rave.web.ui.component.util.event.Handler;
044: import com.sun.rave.web.ui.component.util.event.HandlerContext;
045: import com.sun.rave.web.ui.component.util.event.HandlerDefinition;
046:
047: import java.io.IOException;
048: import java.util.ArrayList;
049: import java.util.HashMap;
050: import java.util.Iterator;
051: import java.util.List;
052: import java.util.Map;
053:
054: import javax.faces.context.FacesContext;
055: import javax.faces.context.ResponseWriter;
056: import javax.faces.component.UIColumn;
057: import javax.faces.component.UIComponent;
058: import javax.faces.component.UIData;
059: import javax.faces.component.UIViewRoot;
060: import javax.faces.el.ValueBinding;
061: import javax.faces.render.Renderer;
062:
063: /**
064: * <p> This class defines a LayoutAttribute. A LayoutAttribute provides a
065: * means to write an attribute for the current markup tag. A markup tag
066: * must be started, but not yet closed for this to work.</p>
067: *
068: * @author Ken Paulsen (ken.paulsen@sun.com)
069: */
070: public class LayoutAttribute extends LayoutElementBase implements
071: LayoutElement {
072:
073: /**
074: * <p> Constructor.</p>
075: */
076: public LayoutAttribute(LayoutElement parent, String name,
077: String value, String property) {
078: super (parent, name);
079: _name = name;
080: _value = value;
081: _property = property;
082: }
083:
084: /**
085: *
086: */
087: public String getName() {
088: return _name;
089: }
090:
091: /**
092: *
093: */
094: public String getValue() {
095: return _value;
096: }
097:
098: /**
099: *
100: */
101: public String getProperty() {
102: return _property;
103: }
104:
105: /**
106: * <p> This method displays the text described by this component. If the
107: * text includes an EL expression, it will be evaluated. It returns
108: * false to avoid attempting to render children.</p>
109: *
110: * @param context The <code>FacesContext</code>
111: * @param component The <code>UIComponent</code>
112: *
113: * @return false
114: */
115: protected boolean encodeThis(FacesContext context,
116: UIComponent component) throws IOException {
117: // Get the ResponseWriter
118: ResponseWriter writer = context.getResponseWriter();
119:
120: // Render...
121: Object value = resolveValue(context, component, getValue());
122: if ((value != null) && !value.toString().trim().equals("")) {
123: String name = getName();
124: String prop = getProperty();
125: if (prop == null) {
126: // Use the name if property is not supplied
127: prop = name;
128: } else if (prop.equals("null")) {
129: prop = null;
130: }
131: writer.writeAttribute(name, value, prop);
132: }
133:
134: // No children
135: return false;
136: }
137:
138: private String _name = null;
139: private String _value = null;
140: private String _property = null;
141: }
|