KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlet > faces > component > UISimpleHelp


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.portlet.faces.component;
6
7 import java.io.IOException JavaDoc ;
8 import java.io.InputStream JavaDoc ;
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 /**
16  * Wed, Dec 22, 2003 @ 23:14
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $Id: UISimpleHelp.java,v 1.4 2004/07/06 13:38:18 oranheim Exp $
20  */

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