1 5 package org.exoplatform.faces.core.renderer.html; 6 7 import java.io.IOException ; 8 import java.util.List ; 9 import java.util.ResourceBundle ; 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 26 public class HtmlBasicRenderer extends Renderer { 27 final static public String ACTION = UIExoComponent.ACTION ; 28 final static public String SAVE_ACTION = UIExoComponent.SAVE_ACTION ; 29 final static public String CANCEL_ACTION = UIExoComponent.CANCEL_ACTION ; 30 final static public String EDIT_ACTION = UIExoComponent.EDIT_ACTION ; 31 final static public String BACK_ACTION = UIExoComponent.BACK_ACTION ; 32 final static public String DELETE_ACTION = UIExoComponent.DELETE_ACTION ; 33 final static public String 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 { 48 } 49 50 public void encodeChildren( FacesContext context, UIComponent component ) throws IOException { 51 } 53 54 public void encodeEnd( FacesContext context, UIComponent component ) throws IOException { 55 } 56 57 public void renderChildren(FacesContext context, UIComponent component ) throws IOException { 58 List 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 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 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 text, String baseURL, 89 Parameter[] params, String tooltip) throws IOException { 90 w.write("<a"); 91 w.write(" HREF='");w.write(baseURL) ; 92 for(int i = 0; i < params.length; i++) { 93 w.write("&");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 convertClientId(FacesContext context, String clientId) { 107 return clientId; 108 } 109 } | Popular Tags |