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.Util;
044: import com.sun.rave.web.ui.component.util.event.AfterCreateEvent;
045: import com.sun.rave.web.ui.component.util.event.BeforeCreateEvent;
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 LayoutStaticText. A LayoutStaticText describes a
065: * text to be output to the screen. This element is NOT a
066: * <code>UIComponent</code>.</P>
067: *
068: * @author Ken Paulsen (ken.paulsen@sun.com)
069: */
070: public class LayoutStaticText extends LayoutElementBase implements
071: LayoutElement {
072:
073: /**
074: * <P> Constructor.</P>
075: */
076: public LayoutStaticText(LayoutElement parent, String id,
077: String value) {
078: super (parent, id);
079: _value = value;
080: }
081:
082: /**
083: *
084: */
085: public String getValue() {
086: return _value;
087: }
088:
089: /**
090: * <P> This method displays the text described by this component. If the
091: * text includes an EL expression, it will be evaluated. It returns
092: * false to avoid attempting to render children.</P>
093: *
094: * @param context The <code>FacesContext</code>
095: * @param component The <code>UIComponent</code>
096: *
097: * @return false
098: */
099: protected boolean encodeThis(FacesContext context,
100: UIComponent component) throws IOException {
101: // Get the ResponseWriter
102: ResponseWriter writer = context.getResponseWriter();
103:
104: // Render the child UIComponent
105: // if (staticText.isEscape()) {
106: // writer.writeText(getValue(), "value");
107: // } else {
108: // This code depends on the side-effect of Util.setOption
109: // converting the string to a ValueBinding if needed. The
110: // "__value" is arbitrary.
111: Object value = Util.setOption(context, "__value", getValue(),
112: getLayoutDefinition(), component);
113: if (value instanceof ValueBinding) {
114: value = ((ValueBinding) value).getValue(context);
115: }
116: if (value != null) {
117: writer.write(value.toString());
118: }
119: // }
120:
121: // No children
122: return false;
123: }
124:
125: private String _value = null;
126: }
|