KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > impl > DefaultPortalServiceInterceptor


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.services.portal.impl;
6
7 import java.util.List JavaDoc;
8 import org.exoplatform.services.database.HibernateService;
9 import org.exoplatform.services.portal.Interceptor;
10 import org.exoplatform.services.portal.community.CommunityConfigService;
11 import org.exoplatform.services.portal.community.CommunityNavigation;
12 import org.exoplatform.services.portal.community.CommunityPortal;
13 import org.exoplatform.services.portal.model.Node;
14 import org.exoplatform.services.portal.model.Page;
15 import org.exoplatform.services.portal.model.PageNode;
16 import org.exoplatform.services.portal.model.PortalConfig;
17 /**
18  * Jul 15, 2004
19  * @author: Tuan Nguyen
20  * @email: tuan08@users.sourceforge.net
21  * @version: $Id: DefaultInterceptor.java,v 1.6 2004/09/28 18:19:24 tuan08 Exp $
22  */

23 public class DefaultPortalServiceInterceptor implements Interceptor {
24   private HibernateService hservice_ ;
25   private CommunityConfigService communityService_ ;
26   
27   public DefaultPortalServiceInterceptor(HibernateService hservice,
28                                          CommunityConfigService communityService) throws Exception JavaDoc {
29     hservice_ = hservice ;
30     communityService_ = communityService ;
31   }
32   
33   public PortalConfig getPortalConfig(String JavaDoc owner) throws Exception JavaDoc {
34     CommunityPortal cp = communityService_.findCommunityPortal(owner) ;
35     boolean shared = false ;
36     if(cp != null) {
37       if(!cp.getPortal().equals("#{owner}")) {
38         owner = cp.getPortal() ;
39         shared = true ;
40       }
41     }
42     PortalConfigData data =
43       (PortalConfigData)hservice_.findOne(PortalConfigData.class, owner);
44     if(data == null) return null ;
45     PortalConfig config = data.getPortalConfig() ;
46     if(shared) {
47       config = (PortalConfig)config.softCloneObject() ;
48       config.setOwner(owner) ;
49       config.setEditPermission("noone") ;
50     }
51     return config ;
52   }
53   
54   public void savePortalConfig(PortalConfig config) throws Exception JavaDoc {
55     hservice_.save(new PortalConfigData(config)) ;
56   }
57   
58   public Page getPage(String JavaDoc pageId) throws Exception JavaDoc {
59     PageData data = (PageData)hservice_.findOne(PageData.class, pageId) ;
60     if(data != null)return data.getPage();
61     return null ;
62   }
63   
64   public void savePage(Page page) throws Exception JavaDoc {
65      hservice_.save(new PageData(page)) ;
66   }
67   
68   public Node getNodeNavigation(String JavaDoc owner) throws Exception JavaDoc {
69     NodeNavigationData data =
70       (NodeNavigationData)hservice_.findOne(NodeNavigationData.class, owner) ;
71     if(data == null) return null ;
72     PageNode pnode = data.getNodeNavigation().getNode() ;
73     NodeImpl root = new NodeImpl(pnode, null, 0) ;
74     List JavaDoc list = communityService_.findCommunityNavigation(owner) ;
75     for(int i = 0 ; i < list.size() ; i++) {
76       CommunityNavigation cn = (CommunityNavigation) list.get(i) ;
77       data = (NodeNavigationData)hservice_.findOne(NodeNavigationData.class, cn.getNavigation()) ;
78       PageNode sharedNode = data.getNodeNavigation().getNode();
79       List JavaDoc children = sharedNode.getChildren() ;
80       for(int j = 0 ; j < children.size() ; j++) {
81         PageNode pageChild = (PageNode) children.get(j) ;
82         NodeImpl shareChild = new NodeImpl(pageChild, root, 1) ;
83         shareChild.setShare(true) ;
84         root.addChild(shareChild) ;
85       }
86     }
87     return root ;
88   }
89   
90   public void saveNodeNavigation(String JavaDoc owner, Node node) throws Exception JavaDoc {
91     NodeImpl root = (NodeImpl) node ;
92     // remove shared node
93
PageNode prootNode = createPageNode(root) ;
94     hservice_.save(new NodeNavigationData(owner , prootNode)) ;
95   }
96   
97   private PageNode createPageNode(NodeImpl node) {
98     PageNode pnode = new PageNode() ;
99     pnode.setUri(node.getUri()) ;
100     pnode.setName(node.getName()) ;
101     pnode.setViewPermission(node.getViewPermission()) ;
102     pnode.setEditPermission(node.getEditPermission()) ;
103     pnode.setIcon(node.getIcon()) ;
104     pnode.setLabel(node.getLabel()) ;
105     pnode.setDescription(node.getDescription()) ;
106     pnode.setPageReference(node.getPageReference()) ;
107     for(int i = 0; i < node.getChildrenSize(); i++) {
108       NodeImpl child = (NodeImpl) node.getChild(i) ;
109       if(!child.isShare()) {
110         pnode.getChildren().add(createPageNode(child)) ;
111       }
112     }
113     return pnode ;
114   }
115 }
Popular Tags