1 14 package org.jahia.engines.sitemap; 15 16 import java.util.HashMap ; 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 29 30 39 public class SiteMap_Engine implements JahiaEngine { 40 41 public static final String ENGINE_NAME = "sitemap"; 42 43 public final static String DEFAULT_LEVEL = "org.jahia.engines.sitemap.SiteMap_Engine.defaultLevel"; 47 48 private static final String 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 58 private SiteMap_Engine () { 59 logger.debug ("***** Starting " + SiteMap_Engine.class.getName () + " engine *****"); 60 } 61 62 65 public static synchronized SiteMap_Engine getInstance () { 66 if (instance == null) { 67 instance = new SiteMap_Engine (); 68 } 69 return instance; 70 } 71 72 79 public boolean authoriseRender (ParamBean jParams) { 80 return true; 81 } 82 83 93 public String renderLink (ParamBean jParams, Object theObj) 94 throws JahiaException { 95 String theUrl = jParams.composeEngineUrl (ENGINE_NAME, EMPTY_STRING); 96 if (theObj != null) 97 theUrl += theObj; 98 return jParams.getResponse ().encodeURL (theUrl); 99 } 100 101 108 public boolean needsJahiaData (ParamBean jParams) { 109 return true; 110 } 111 112 120 public void handleActions (ParamBean jParams, JahiaData jData) 121 throws JahiaException { 122 HashMap engineMap = new HashMap (); 123 String 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 (JahiaEngine.RENDERTYPE_FORWARD)); 129 engineMap.put (ENGINE_NAME_PARAM, ENGINE_NAME); 130 engineMap.put (ENGINE_URL_PARAM, jParams.composeEngineUrl (ENGINE_NAME, EMPTY_STRING)); 131 ContentPage contentPage = ServicesRegistry.getInstance (). 133 getJahiaPageService ().lookupContentPage (jParams.getSite ().getHomePageID (), 134 false); 135 JahiaSiteMapService siteMapService = ServicesRegistry.getInstance (). 136 getJahiaSiteMapService (); 137 int pageInfosFlag; 138 String languageCode = jParams.getLocale ().toString (); String 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; } 149 } else { 150 pageInfosFlag = ContentPage.ACTIVE_PAGE_INFOS | ContentPage.STAGING_PAGE_INFOS; 151 } 152 int defaultLevel = SiteMapViewHelper.DEFAULT_LEVEL; 153 Integer defaultLevelInt = (Integer ) 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 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 175 public final String getName () { 176 return ENGINE_NAME; 177 } 178 179 } 180 | Popular Tags |