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:
042: package org.netbeans.modules.visualweb.faces.dt.renderer;
043:
044: import com.sun.faces.renderkit.html_basic.MessagesRenderer;
045: import org.netbeans.modules.visualweb.faces.dt.util.ComponentBundle;
046: import java.io.IOException;
047: import javax.faces.component.UIComponent;
048: import javax.faces.component.UIMessage;
049: import javax.faces.component.UIMessages;
050: import javax.faces.context.FacesContext;
051: import javax.faces.context.ResponseWriter;
052:
053: /**
054: * A delegating renderer for {@link javax.faces.component.UIMessages}.
055: *
056: * @author gjmurphy
057: */
058: public class MessagesDesignTimeRenderer extends
059: AbstractDesignTimeRenderer {
060:
061: static ComponentBundle bundle = ComponentBundle
062: .getBundle(MessagesDesignTimeRenderer.class);
063:
064: public MessagesDesignTimeRenderer() {
065: super (new MessagesRenderer());
066: }
067:
068: public void encodeBegin(FacesContext context, UIComponent component)
069: throws IOException {
070: UIMessages messageComponent = (UIMessages) component;
071: String summary = bundle.getMessage("Messages.default.summary"); //NOI18N
072: String detail = bundle.getMessage("Messages.default.detail"); //NOI18N
073:
074: ResponseWriter writer = context.getResponseWriter();
075: String style = (String) component.getAttributes().get("style"); //NOI18N
076: String styleClass = (String) component.getAttributes().get(
077: "styleClass"); //NOI18N
078: String severityStyle = (String) component.getAttributes().get(
079: "errorStyle"); //NOI18N
080: String severityStyleClass = (String) component.getAttributes()
081: .get("errorClass"); //NOI18N
082: String layout = (String) component.getAttributes()
083: .get("layout"); //NOI18N
084:
085: if (severityStyleClass != null)
086: styleClass = severityStyleClass;
087: if (severityStyle != null)
088: style = severityStyle;
089:
090: boolean wroteTable = false;
091: boolean wroteSpan = false;
092:
093: if ((layout != null) && (layout.equals("table"))) { //NOI18N
094: writer.startElement("table", component); //NOI18N
095: writer.writeAttribute("id", component.getClientId(context),
096: "id"); //NOI18N
097: writer.startElement("tr", component); //NOI18N
098: writer.startElement("td", component); //NOI18N
099: wroteTable = true;
100: }
101:
102: if (styleClass != null || style != null) {
103: writer.startElement("span", component); //NOI18N
104: wroteSpan = true;
105: if (!wroteTable) {
106: writer.writeAttribute("id", component
107: .getClientId(context), "id"); //NOI18N
108: }
109: if (styleClass != null) {
110: writer
111: .writeAttribute("class", styleClass,
112: "styleClass"); //NOI18N
113: }
114: if (style != null) {
115: writer.writeAttribute("style", style, "style"); //NOI18N
116: }
117: }
118: if (messageComponent.isShowSummary()) {
119: writer.writeText("\t", null); //NOI18N
120: writer.writeText(summary, null);
121: writer.writeText(" ", null); //NOI18N
122: }
123: if (messageComponent.isShowDetail()) {
124: writer.writeText(detail, null);
125: }
126: if (wroteSpan) {
127: writer.endElement("span"); //NOI18N
128: }
129: if (wroteTable) {
130: writer.endElement("td"); //NOI18N
131: writer.endElement("tr"); //NOI18N
132: writer.endElement("table"); //NOI18N
133: }
134:
135: }
136:
137: public void encodeEnd(FacesContext context, UIComponent component)
138: throws IOException {
139: }
140:
141: }
|