KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > engines > sites > Sites_Engine


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 //
14
// Sites_Engine
15
// NK 21.05.2001
16
//
17

18 package org.jahia.engines.sites;
19
20 import java.util.Enumeration JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Vector JavaDoc;
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 JavaDoc ENGINE_NAME = "sites";
39     private static final String JavaDoc 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     /**
46      *
47      */

48     private Sites_Engine () {
49         logger.debug ("***** Starting " + Sites_Engine.class.getName () + " engine *****");
50         toolBox = EngineToolBox.getInstance ();
51     }
52
53
54     /**
55      *
56      */

57     public static synchronized Sites_Engine getInstance () {
58         if (instance == null) {
59             instance = new Sites_Engine ();
60         }
61         return instance;
62     }
63
64
65     /**
66      * authoriseRender
67      */

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 JavaDoc renderLink (ParamBean jParams, Object JavaDoc 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     /**
90      * Retrieve the engine name.
91      *
92      * @return the engine name.
93      */

94     public final String JavaDoc getName () {
95         return ENGINE_NAME;
96     }
97
98
99     /**
100      * process
101      */

102     public void process (ParamBean jParams) throws JahiaException {
103         // compose a new hashmap with engine properties...
104
HashMap JavaDoc engineMap = initEngineMap (jParams);
105
106         toolBox.displayScreen (jParams, engineMap);
107     }
108
109
110     /**
111      * inits the engine map
112      *
113      * @param jParams a ParamBean object (with request and response)
114      *
115      * @return a HashMap object containing all the basic values needed by an engine
116      */

117     private HashMap JavaDoc initEngineMap (ParamBean jParams)
118             throws JahiaException,
119             JahiaSessionExpirationException {
120         // init engine map
121
HashMap JavaDoc engineMap = new HashMap JavaDoc ();
122
123         // build the sites lists
124
Vector JavaDoc vec = new Vector JavaDoc ();
125         Enumeration JavaDoc 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 JavaDoc (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