1 21 package org.jahia.admin.pages; 22 23 import java.io.IOException ; 24 import java.util.Enumeration ; 25 import java.util.Vector ; 26 27 import javax.servlet.ServletException ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.http.HttpSession ; 31 32 import org.jahia.bin.JahiaAdministration; 33 import org.jahia.data.JahiaData; 34 import org.jahia.exceptions.JahiaException; 35 import org.jahia.exceptions.JahiaTemplateNotFoundException; 36 import org.jahia.params.ParamBean; 37 import org.jahia.registries.ServicesRegistry; 38 import org.jahia.resourcebundle.JahiaResourceBundle; 39 import org.jahia.services.pages.ContentPage; 40 import org.jahia.services.pages.JahiaPage; 41 import org.jahia.services.pages.JahiaPageBaseService; 42 import org.jahia.services.pages.JahiaPageDefinition; 43 import org.jahia.services.pages.JahiaPageService; 44 import org.jahia.services.sites.JahiaSite; 45 import org.jahia.services.sites.JahiaSitesService; 46 47 48 60 public class ManagePages 61 { 62 private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; 63 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 64 private JahiaSite site; 65 66 67 68 76 public ManagePages( HttpServletRequest request, 77 HttpServletResponse response, 78 HttpSession session ) 79 throws Throwable 80 { 81 site = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); 83 if(site==null) { 84 JahiaSitesService sitesService = ServicesRegistry.getInstance().getJahiaSitesService(); 85 site = sitesService.getSite( 0 ); 86 session.setAttribute( ParamBean.SESSION_SITE, site ); 87 } 88 89 userRequestDispatcher( request, response, session ); 90 } 92 93 94 102 private void userRequestDispatcher( HttpServletRequest request, 103 HttpServletResponse response, 104 HttpSession session ) 105 throws Throwable 106 { 107 String operation = request.getParameter("sub"); 108 109 if(operation.equals("display")) { 110 displayPagesSettings( request, response, session ); 111 } else if(operation.equals("process")) { 112 processPagesSettings( request, response, session ); 113 } 114 } 116 117 118 129 private void displayPagesSettings( HttpServletRequest request, 130 HttpServletResponse response, 131 HttpSession session ) 132 throws IOException , ServletException 133 { 134 try { 135 136 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance(); 138 Vector allPagesIDVector = pageService.getPageIDsInSite(site.getID(), 139 org.jahia.services.pages.PageInfoInterface.TYPE_DIRECT); 140 141 Vector allPagesInfosVector = new Vector (); 143 Enumeration allPagesIDEnumeration = allPagesIDVector.elements(); 144 while(allPagesIDEnumeration.hasMoreElements()) { 145 Integer pageID = (Integer ) allPagesIDEnumeration.nextElement(); 146 try { 147 ContentPage contentPage = ContentPage.getPage(pageID.intValue()); 148 if ( contentPage != null ){ 149 allPagesInfosVector.add (contentPage); 150 } 151 } catch (JahiaTemplateNotFoundException jtnfe) { 152 } 153 } 154 155 Integer homePageID = new Integer ( site.getHomePageID() ); 157 158 Integer basePageID = (Integer ) request.getAttribute(CLASS_NAME + "basePageID"); 160 Integer baseTemplateID = (Integer ) request.getAttribute(CLASS_NAME + "baseTemplateID"); 161 162 Enumeration allTemplatesEnumeration = ServicesRegistry.getInstance().getJahiaPageTemplateService().getPageTemplates (site.getID(), true); 164 165 if(basePageID == null) { basePageID = new Integer (0); } 167 if(baseTemplateID == null) { baseTemplateID = new Integer (0); } 168 if(homePageID == null) { homePageID = new Integer (0); } 169 170 request.setAttribute("homePageID", homePageID); 172 request.setAttribute("basePageID", basePageID); 173 request.setAttribute("baseTemplateID", baseTemplateID); 174 request.setAttribute("allTemplatesEnumeration", allTemplatesEnumeration); 175 request.setAttribute("allPagesInfosEnumeration", allPagesInfosVector.elements()); 176 177 JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "pages_settings.jsp" ); 178 179 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 181 ParamBean jParams = null; 182 if (jData != null) { 183 jParams = jData.params (); 184 } 185 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", 186 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 187 jParams, jParams.getLocale())); 188 } catch (JahiaException je) { 189 } 190 } 192 193 194 205 protected void processPagesSettings( HttpServletRequest request, 206 HttpServletResponse response, 207 HttpSession session ) 208 throws IOException , ServletException 209 { 210 int idPage = 0; 211 int idTemplate = 0; 212 JahiaPage page = null; 213 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 214 ParamBean jParams = null; 215 if (jData != null) { 216 jParams = jData.params(); 217 } 218 219 try { 220 221 JahiaPageService pageServ = ServicesRegistry.getInstance() 222 .getJahiaPageService(); 223 224 if ( pageServ == null ){ 225 226 throw new JahiaException( "Unavailable Services", 227 "Unavailable Services", 228 JahiaException.SERVICE_ERROR, 229 JahiaException.ERROR_SEVERITY ); 230 } 231 232 233 String subAction = (String )request.getParameter("subaction"); 234 235 String idPageString = (String )request.getParameter("pageid").trim(); 237 238 try { 239 idPage = Integer.parseInt(idPageString); 240 if ( idPage != 0 ){ 241 page = pageServ.lookupPage(idPage); 242 if ( page != null ){ 243 244 JahiaPageDefinition pageDef = page.getPageTemplate(); 245 if ( pageDef != null ){ 246 idTemplate = pageDef.getID(); 247 } 248 } 249 } 250 } catch (NumberFormatException nfe) { 251 252 throw new JahiaException( "ManagePages", 253 "page not found", 254 JahiaException.DATA_ERROR, 255 JahiaException.ERROR_SEVERITY ); 256 } catch (JahiaTemplateNotFoundException jtnfe) { 258 } 261 262 263 264 if ( subAction.equals("save") ) { 265 266 if(idPageString.equals("0")) { 268 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.choicePage.label", 269 jParams, jParams.getLocale()); 270 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 271 idTemplate = 0; 272 } else if ( page!=null ) { 273 String idTemplateString = (String ) request.getParameter("templateid").trim(); 274 275 try { 276 idTemplate = Integer.parseInt(idTemplateString); 277 278 if ( idTemplate != 0 ){ 279 page.setPageTemplateID (idTemplate); 281 page.commitChanges (true); 282 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.changeUpdated.label", 283 jParams, jParams.getLocale()); 284 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 285 } else { 286 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.choiceTemplate.label", 287 jParams, jParams.getLocale()); 288 session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", dspMsg); 289 } 290 } catch (NumberFormatException nfe) { 291 292 throw new JahiaException( "ManagePages", 293 nfe.getMessage(), 294 JahiaException.DATA_ERROR, 295 JahiaException.ERROR_SEVERITY ); 296 297 } 298 } else { 299 300 throw new JahiaException( "ManagePages", 301 "Page not found [" + idPage +"]", 302 JahiaException.DATA_ERROR, 303 JahiaException.ERROR_SEVERITY ); 304 } 305 } 306 307 request.setAttribute(CLASS_NAME + "basePageID", new Integer (idPage)); 308 request.setAttribute(CLASS_NAME + "baseTemplateID", new Integer (idTemplate)); 309 displayPagesSettings( request, response, session ); 310 311 } catch ( JahiaException je ){ 312 String dspMsg = JahiaResourceBundle.getAdminResource("org.jahia.admin.JahiaDisplayMessage.requestProcessingError.label", 313 jParams, jParams.getLocale()); 314 request.setAttribute("jahiaDisplayMessage", dspMsg); 315 JahiaAdministration.doRedirect( request, 316 response, 317 session, 318 JSP_PATH + "menu.jsp" ); 319 } 320 321 322 } 324 325 } | Popular Tags |