1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.render.html; |
17 | |
|
18 | |
import java.io.IOException; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import javax.faces.application.FacesMessage; |
22 | |
import javax.faces.application.FacesMessage.Severity; |
23 | |
import javax.faces.component.UIComponent; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.context.ResponseWriter; |
26 | |
import javax.faces.internal.UIComponentUtil; |
27 | |
|
28 | |
import org.seasar.teeda.core.JsfConstants; |
29 | |
import org.seasar.teeda.core.render.AbstractRenderer; |
30 | |
import org.seasar.teeda.core.util.RendererUtil; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 106 | public abstract class AbstractHtmlMessagesRenderer extends AbstractRenderer { |
36 | |
|
37 | |
protected void renderOneMessage(FacesContext context, |
38 | |
UIComponent component, FacesMessage facesMassage, |
39 | |
final String idForRender, Map attributes) throws IOException { |
40 | |
|
41 | 53 | final String style = getStyle(component, facesMassage.getSeverity()); |
42 | 53 | final String styleClass = getStyleClass(component, facesMassage |
43 | |
.getSeverity()); |
44 | 53 | String title = getTitle(component); |
45 | |
|
46 | 53 | String summary = facesMassage.getSummary(); |
47 | 53 | String detail = facesMassage.getDetail(); |
48 | 53 | boolean isWriteSummary = isShowSummary(component) && summary != null; |
49 | 53 | boolean isWriteDetail = isShowDetail(component) && detail != null; |
50 | 53 | if (isTooltip(component) && isWriteSummary && isWriteDetail) { |
51 | 4 | isWriteSummary = false; |
52 | 4 | title = summary; |
53 | |
} |
54 | |
|
55 | 53 | ResponseWriter writer = context.getResponseWriter(); |
56 | 53 | boolean startSpan = false; |
57 | 53 | if (idForRender != null || style != null || styleClass != null |
58 | |
|| title != null || containsAttributeForRender(attributes)) { |
59 | 28 | startSpan = true; |
60 | 28 | writer.startElement(JsfConstants.SPAN_ELEM, component); |
61 | 28 | RendererUtil.renderAttribute(writer, JsfConstants.ID_ATTR, |
62 | |
idForRender); |
63 | 28 | RendererUtil |
64 | |
.renderAttribute(writer, JsfConstants.TITLE_ATTR, title); |
65 | 28 | RendererUtil |
66 | |
.renderAttribute(writer, JsfConstants.STYLE_ATTR, style); |
67 | 28 | RendererUtil.renderAttribute(writer, JsfConstants.STYLE_CLASS_ATTR, |
68 | |
styleClass); |
69 | 28 | renderAttributes(attributes, writer); |
70 | |
} |
71 | |
|
72 | |
|
73 | 53 | if (isWriteSummary) { |
74 | 29 | writer.write(summary); |
75 | |
} |
76 | 53 | if (isWriteDetail) { |
77 | 25 | if (isWriteSummary) { |
78 | 3 | writer.write(" "); |
79 | |
} |
80 | 25 | writer.write(detail); |
81 | |
} |
82 | |
|
83 | 53 | if (startSpan) { |
84 | 28 | writer.endElement(JsfConstants.SPAN_ELEM); |
85 | |
} |
86 | 53 | } |
87 | |
|
88 | |
protected boolean isTooltip(UIComponent component) { |
89 | 53 | return UIComponentUtil.getPrimitiveBooleanAttribute(component, |
90 | |
JsfConstants.TOOLTIP_ATTR); |
91 | |
} |
92 | |
|
93 | |
protected boolean isShowDetail(UIComponent component) { |
94 | 53 | return UIComponentUtil.getPrimitiveBooleanAttribute(component, |
95 | |
JsfConstants.SHOW_DETAIL_ATTR); |
96 | |
} |
97 | |
|
98 | |
protected boolean isShowSummary(UIComponent component) { |
99 | 53 | return UIComponentUtil.getPrimitiveBooleanAttribute(component, |
100 | |
JsfConstants.SHOW_SUMMARY_ATTR); |
101 | |
} |
102 | |
|
103 | |
protected String getTitle(UIComponent component) { |
104 | 53 | return UIComponentUtil.getStringAttribute(component, |
105 | |
JsfConstants.TITLE_ATTR); |
106 | |
} |
107 | |
|
108 | |
protected String getStyleClass(UIComponent component, Severity severity) { |
109 | 53 | String styleClass = null; |
110 | 53 | if (severity == FacesMessage.SEVERITY_INFO) { |
111 | 42 | styleClass = UIComponentUtil.getStringAttribute(component, |
112 | |
JsfConstants.INFO_CLASS_ATTR); |
113 | 11 | } else if (severity == FacesMessage.SEVERITY_WARN) { |
114 | 4 | styleClass = UIComponentUtil.getStringAttribute(component, |
115 | |
JsfConstants.WARN_CLASS_ATTR); |
116 | 7 | } else if (severity == FacesMessage.SEVERITY_ERROR) { |
117 | 4 | styleClass = UIComponentUtil.getStringAttribute(component, |
118 | |
JsfConstants.ERROR_CLASS_ATTR); |
119 | 3 | } else if (severity == FacesMessage.SEVERITY_FATAL) { |
120 | 3 | styleClass = UIComponentUtil.getStringAttribute(component, |
121 | |
JsfConstants.FATAL_CLASS_ATTR); |
122 | |
} |
123 | 53 | if (styleClass == null) { |
124 | 40 | styleClass = UIComponentUtil.getStringAttribute(component, |
125 | |
JsfConstants.STYLE_CLASS_ATTR); |
126 | |
} |
127 | 53 | return styleClass; |
128 | |
} |
129 | |
|
130 | |
protected String getStyle(UIComponent component, Severity severity) { |
131 | 53 | String style = null; |
132 | 53 | if (severity == FacesMessage.SEVERITY_INFO) { |
133 | 42 | style = UIComponentUtil.getStringAttribute(component, |
134 | |
JsfConstants.INFO_STYLE_ATTR); |
135 | 11 | } else if (severity == FacesMessage.SEVERITY_WARN) { |
136 | 4 | style = UIComponentUtil.getStringAttribute(component, |
137 | |
JsfConstants.WARN_STYLE_ATTR); |
138 | 7 | } else if (severity == FacesMessage.SEVERITY_ERROR) { |
139 | 4 | style = UIComponentUtil.getStringAttribute(component, |
140 | |
JsfConstants.ERROR_STYLE_ATTR); |
141 | 3 | } else if (severity == FacesMessage.SEVERITY_FATAL) { |
142 | 3 | style = UIComponentUtil.getStringAttribute(component, |
143 | |
JsfConstants.FATAL_STYLE_ATTR); |
144 | |
} |
145 | 53 | if (style == null) { |
146 | 40 | style = UIComponentUtil.getStringAttribute(component, |
147 | |
JsfConstants.STYLE_ATTR); |
148 | |
} |
149 | 53 | return style; |
150 | |
} |
151 | |
|
152 | |
} |