1 40 41 package org.jahia.admin.homepages; 42 43 import java.io.IOException ; 44 import java.util.ArrayList ; 45 import java.util.Enumeration ; 46 import java.util.Vector ; 47 48 import javax.servlet.ServletException ; 49 import javax.servlet.http.HttpServletRequest ; 50 import javax.servlet.http.HttpServletResponse ; 51 import javax.servlet.http.HttpSession ; 52 53 import org.jahia.bin.JahiaAdministration; 54 import org.jahia.data.JahiaData; 55 import org.jahia.engines.selectpage.SelectPage_Engine; 56 import org.jahia.exceptions.JahiaException; 57 import org.jahia.params.ParamBean; 58 import org.jahia.registries.ServicesRegistry; 59 import org.jahia.resourcebundle.JahiaResourceBundle; 60 import org.jahia.services.fields.ContentField; 61 import org.jahia.services.homepages.HomepageTypes; 62 import org.jahia.services.homepages.JahiaHomepage; 63 import org.jahia.services.homepages.JahiaHomepageLink; 64 import org.jahia.services.homepages.JahiaHomepagesService; 65 import org.jahia.services.pages.ContentPage; 66 import org.jahia.services.pages.JahiaPageBaseService; 67 import org.jahia.services.sites.JahiaSite; 68 import org.jahia.services.version.EntryLoadRequest; 69 import org.jahia.utils.LanguageCodeConverters; 70 71 79 public class HomePageTool { 80 81 82 private static org.apache.log4j.Logger logger = 83 org.apache.log4j.Logger.getLogger (HomePageTool.class); 84 85 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 86 87 private JahiaSite jahiaSite; 88 89 private String message = ""; 90 private ParamBean jParams; 91 92 public static final String ENGINE_LAUNCHER_NAME = HomePageTool.class.getName (); 93 94 101 public HomePageTool (HttpServletRequest request, HttpServletResponse response, 102 HttpSession session) 103 throws Throwable { 104 jahiaSite = (JahiaSite)session.getAttribute (ParamBean.SESSION_SITE); 106 107 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 108 this.jParams = jData.params (); 109 110 requestDispatcher (request, response, session); 112 } 113 114 121 public void requestDispatcher (HttpServletRequest request, 122 HttpServletResponse response, 123 HttpSession session) 124 throws Throwable { 125 String operation = request.getParameter ("subaction"); 126 127 try { 128 if (operation.equals ("display")) { 129 displayHomePageTool (request, response, session); 130 } else if (operation.equals ("process")) { 131 processHomePageTool (request, response, session); 132 } 133 } catch (Throwable t) { 134 logger.warn (t); 135 } 136 } 137 138 149 private void doRedirect (HttpServletRequest request, 150 HttpServletResponse response, 151 HttpSession session, 152 String target) 153 throws IOException , ServletException { 154 try { 155 if (request.getAttribute ("warningMsg") == null) { 157 request.setAttribute ("warningMsg", ""); 158 } 159 160 if (request.getAttribute ("msg") == null) { 162 request.setAttribute ("msg", 163 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 164 jParams, jParams.getLocale())); 165 } 166 167 if (request.getAttribute ("focus") == null) { 168 request.setAttribute ("focus", "-none-"); 169 } 170 171 if (request.getAttribute ("title") == null) { 173 request.setAttribute ("title", "Home Page Tool"); 174 } 175 176 JahiaAdministration.doRedirect (request, response, session, target); 178 179 } catch (IOException ie) { 180 logger.warn (ie); 181 182 } catch (ServletException se) { 183 logger.warn (se); 184 } 185 } 186 187 188 private void displayHomePageTool (HttpServletRequest request, 189 HttpServletResponse response, 190 HttpSession session) 191 throws IOException , ServletException , JahiaException { 192 logger.info("Started"); 193 JahiaHomepagesService homePageService = ServicesRegistry.getInstance ().getJahiaHomepagesService (); 195 Enumeration homePageEnumeration = homePageService.getHomepages (jahiaSite); 196 request.setAttribute ("homePageEnumeration", homePageEnumeration); 197 198 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance (); 200 Vector allPagesIDVector = pageService.getPageIDsInSite (jahiaSite.getID (), 201 org.jahia.services.pages.PageInfoInterface.TYPE_DIRECT); 202 ArrayList sitePages = new ArrayList (); 204 Enumeration allPagesIDEnumeration = allPagesIDVector.elements (); 205 while (allPagesIDEnumeration.hasMoreElements ()) { 206 Integer pageID = (Integer )allPagesIDEnumeration.nextElement (); 207 ContentPage contentPage = pageService.lookupContentPage (pageID.intValue (), jParams.getEntryLoadRequest (), false); 208 sitePages.add (contentPage); 209 } 210 request.setAttribute ("sitePages", sitePages); 211 int pageID = SelectPage_Engine.getInstance ().getSelectedPageID (session); 212 if (pageID != -1) { 213 request.setAttribute ("pageID", new Integer (pageID)); 214 request.setAttribute ("homePageID", new Integer (pageID)); 215 } else { 216 Integer homePageID = (Integer )session.getAttribute ("homePageID"); 217 if (homePageID == null) { 218 homePageID = new Integer (-1); 219 } 220 } 221 request.setAttribute ("jahiaSite", jahiaSite); 222 request.setAttribute ("jspSource", JSP_PATH + "homepages/popup/homepagetool.jsp"); 223 session.setAttribute ("jahiaDisplayMessage", 224 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 225 jParams, jParams.getLocale())); 226 request.setAttribute ("message", message); 227 doRedirect (request, response, session, JSP_PATH + "adminpopup.jsp"); 228 message = ""; 229 } 230 231 private void processHomePageTool (HttpServletRequest request, 232 HttpServletResponse response, 233 HttpSession session) 234 throws IOException , ServletException , JahiaException { 235 logger.info("Started"); 236 String choice = request.getParameter ("choice"); 237 if (choice != null) { 238 if (choice.equals ("sitePage")) { 239 String pageID = request.getParameter ("pageID"); 240 logger.debug("Site Page ID : " + pageID); 241 if (pageID == null) { 242 message = JahiaResourceBundle.getAdminResource ("org.jahia.admin.Message.selectSitePage.label", 243 jParams, jParams.getLocale ()); 244 } else { 245 ArrayList locales = jahiaSite.getLanguageSettingsAsLocales (false); 246 EntryLoadRequest loadRequest = jParams.getEntryLoadRequest (); 247 if (!locales.contains (jParams.getLocale ())) { 248 loadRequest = EntryLoadRequest.STAGED; 249 locales.add (0, LanguageCodeConverters.languageCodeToLocale (ContentField.SHARED_LANGUAGE)); 250 loadRequest.setLocales (locales); 251 } 252 session.setAttribute ("homePageID", new Integer (pageID)); 253 session.setAttribute ("homePageLabel", JahiaPageBaseService. 254 getInstance ().lookupContentPage (Integer.parseInt (pageID), loadRequest, false).getTitle (loadRequest)); 255 request.setAttribute ("suicide", ""); 256 } 257 258 } else if (choice.equals ("removeHomePage")) { 259 session.setAttribute ("homePageID", new Integer (-1)); 260 session.setAttribute ("homePageLabel", "none"); 261 request.setAttribute ("suicide", ""); 262 263 } else { JahiaHomepagesService homePageService = 265 ServicesRegistry.getInstance ().getJahiaHomepagesService (); 266 String homePageDefID = request.getParameter ("homePageDefID"); 267 JahiaHomepage homePage = homePageService.getHomepage (Integer.parseInt (homePageDefID)); 268 if (homePage.getType () == HomepageTypes.HOMEPAGE_LINK) { 269 logger.debug ("Home Page ID : " + homePageDefID); 270 JahiaHomepageLink homePageLink = (JahiaHomepageLink)homePage; 271 session.setAttribute ("homePageID", new Integer (homePageLink.getPageID ())); 272 session.setAttribute ("homePageLabel", JahiaPageBaseService. 273 getInstance ().lookupPageWhitoutTemplates (homePageLink.getPageID ()).getTitle ()); 274 } else if (homePage.getType () == HomepageTypes.HOMEPAGE_NEW) { 275 } else if (homePage.getType () == HomepageTypes.HOMEPAGE_COPY) { 277 } 279 request.setAttribute ("suicide", ""); 280 } 281 282 } else { 283 message = JahiaResourceBundle.getAdminResource ("org.jahia.admin.Message.selectRadioBoxes.label", 284 jParams, jParams.getLocale ()); 285 } 286 displayHomePageTool (request, response, session); 287 } 288 289 } 290 | Popular Tags |