KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > forum > component > UIForumPortlet


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
6 package org.exoplatform.portlets.communication.forum.component;
7
8 import java.util.*;
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11 import javax.portlet.PortletPreferences;
12 import org.exoplatform.Constants;
13 import org.exoplatform.faces.FacesUtil;
14 import org.exoplatform.faces.core.component.UIExoComponent;
15 import org.exoplatform.faces.core.component.UIPortlet;
16 import org.exoplatform.portlets.communication.forum.ForumACL;
17 import org.exoplatform.services.communication.forum.ForumService;
18 import org.exoplatform.services.communication.forum.ForumServiceContainer;
19 import org.exoplatform.services.grammar.wiki.WikiEngineService;
20 import org.exoplatform.services.indexing.IndexingService;
21 import org.exoplatform.services.organization.OrganizationService;
22 /**
23  * @author Benjamin Mestrallet benjamin.mestrallet@exoplatform.com
24  */

25 public class UIForumPortlet extends UIPortlet {
26   
27   private Stack history;
28
29   public UIForumPortlet(ForumServiceContainer container,
30                         OrganizationService orgService,
31                         IndexingService iservice,
32                         WikiEngineService weService) throws Exception JavaDoc {
33     setId("UIForumPortlet");
34     setRendererType("ChildrenRenderer");
35     history = new Stack();
36     PortletPreferences prefs = FacesUtil.getPortletPreferences();
37     String JavaDoc forumOwner = prefs.getValue("forum-owner", Constants.DEFAUL_PORTAL_OWNER);
38     String JavaDoc remoteUser =
39       FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
40     ForumACL acl = new ForumACL(remoteUser);
41     if (remoteUser == null) remoteUser = "anonymous";
42     ForumService service = container.findForumService(forumOwner);
43
44     List children = getChildren();
45     
46     UIToolbarPanel toolbarPanel = new UIToolbarPanel();
47     toolbarPanel.setRendered(true);
48     children.add(toolbarPanel);
49     
50     UIViewCategories uiViewCategories = new UIViewCategories(service);
51     uiViewCategories.setRendered(true);
52     children.add(uiViewCategories);
53
54     UITopics uiTopics = new UITopics(orgService, service, acl);
55     uiTopics.setRendered(false);
56     children.add(uiTopics);
57
58     UIPosts uiPosts = new UIPosts(weService, orgService, service, acl);
59     uiPosts.setRendered(false);
60     children.add(uiPosts);
61
62     UIPostForm uiPostForm = new UIPostForm(service);
63     uiPostForm.setRendered(false);
64     children.add(uiPostForm);
65
66     UIForumSearcher panel = new UIForumSearcher(service, iservice);
67     panel.setRendered(false);
68     children.add(panel);
69     
70     UIWatchForm uiWatchForm = new UIWatchForm(service) ;
71     uiWatchForm.setRendered(false) ;
72     children.add(uiWatchForm) ;
73   }
74   
75   public UIComponent getRenderedComponent(){
76     Collection children = getChildren();
77     for (Iterator iter = children.iterator(); iter.hasNext();) {
78       UIComponent element = (UIComponent) iter.next();
79       if(!(element instanceof UIToolbarPanel) && element.isRendered())
80         return element;
81     }
82     return null;
83   }
84   
85   public void addHistoryElement(UIComponent component){
86     history.add(component);
87   }
88   
89   public void undo(){
90     if(history.size() > 0)
91       setRenderedComponent(((UIComponent)history.pop()).getId());
92   }
93
94   public void processDecodes(FacesContext context) {
95     Map paramMap = context.getExternalContext().getRequestParameterMap();
96     String JavaDoc uicomponent = (String JavaDoc) paramMap.get(UICOMPONENT);
97     UIExoComponent uiComp = findRenderedComponentById(uicomponent);
98     if (uiComp != null) {
99       uiComp.processDecodes(context);
100       return;
101     }
102     //user click back button
103
uiComp = findComponentById(uicomponent);
104     if (uiComp.canDecodeInvalidState()) {
105       uiComp.processDecodes(context);
106     }
107   }
108
109 }
Popular Tags