KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > engines > sitemap > SiteMap_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 package org.jahia.engines.sitemap;
15
16 import java.util.HashMap JavaDoc;
17
18 import org.jahia.data.JahiaData;
19 import org.jahia.data.viewhelper.sitemap.SiteMapViewHelper;
20 import org.jahia.engines.EngineToolBox;
21 import org.jahia.engines.JahiaEngine;
22 import org.jahia.exceptions.JahiaException;
23 import org.jahia.params.ParamBean;
24 import org.jahia.registries.ServicesRegistry;
25 import org.jahia.services.pages.ContentPage;
26 import org.jahia.services.sitemap.JahiaSiteMapService;
27
28 /** @todo this engine should be modified if site map defined with tag lib !! */
29
30 /**
31  * <p>Title: Jahia site map</p> <p>Description: Manage a tree view of a Site Map for a Jahia
32  * Site.</p> <p>Copyright: MAP (Jahia Solutions S�rl 2002)</p> <p>Company: Jahia Solutions
33  * S�rl</p>
34  *
35  * @author Mikha�l Janson
36  * @author MAP
37  * @version 3.0
38  */

39 public class SiteMap_Engine implements JahiaEngine {
40
41     public static final String JavaDoc ENGINE_NAME = "sitemap";
42
43     // Session variable that can be initialize in templates :
44
// For example :
45
// jParams.getSession().setAttribute(org.jahia.engines.sitemap.SiteMap_Engine.DEFAULT_LEVEL, new Integer(2));
46
public final static String JavaDoc DEFAULT_LEVEL = "org.jahia.engines.sitemap.SiteMap_Engine.defaultLevel";
47
48     private static final String JavaDoc SITEMAP_JSP_NAME = "sitemap.jsp";
49
50     private static SiteMap_Engine instance = null;
51
52     private static final org.apache.log4j.Logger logger =
53             org.apache.log4j.Logger.getLogger (SiteMap_Engine.class);
54
55     /**
56      * Constructor
57      */

58     private SiteMap_Engine () {
59         logger.debug ("***** Starting " + SiteMap_Engine.class.getName () + " engine *****");
60     }
61
62     /**
63      * @return Returns a single instance of the object
64      */

65     public static synchronized SiteMap_Engine getInstance () {
66         if (instance == null) {
67             instance = new SiteMap_Engine ();
68         }
69         return instance;
70     }
71
72     /**
73      * Authorises engine render
74      *
75      * @param jParams The ParamBean object.
76      *
77      * @return always true.
78      */

79     public boolean authoriseRender (ParamBean jParams) {
80         return true;
81     }
82
83     /**
84      * Renders link to pop-up window
85      *
86      * @param jParams The ParamBean object.
87      * @param theObj A String object
88      *
89      * @return The URL to this engine.
90      *
91      * @throws JahiaException
92      */

93     public String JavaDoc renderLink (ParamBean jParams, Object JavaDoc theObj)
94             throws JahiaException {
95         String JavaDoc theUrl = jParams.composeEngineUrl (ENGINE_NAME, EMPTY_STRING);
96         if (theObj != null)
97             theUrl += theObj;
98         return jParams.getResponse ().encodeURL (theUrl);
99     }
100
101     /**
102      * Specifies if the engine needs the JahiaData object
103      *
104      * @param jParams The ParamBean object
105      *
106      * @return always true.
107      */

108     public boolean needsJahiaData (ParamBean jParams) {
109         return true;
110     }
111
112     /**
113      * Handles the engine actions
114      *
115      * @param jParams a ParamBean object
116      * @param jData a JahiaData object
117      *
118      * @throws JahiaException
119      */

120     public void handleActions (ParamBean jParams, JahiaData jData)
121             throws JahiaException {
122         HashMap JavaDoc engineMap = new HashMap JavaDoc ();
123         String JavaDoc jspSiteMapFileName = jParams.getPage ().getPageTemplate ().getSourcePath ();
124         jspSiteMapFileName = jspSiteMapFileName.substring (0,
125                 jspSiteMapFileName.lastIndexOf ("/") + 1) +
126                 SITEMAP_JSP_NAME;
127         engineMap.put (ENGINE_OUTPUT_FILE_PARAM, jspSiteMapFileName);
128         engineMap.put (RENDER_TYPE_PARAM, new Integer JavaDoc (JahiaEngine.RENDERTYPE_FORWARD));
129         engineMap.put (ENGINE_NAME_PARAM, ENGINE_NAME);
130         engineMap.put (ENGINE_URL_PARAM, jParams.composeEngineUrl (ENGINE_NAME, EMPTY_STRING));
131         // Create site map
132
ContentPage contentPage = ServicesRegistry.getInstance ().
133                 getJahiaPageService ().lookupContentPage (jParams.getSite ().getHomePageID (),
134                         false);
135         JahiaSiteMapService siteMapService = ServicesRegistry.getInstance ().
136                 getJahiaSiteMapService ();
137         int pageInfosFlag;
138         String JavaDoc languageCode = jParams.getLocale ().toString (); //null; // this language per default.
139
String JavaDoc allLanguages = jParams.getRequest ().getParameter ("allLanguages");
140         if (allLanguages == null) {
141             allLanguages = "off";
142         }
143         engineMap.put ("allLanguages", allLanguages);
144         if (jData.gui ().isNormalMode ()) {
145             pageInfosFlag = ContentPage.ACTIVE_PAGE_INFOS;
146             if ("on".equals (allLanguages)) {
147                 languageCode = null; //jParams.getLocale().toString();
148
}
149         } else {
150             pageInfosFlag = ContentPage.ACTIVE_PAGE_INFOS | ContentPage.STAGING_PAGE_INFOS;
151         }
152         int defaultLevel = SiteMapViewHelper.DEFAULT_LEVEL;
153         Integer JavaDoc defaultLevelInt = (Integer JavaDoc) jParams.getSession ().getAttribute (DEFAULT_LEVEL);
154         if (defaultLevelInt != null) {
155             defaultLevel = defaultLevelInt.intValue ();
156         }
157         SiteMapViewHelper siteMapViewHelper = siteMapService.getTreeSiteMapViewHelper (
158                 jParams.getUser (), contentPage, jParams.getSessionID (), pageInfosFlag,
159                 languageCode, defaultLevel);
160         engineMap.put ("treeJahiaSiteMap", siteMapViewHelper);
161         String JavaDoc siteMapParam = jParams.getParameter ("sitemap");
162         if (siteMapParam != null) {
163             siteMapService.invokeTreeSiteMapViewHelperMethod (jParams.getUser (),
164                     contentPage, jParams.getSessionID (), pageInfosFlag, languageCode,
165                     siteMapParam);
166         }
167         EngineToolBox.getInstance ().displayScreen (jParams, engineMap);
168     }
169
170     /**
171      * Retrieve the engine name.
172      *
173      * @return the engine name.
174      */

175     public final String JavaDoc getName () {
176         return ENGINE_NAME;
177     }
178
179 }
180
Popular Tags