KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > faces > component > PortalComponentIDGenerator


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.portal.faces.component;
6
7 import org.exoplatform.services.idgenerator.IDGeneratorService;
8 import org.exoplatform.container.configuration.*;
9 /**
10  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
11  * @since Nov 2, 2004
12  * @version $Id: PortalComponentIDGenerator.java,v 1.1 2004/11/03 01:19:44 tuan08 Exp $
13  */

14 public class PortalComponentIDGenerator {
15   final static public String JavaDoc UUID_ALGORITHM = "uuid" ;
16   final static public String JavaDoc EXO_ALGORITHM = "exo" ;
17   
18   private IDGeneratorService idservice_ ;
19   private String JavaDoc algorithm_ ;
20   
21   public PortalComponentIDGenerator(IDGeneratorService idservice,
22                                     ConfigurationManager cservice) throws Exception JavaDoc {
23     idservice_ = idservice ;
24     ServiceConfiguration sconf = cservice.getServiceConfiguration(getClass()) ;
25     ValueParam param = sconf.getValueParam("algorithm") ;
26     algorithm_ = param.getValue() ;
27   }
28   
29   public String JavaDoc generatePortletId(UIPortal uiPortal, String JavaDoc portletName) {
30     if(UUID_ALGORITHM.equals(algorithm_)) {
31       return "P" + idservice_.generateStringID(portletName) ;
32     }
33     String JavaDoc 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 JavaDoc generateContainerId(UIPortal uiPortal, String JavaDoc containerName) {
42     if(UUID_ALGORITHM.equals(algorithm_)) {
43       return "P" + idservice_.generateStringID(containerName) ;
44     }
45     return containerName ;
46   }
47   
48   public String JavaDoc generatePageId(UIPortal uiPortal, String JavaDoc pageName) {
49     if(UUID_ALGORITHM.equals(algorithm_)) {
50       return "P" + idservice_.generateStringID(pageName) ;
51     }
52     return pageName ;
53   }
54 }
Popular Tags