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.MessageRenderer;
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.context.FacesContext;
050: import javax.faces.context.ResponseWriter;
051: import javax.faces.render.Renderer;
052:
053: /**
054: * A delegating renderer for {@link javax.faces.component.UIMessage}. If the message
055: * component is not yet "for" another component, a summary instruction is rendered.
056: * If it is "for" another component, a summary of the reference is rendered.
057: *
058: * @author gjmurphy
059: */
060: public class MessageDesignTimeRenderer extends
061: AbstractDesignTimeRenderer {
062:
063: static ComponentBundle bundle = ComponentBundle
064: .getBundle(MessageDesignTimeRenderer.class);
065:
066: public MessageDesignTimeRenderer() {
067: super (new MessageRenderer());
068: }
069:
070: protected MessageDesignTimeRenderer(Renderer renderer) {
071: super (renderer);
072: }
073:
074: public void encodeBegin(FacesContext context, UIComponent component)
075: throws IOException {
076: UIMessage messageComponent = (UIMessage) component;
077: String forComponentId = messageComponent.getFor();
078: String summary = null;
079: String detail = null;
080: if (forComponentId == null || forComponentId.length() == 0)
081: summary = bundle.getMessage("Message.default.summary"); //NOI18N
082: else
083: summary = bundle.getMessage("Message.for.summary",
084: new String[] { forComponentId }); //NOI18N
085: if (forComponentId == null || forComponentId.length() == 0)
086: detail = ""; //NOI18N
087: else
088: detail = bundle.getMessage("Message.for.detail",
089: new String[] { forComponentId }); //NOI18N
090:
091: ResponseWriter writer = context.getResponseWriter();
092: String style = (String) component.getAttributes().get("style"); //NOI18N
093: String styleClass = (String) component.getAttributes().get(
094: "styleClass"); //NOI18N
095: String severityStyle = (String) component.getAttributes().get(
096: "errorStyle"); //NOI18N
097: String severityStyleClass = (String) component.getAttributes()
098: .get("errorClass"); //NOI18N
099: String layout = (String) component.getAttributes()
100: .get("layout"); //NOI18N
101:
102: if (severityStyleClass != null)
103: styleClass = severityStyleClass;
104: if (severityStyle != null)
105: style = severityStyle;
106:
107: boolean wroteTable = false;
108: boolean wroteSpan = false;
109:
110: if ((layout != null) && (layout.equals("table"))) { //NOI18N
111: writer.startElement("table", component); //NOI18N
112: writer.writeAttribute("id", component.getClientId(context),
113: "id"); //NOI18N
114: writer.startElement("tr", component); //NOI18N
115: writer.startElement("td", component); //NOI18N
116: wroteTable = true;
117: }
118:
119: if (styleClass != null || style != null) {
120: writer.startElement("span", component); //NOI18N
121: wroteSpan = true;
122: if (!wroteTable) {
123: writer.writeAttribute("id", component
124: .getClientId(context), "id"); //NOI18N
125: }
126: if (styleClass != null) {
127: writer
128: .writeAttribute("class", styleClass,
129: "styleClass"); //NOI18N
130: }
131: if (style != null) {
132: writer.writeAttribute("style", style, "style"); //NOI18N
133: }
134: }
135: if (messageComponent.isShowSummary()) {
136: writer.writeText("\t", null); //NOI18N
137: writer.writeText(summary, null);
138: writer.writeText(" ", null); //NOI18N
139: }
140: if (messageComponent.isShowDetail()) {
141: writer.writeText(detail, null);
142: }
143: if (wroteSpan) {
144: writer.endElement("span"); //NOI18N
145: }
146: if (wroteTable) {
147: writer.endElement("td"); //NOI18N
148: writer.endElement("tr"); //NOI18N
149: writer.endElement("table"); //NOI18N
150: }
151:
152: }
153:
154: public void encodeEnd(FacesContext context, UIComponent component)
155: throws IOException {
156: }
157:
158: }
|