1 5 package org.exoplatform.portal.faces.component; 6 7 import org.exoplatform.services.idgenerator.IDGeneratorService; 8 import org.exoplatform.container.configuration.*; 9 14 public class PortalComponentIDGenerator { 15 final static public String UUID_ALGORITHM = "uuid" ; 16 final static public String EXO_ALGORITHM = "exo" ; 17 18 private IDGeneratorService idservice_ ; 19 private String algorithm_ ; 20 21 public PortalComponentIDGenerator(IDGeneratorService idservice, 22 ConfigurationManager cservice) throws Exception { 23 idservice_ = idservice ; 24 ServiceConfiguration sconf = cservice.getServiceConfiguration(getClass()) ; 25 ValueParam param = sconf.getValueParam("algorithm") ; 26 algorithm_ = param.getValue() ; 27 } 28 29 public String generatePortletId(UIPortal uiPortal, String portletName) { 30 if(UUID_ALGORITHM.equals(algorithm_)) { 31 return "P" + idservice_.generateStringID(portletName) ; 32 } 33 String id = portletName ; 34 if(uiPortal.findComponentById(id) != null || 35 uiPortal.getCurrentUIPage().findComponentById(id) != null) { 36 id = "P" + idservice_.generateStringID(portletName) ; 37 } 38 return id ; 39 } 40 41 public String generateContainerId(UIPortal uiPortal, String containerName) { 42 if(UUID_ALGORITHM.equals(algorithm_)) { 43 return "P" + idservice_.generateStringID(containerName) ; 44 } 45 return containerName ; 46 } 47 48 public String generatePageId(UIPortal uiPortal, String pageName) { 49 if(UUID_ALGORITHM.equals(algorithm_)) { 50 return "P" + idservice_.generateStringID(pageName) ; 51 } 52 return pageName ; 53 } 54 } | Popular Tags |