1 5 package org.exoplatform.services.portal.impl; 6 7 import java.util.List ; 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 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 { 29 hservice_ = hservice ; 30 communityService_ = communityService ; 31 } 32 33 public PortalConfig getPortalConfig(String owner) throws Exception { 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 { 55 hservice_.save(new PortalConfigData(config)) ; 56 } 57 58 public Page getPage(String pageId) throws Exception { 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 { 65 hservice_.save(new PageData(page)) ; 66 } 67 68 public Node getNodeNavigation(String owner) throws Exception { 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 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 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 owner, Node node) throws Exception { 91 NodeImpl root = (NodeImpl) node ; 92 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 |