001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: HtmlMessageRenderer.java,v 1.2 2006/09/29 12:32:09 drmlipp Exp $
021: *
022: * $Log: HtmlMessageRenderer.java,v $
023: * Revision 1.2 2006/09/29 12:32:09 drmlipp
024: * Consistently using WfMOpen as projct name now.
025: *
026: * Revision 1.1 2006/09/04 12:11:54 drmlipp
027: * Fixed double initialization.
028: *
029: */
030: package de.danet.an.util.jsf.taglib;
031:
032: import java.io.IOException;
033:
034: import javax.faces.application.FacesMessage;
035: import javax.faces.component.UIComponent;
036: import javax.faces.component.UIViewRoot;
037: import javax.faces.context.FacesContext;
038: import javax.faces.context.ResponseWriter;
039:
040: import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
041: import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlMessageRendererBase;
042: import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
043:
044: /**
045: * This class provides a fixed message implementation.
046: *
047: * @author Michael Lipp
048: *
049: */
050: public class HtmlMessageRenderer extends
051: org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer {
052:
053: protected void renderSingleFacesMessage(FacesContext facesContext,
054: UIComponent message, FacesMessage facesMessage,
055: String messageClientId) throws IOException {
056: // determine style and style class
057: String[] styleAndClass = HtmlMessageRendererBase
058: .getStyleAndStyleClass(message, facesMessage
059: .getSeverity());
060: String style = styleAndClass[0];
061: String styleClass = styleAndClass[1];
062:
063: String summary = getSummary(facesContext, message,
064: facesMessage, messageClientId);
065: String detail = getDetail(facesContext, message, facesMessage,
066: messageClientId);
067:
068: String title = getTitle(message);
069: boolean tooltip = isTooltip(message);
070:
071: if (title == null && tooltip) {
072: title = summary;
073: }
074:
075: ResponseWriter writer = facesContext.getResponseWriter();
076:
077: boolean span = false;
078:
079: if (message.getId() != null
080: && !message.getId().startsWith(
081: UIViewRoot.UNIQUE_ID_PREFIX)) {
082: span = true;
083:
084: writer.startElement(HTML.SPAN_ELEM, message);
085:
086: HtmlRendererUtils.writeIdIfNecessary(writer, message,
087: facesContext);
088:
089: HtmlRendererUtils
090: .renderHTMLAttributes(
091: writer,
092: message,
093: HTML.MESSAGE_PASSTHROUGH_ATTRIBUTES_WITHOUT_TITLE_STYLE_AND_STYLE_CLASS);
094: } else {
095: span = HtmlRendererUtils
096: .renderHTMLAttributesWithOptionalStartElement(
097: writer,
098: message,
099: HTML.SPAN_ELEM,
100: HTML.MESSAGE_PASSTHROUGH_ATTRIBUTES_WITHOUT_TITLE_STYLE_AND_STYLE_CLASS);
101: }
102:
103: span |= HtmlRendererUtils
104: .renderHTMLAttributeWithOptionalStartElement(writer,
105: message, HTML.SPAN_ELEM, HTML.TITLE_ATTR,
106: title, span);
107: span |= HtmlRendererUtils
108: .renderHTMLAttributeWithOptionalStartElement(writer,
109: message, HTML.SPAN_ELEM, HTML.STYLE_ATTR,
110: style, span);
111: span |= HtmlRendererUtils
112: .renderHTMLAttributeWithOptionalStartElement(writer,
113: message, HTML.SPAN_ELEM, HTML.STYLE_CLASS_ATTR,
114: styleClass, span);
115:
116: boolean showSummary = isShowSummary(message)
117: && (summary != null);
118: boolean showDetail = isShowDetail(message) && (detail != null);
119:
120: if (showSummary && !(getTitle(message) == null && tooltip)) {
121: writer.writeText(summary, null);
122: if (showDetail) {
123: writer.writeText(" ", null);
124: }
125: }
126:
127: if (showDetail) {
128: writer.writeText(detail, null);
129: }
130:
131: if (span) {
132: writer
133: .endElement(org.apache.myfaces.shared_tomahawk.renderkit.html.HTML.SPAN_ELEM);
134: }
135: }
136:
137: }
|