KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > renderer > html > HtmlBasicRenderer


1 /**************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  *************************************************************************/

5 package org.exoplatform.faces.core.renderer.html;
6
7 import java.io.IOException JavaDoc;
8 import java.util.List JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10 import javax.faces.component.UIComponent;
11 import javax.faces.context.ExternalContext;
12 import javax.faces.context.FacesContext;
13 import javax.faces.context.ResponseWriter;
14 import javax.faces.render.Renderer;
15 import org.exoplatform.commons.utils.Formater;
16 import org.exoplatform.container.SessionContainer;
17 import org.exoplatform.faces.context.PortletExternalContext;
18 import org.exoplatform.faces.core.component.UIExoComponent;
19 import org.exoplatform.faces.core.component.model.Parameter;
20 import org.exoplatform.portal.session.PortalResources;
21 import org.exoplatform.portal.session.RequestInfo;
22 /**
23  * @email: tuan08@users.sourceforge.net
24  * @version: $Id: HtmlBasicRenderer.java,v 1.22 2004/10/16 21:13:51 tuan08 Exp $
25  */

26 public class HtmlBasicRenderer extends Renderer {
27     final static public String JavaDoc ACTION = UIExoComponent.ACTION ;
28   final static public String JavaDoc SAVE_ACTION = UIExoComponent.SAVE_ACTION ;
29   final static public String JavaDoc CANCEL_ACTION = UIExoComponent.CANCEL_ACTION ;
30   final static public String JavaDoc EDIT_ACTION = UIExoComponent.EDIT_ACTION ;
31   final static public String JavaDoc BACK_ACTION = UIExoComponent.BACK_ACTION ;
32   final static public String JavaDoc DELETE_ACTION = UIExoComponent.DELETE_ACTION ;
33   final static public String JavaDoc REMOVE_ACTION = UIExoComponent.DELETE_ACTION ;
34   
35   final static public Parameter[] EMPTY_PARAMS = new Parameter[0] ;
36   protected static Formater ft_ = Formater.getFormater(null) ;
37   final static public LinkRenderer defaultLinkRenderer = new LinkRenderer() ;
38   final static public ButtonRenderer defaultButtonRenderer = new ButtonRenderer() ;
39   
40   protected LinkRenderer linkRenderer_ = defaultLinkRenderer ;
41   protected ButtonRenderer buttonRenderer_ = defaultButtonRenderer ;
42     
43   public void decode(FacesContext context, UIComponent uiComponent) {
44   
45   }
46
47   public void encodeBegin( FacesContext context, UIComponent component ) throws IOException JavaDoc {
48   }
49
50   public void encodeChildren( FacesContext context, UIComponent component ) throws IOException JavaDoc {
51     //throw new IOException("user Children Renderer for class " + component.getClass().getName()) ;
52
}
53
54   public void encodeEnd( FacesContext context, UIComponent component ) throws IOException JavaDoc {
55   }
56   
57   public void renderChildren(FacesContext context, UIComponent component ) throws IOException JavaDoc {
58     List JavaDoc children = component.getChildren() ;
59     for(int i = 0 ; i < children.size() ; i++) {
60       UIComponent uiChild = (UIComponent) children.get(i) ;
61       if(uiChild.isRendered()) {
62         uiChild.encodeBegin(context) ;
63         uiChild.encodeChildren(context) ;
64         uiChild.encodeEnd(context) ;
65       }
66     }
67   }
68   
69   static public ResourceBundle JavaDoc getApplicationResourceBundle(ExternalContext eContext) {
70         if (eContext instanceof PortletExternalContext) {
71         PortletExternalContext econtext = (PortletExternalContext) eContext ;
72         return econtext.getApplicationResourceBundle() ;
73         }
74     PortalResources appres =
75       (PortalResources)SessionContainer.getComponent(PortalResources.class);
76     return appres.getApplicationResource();
77     }
78   
79   static public String JavaDoc getBaseURL(FacesContext context) {
80     ExternalContext econtext = context.getExternalContext();
81     if (econtext instanceof PortletExternalContext) {
82         return econtext.encodeActionURL("") ;
83     }
84     RequestInfo rinfo = (RequestInfo)SessionContainer.getComponent(RequestInfo.class);
85     return rinfo.getPageURI();
86   }
87  
88   static public void appendLink(ResponseWriter w, String JavaDoc text, String JavaDoc baseURL,
89                                 Parameter[] params, String JavaDoc tooltip) throws IOException JavaDoc {
90     w.write("<a");
91     w.write(" HREF='");w.write(baseURL) ;
92     for(int i = 0; i < params.length; i++) {
93       w.write("&amp;");w.write(params[i].getName());w.write('=');w.write(params[i].getValue()) ;
94     }
95     w.write("'");
96     if(tooltip == null || tooltip.length() == 0){
97       w.write(">");
98     }else {
99       w.write(" alt='");w.write(tooltip);w.write("'");
100       w.write(" title='");w.write(tooltip);w.write("'>");
101     }
102     w.write(text);
103     w.write("</a>") ;
104   }
105   
106   public String JavaDoc convertClientId(FacesContext context, String JavaDoc clientId) {
107     return clientId;
108   }
109 }
Popular Tags