KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > wap > renderkit > wml > MessageRenderer


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.myfaces.wap.renderkit.wml;
17
18 import java.util.Iterator JavaDoc;
19
20 import javax.faces.application.FacesMessage;
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.context.ResponseWriter;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.myfaces.wap.component.Message;
28 import org.apache.myfaces.wap.renderkit.WmlRenderer;
29
30 /**
31  * @author <a HREF="mailto:Jiri.Zaloudek@ivancice.cz">Jiri Zaloudek</a> (latest modification by $Author: matzew $)
32  * @version $Revision: 1.1 $ $Date: 2004/12/30 09:37:26 $
33  * $Log: MessageRenderer.java,v $
34  * Revision 1.1 2004/12/30 09:37:26 matzew
35  * added a new RenderKit for WML. Thanks to Jirí Žaloudek
36  *
37  */

38 public class MessageRenderer extends WmlRenderer {
39     private static Log log = LogFactory.getLog(MessageRenderer.class);
40     
41     /** Creates a new instance of TextRenderer */
42     public MessageRenderer() {
43         super();
44         log.debug("created object " + this.getClass().getName());
45     }
46     
47     public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
48         log.debug("encodeBegin(" + component.getId() + ")");
49         if (context == null || component == null) {
50             throw new NullPointerException JavaDoc();
51         }
52     }
53     
54     public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
55         log.debug("encodeChildren(" + component.getId() + ")");
56         if (context == null || component == null) {
57             throw new NullPointerException JavaDoc();
58         }
59     }
60     
61     public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
62         log.debug("encodeEnd(" + component.getId() + ")");
63         if (context == null || component == null) {
64             throw new NullPointerException JavaDoc();
65         }
66         if (!component.isRendered()) return;
67         
68         Message comp = (Message)component;
69         ResponseWriter writer = context.getResponseWriter();
70         
71         String JavaDoc _for = comp.getFor();
72         if (_for == null) log.error("Attribute 'for' of UIMessage must not be null.");
73         
74         UIComponent forComponent = component.findComponent(_for);
75         if (forComponent == null) log.error("Unable to find component '" + _for + "'. Can not render UIMessage component.");
76         
77         Iterator JavaDoc iter = context.getMessages(forComponent.getClientId(context));
78         if (iter.hasNext()) {
79             FacesMessage message = (FacesMessage)iter.next();
80             if (comp.isShowSummary())
81                 writer.write(message.getSummary());
82             if (comp.isShowDetail())
83                 writer.write(message.getDetail());
84         }
85     }
86     
87     public void decode(FacesContext context, UIComponent component) {
88         if (component == null ) throw new NullPointerException JavaDoc();
89     }
90 }
91
92
Popular Tags