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 org.netbeans.modules.visualweb.web.ui.dt.renderer;
042:
043: import java.io.IOException;
044: import javax.faces.component.UIComponent;
045: import javax.faces.context.FacesContext;
046: import javax.faces.convert.ConverterException;
047: import javax.faces.el.EvaluationException;
048: import javax.faces.el.ValueBinding;
049: import javax.faces.render.Renderer;
050:
051: /**
052: * Stuff. No fluff.
053: *
054: * @author gjmurphy
055: */
056: public class AbstractDesignTimeRenderer extends Renderer {
057:
058: protected static String UNINITITIALIZED_STYLE_CLASS = "rave-uninitialized-text";
059: protected static String BORDER_STYLE_CLASS = "rave-design-border";
060:
061: // Delagatee renderer
062: protected Renderer renderer;
063:
064: public AbstractDesignTimeRenderer(Renderer renderer) {
065: this .renderer = renderer;
066: }
067:
068: public Object getConvertedValue(FacesContext context,
069: UIComponent component, Object submittedValue)
070: throws ConverterException {
071: return this .renderer.getConvertedValue(context, component,
072: submittedValue);
073: }
074:
075: public void encodeEnd(FacesContext context, UIComponent component)
076: throws IOException {
077: this .renderer.encodeEnd(context, component);
078: }
079:
080: public void encodeChildren(FacesContext context,
081: UIComponent component) throws IOException {
082: this .renderer.encodeChildren(context, component);
083: }
084:
085: public void encodeBegin(FacesContext context, UIComponent component)
086: throws IOException {
087: this .renderer.encodeBegin(context, component);
088: }
089:
090: public void decode(FacesContext context, UIComponent component) {
091: this .renderer.decode(context, component);
092: }
093:
094: public String convertClientId(FacesContext context, String clientId) {
095: return this .renderer.convertClientId(context, clientId);
096: }
097:
098: public boolean getRendersChildren() {
099: return this .renderer.getRendersChildren();
100: }
101:
102: protected static String addStyleClass(String value,
103: String styleClass) {
104: if (value == null) {
105: return styleClass;
106: } else if (value.indexOf(styleClass) >= 0) {
107: return value;
108: } else {
109: return value + " " + styleClass;
110: }
111: }
112:
113: protected static String removeStyleClass(String value,
114: String styleClass) {
115: if (value == null || value.indexOf(styleClass) == -1)
116: return value;
117: int i = value.indexOf(styleClass);
118: while (i > 0 && Character.isSpaceChar(value.charAt(i)))
119: i--;
120: return value.substring(0, i)
121: + value.substring(i + styleClass.length());
122: }
123:
124: protected static Object getDummyData(FacesContext context,
125: ValueBinding vb) {
126: Class type = null;
127: try {
128: type = vb.getType(context);
129: } catch (EvaluationException e) {
130: // FIXME - workaround for [6371691] that should be reconsidered,
131: // as swallowing exceptions is not a good general practice
132: type = Object.class;
133: }
134: return getDummyData(type);
135: }
136:
137: protected static Object getDummyData(Class clazz) {
138: if (clazz.equals(Object.class))
139: return null;
140: return com.sun.data.provider.impl.AbstractDataProvider
141: .getFakeData(clazz);
142: }
143:
144: }
|