1 5 package org.exoplatform.portal.faces.component; 6 7 import org.exoplatform.commons.utils.ExceptionUtil; 8 import org.exoplatform.container.PortalContainer; 9 import org.exoplatform.container.SessionContainer; 10 import org.exoplatform.container.client.http.HttpClientInfo; 11 import org.exoplatform.faces.UIComponentFactory; 12 import org.exoplatform.portal.session.ExoPortal; 13 import org.exoplatform.services.cache.SimpleExoCache; 14 import org.exoplatform.services.log.LogUtil; 15 import org.exoplatform.services.portal.PortalACL; 16 import org.exoplatform.services.portal.PortalConfigService; 17 import org.exoplatform.services.portal.model.Node; 18 import org.exoplatform.services.portal.model.Page; 19 import org.exoplatform.services.portal.model.PageReference; 20 25 public class PortalComponentCache { 26 private UIComponentFactory componentFactory_ ; 27 private SimpleExoCache cache_ ; 28 29 public PortalComponentCache() { 30 componentFactory_ = new UIComponentFactory(null) ; 31 cache_ = new SimpleExoCache(20) ; 33 } 34 35 public Object getPortalComponent(Class clazz) { 36 try { 37 Object object = cache_.get(clazz.getName()) ; 38 if(object == null) { 39 object = componentFactory_.createUIComponent(clazz) ; 40 cache_.put(clazz.getName(), object) ; 41 } 42 return object ; 43 } catch (Exception ex) { 44 LogUtil.getLog(getClass()).error( "create component :" + clazz.getName(), ex) ; 45 } 46 return null ; 47 } 48 49 public UIPage getUIPage(Node node, UIPortal uiPortal) { 50 SessionContainer scontainer = SessionContainer.getInstance() ; 51 try { 52 HttpClientInfo info = (HttpClientInfo) scontainer.getMonitor().getClientInfo() ; 53 PageReference pref = node.getPageReference(info.getPreferredMimeType()) ; 54 if(pref == null ) { 55 pref = node.getPageReference(ExoPortal.XHTML_MIME_TYPE) ; 56 } 57 String referenceId = pref.getPageReference(); 58 UIPage uiPage = (UIPage) cache_.get(referenceId) ; 59 if (uiPage == null && referenceId != null) { 60 61 PortalConfigService configService = 62 (PortalConfigService) PortalContainer.getComponent(PortalConfigService.class) ; 63 PortalACL portalACL = configService.getPortalACL() ; 64 Page config = configService.getPage(referenceId); 65 if(config == null) { 66 uiPage = new UIPage() ; 67 uiPage.setError("Cannot find the page " + referenceId) ; 68 } else if (!portalACL.hasViewPagePermission(config, uiPortal.getOwner())) { 69 uiPage = new UIPage() ; 70 uiPage.setError("User do not have the right to access the page " + referenceId) ; 71 } else { 72 uiPage = new UIPage(config, "default"); 73 uiPage.setRendered(true); 74 if(uiPortal.hasComponentAdminRole() && 75 portalACL.hasEditPagePermission(config, uiPortal.getOwner())) { 76 uiPage.setComponentAdminRole(true) ; 77 } 78 cache_.put(referenceId, uiPage); 79 } 80 81 } 82 return uiPage ; 83 } catch (Throwable t) { 84 t = ExceptionUtil.getRootCause(t) ; 85 LogUtil.getLog(getClass()).error("Error: ", t) ; 86 } 87 return null ; 88 } 89 90 public void removeUIPageFromCache(String referenceId) throws Exception { 91 cache_.remove(referenceId); 92 } 93 } 94 | Popular Tags |