1 13 18 package org.jahia.engines.sites; 19 20 import java.util.Enumeration ; 21 import java.util.HashMap ; 22 import java.util.Vector ; 23 24 import org.jahia.data.JahiaData; 25 import org.jahia.engines.EngineToolBox; 26 import org.jahia.engines.JahiaEngine; 27 import org.jahia.exceptions.JahiaException; 28 import org.jahia.exceptions.JahiaSessionExpirationException; 29 import org.jahia.params.ParamBean; 30 import org.jahia.registries.ServicesRegistry; 31 import org.jahia.services.sites.JahiaSite; 32 import org.jahia.services.sites.JahiaSitesService; 33 34 35 public class Sites_Engine implements JahiaEngine { 36 37 private static Sites_Engine instance = null; 38 public static final String ENGINE_NAME = "sites"; 39 private static final String TEMPLATE_JSP = "/jsp/jahia/engines/sites/sites_launcher.jsp"; 40 private EngineToolBox toolBox; 41 42 private static final org.apache.log4j.Logger logger 43 = org.apache.log4j.Logger.getLogger (Sites_Engine.class); 44 45 48 private Sites_Engine () { 49 logger.debug ("***** Starting " + Sites_Engine.class.getName () + " engine *****"); 50 toolBox = EngineToolBox.getInstance (); 51 } 52 53 54 57 public static synchronized Sites_Engine getInstance () { 58 if (instance == null) { 59 instance = new Sites_Engine (); 60 } 61 return instance; 62 } 63 64 65 68 public boolean authoriseRender (ParamBean jParams) { 69 return (jParams.getOperationMode () == ParamBean.EDIT); 70 } 71 72 73 public boolean needsJahiaData (ParamBean jParams) { 74 return false; 75 } 76 77 78 public String renderLink (ParamBean jParams, Object theObj) 79 throws JahiaException { 80 return jParams.composeEngineUrl (ENGINE_NAME, EMPTY_STRING); 81 } 82 83 84 public void handleActions (ParamBean jParams, JahiaData jData) 85 throws JahiaException { 86 process (jParams); 87 } 88 89 94 public final String getName () { 95 return ENGINE_NAME; 96 } 97 98 99 102 public void process (ParamBean jParams) throws JahiaException { 103 HashMap engineMap = initEngineMap (jParams); 105 106 toolBox.displayScreen (jParams, engineMap); 107 } 108 109 110 117 private HashMap initEngineMap (ParamBean jParams) 118 throws JahiaException, 119 JahiaSessionExpirationException { 120 HashMap engineMap = new HashMap (); 122 123 Vector vec = new Vector (); 125 Enumeration enumeration = vec.elements (); 126 127 JahiaSitesService sitesServ = ServicesRegistry.getInstance () 128 .getJahiaSitesService (); 129 130 if (sitesServ != null) { 131 try { 132 enumeration = sitesServ.getSites (); 133 } catch (JahiaException ex) { 134 enumeration = vec.elements (); 135 } 136 } 137 138 boolean isSuperAdmin = jParams.getUser ().isAdminMember (0); 139 140 while (enumeration.hasMoreElements ()) { 141 JahiaSite site = (JahiaSite) enumeration.nextElement (); 142 if (isSuperAdmin || jParams.getUser ().isAdminMember (site.getID ())) { 143 vec.add (site); 144 } 145 } 146 engineMap.put (RENDER_TYPE_PARAM, new Integer (JahiaEngine.RENDERTYPE_FORWARD)); 147 engineMap.put (ENGINE_NAME_PARAM, ENGINE_NAME); 148 engineMap.put (ENGINE_URL_PARAM, jParams.composeEngineUrl (ENGINE_NAME, EMPTY_STRING)); 149 engineMap.put (ENGINE_OUTPUT_FILE_PARAM, TEMPLATE_JSP); 150 151 engineMap.put ("sitesList", vec.elements ()); 152 153 return engineMap; 154 155 } 156 157 } 158 | Popular Tags |