KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.component.UIParameter;
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.OutputLink;
28 import org.apache.myfaces.wap.renderkit.Attributes;
29 import org.apache.myfaces.wap.renderkit.RendererUtils;
30 import org.apache.myfaces.wap.renderkit.WmlRenderer;
31
32
33 /**
34  * @author <a HREF="mailto:Jiri.Zaloudek@ivancice.cz">Jiri Zaloudek</a> (latest modification by $Author: matzew $)
35  * @version $Revision: 1.1 $ $Date: 2004/12/30 09:37:26 $
36  * $Log: OutputLinkRenderer.java,v $
37  * Revision 1.1 2004/12/30 09:37:26 matzew
38  * added a new RenderKit for WML. Thanks to Jirí Žaloudek
39  *
40  */

41 public class OutputLinkRenderer extends WmlRenderer {
42     private static Log log = LogFactory.getLog(OutputLinkRenderer.class);
43     
44     /** Creates a new instance of TextRenderer */
45     public OutputLinkRenderer() {
46         super();
47         log.debug("created object " + this.getClass().getName());
48     }
49     
50     public boolean getRendersChildren(){
51         return(true);
52     }
53     
54     public void encodeBegin(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
55         log.debug("encodeBegin(" + component.getId() + ")");
56         
57         if (context == null || component == null) {
58             throw new NullPointerException JavaDoc();
59         }
60         if (!component.isRendered()) return;
61         
62         ResponseWriter writer = context.getResponseWriter();
63         OutputLink comp = (OutputLink)component;
64         
65         String JavaDoc href = RendererUtils.convertToString(context, component);
66         
67         List JavaDoc child = component.getChildren();
68         for (int i = 0; i < child.size(); i++){ // insert parameters from UIParameter components
69
if (child.get(i) instanceof UIParameter){
70                 href = insertParam(href, (UIParameter)child.get(i), writer.getCharacterEncoding());
71             }
72         }
73         href = context.getExternalContext().encodeResourceURL(href);
74         
75         writer.startElement(Attributes.A, component);
76         RendererUtils.writeAttribute(Attributes.HREF, href, writer);
77         RendererUtils.writeAttribute(Attributes.ID, comp.getClientId(context), writer);
78         RendererUtils.writeAttribute(Attributes.CLASS, comp.getStyleClass(), writer);
79         RendererUtils.writeAttribute(Attributes.XML_LANG, comp.getXmllang(), writer);
80         RendererUtils.writeAttribute(Attributes.TITLE, comp.getTitle(), writer);
81         writer.flush();
82     }
83     
84     public void encodeChildren(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
85         log.debug("encodeChildren(" + component.getId() + ")");
86         if (context == null || component == null) {
87             throw new NullPointerException JavaDoc();
88         }
89         if (!component.isRendered()) return;
90         
91         RendererUtils.renderChildren(context, component);
92     }
93     
94     public void encodeEnd(FacesContext context, UIComponent component) throws java.io.IOException JavaDoc {
95         log.debug("encodeEnd(" + component.getId() + ")");
96         if (context == null || component == null) {
97             throw new NullPointerException JavaDoc();
98         }
99         if (!component.isRendered()) return;
100         
101         ResponseWriter writer = context.getResponseWriter();
102         writer.endElement(Attributes.A);
103     }
104     
105     public void decode(FacesContext context, UIComponent component) {
106         if (component == null ) throw new NullPointerException JavaDoc();
107     }
108     
109     private String JavaDoc insertParam(String JavaDoc href, UIParameter param, String JavaDoc encoding) throws java.io.IOException JavaDoc {
110         String JavaDoc name = (String JavaDoc)param.getName();
111         String JavaDoc value = (String JavaDoc)param.getValue();
112         
113         return(RendererUtils.insertGetParam(href, name, value, encoding));
114     }
115     
116     /** Overrides method getConvertedValue */
117     public Object JavaDoc getConvertedValue(FacesContext context, UIComponent component, Object JavaDoc submittedValue) throws javax.faces.convert.ConverterException {
118         return(RendererUtils.convertToObject(context, component));
119     }
120 }
121
122
Popular Tags