1 5 package org.exoplatform.portlet.faces.component; 6 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import javax.faces.context.FacesContext; 10 import javax.faces.context.ResponseWriter; 11 import javax.portlet.PortletConfig ; 12 13 import org.exoplatform.faces.core.component.UIExoComponentBase; 14 import org.exoplatform.portlet.faces.context.ExternalContextImpl ; 15 21 public class UISimpleHelp extends UIExoComponentBase { 22 public static final String COMPONENT_TYPE = "UISimpleHelp"; 23 public static final String RENDERER_TYPE = "NoRenderer"; 24 25 private String content_ ; 26 public UISimpleHelp() { 27 try { 28 ExternalContextImpl eContext = 29 (ExternalContextImpl) FacesContext.getCurrentInstance().getExternalContext() ; 30 PortletConfig config = eContext.getConfig() ; 31 String path = config.getInitParameter("portlet-help-file") ; 32 if (path != null) { 33 InputStream is = eContext.getResourceAsStream(path) ; 34 if (is != null) { 35 byte[] buf = new byte[is.available()] ; 36 is.read(buf) ; 37 content_ = new String (buf) ; 38 } else { 39 content_ = "The help file is not available" ; 40 } 41 } else { 42 content_ = "The help file is not available" ; 44 } 45 } catch (Exception ex) { 46 content_ = ex.getMessage() ; 47 ex.printStackTrace() ; 48 } 49 } 50 51 public String getComponentType() { return COMPONENT_TYPE; } 52 53 public String getRendererType() { return RENDERER_TYPE; } 54 55 56 public void decode(FacesContext context) { 57 } 58 59 final public void encodeBegin(FacesContext context) throws IOException { 60 ResponseWriter w = context.getResponseWriter() ; 61 w.write(content_); 62 } 63 64 final public void encodeChildren(FacesContext context) throws IOException { 65 } 66 67 final public void encodeEnd(FacesContext context) throws IOException { 68 } 69 } 70 | Popular Tags |