📄 managepages.java
字号:
// $Id: ManagePages.java,v 1.4 2002/06/07 13:50:30 pmartin Exp $//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// ManagePages//// 01.04.2001 AK added in jahia.// 23.05.2001 NK Lot of change mainly to display the page's template when the user choose another page in the page selectbox.// 13.16.2001 MJ Avoid crash when pointing to a page referencing a deleted template.//package org.jahia.admin.pages;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import org.jahia.bin.*;import org.jahia.utils.*;import org.jahia.registries.*;import org.jahia.services.pages.*;import org.jahia.exceptions.*;import org.jahia.services.sites.*;import org.jahia.params.*;/** * desc: This class is used by the administration to manage * pages settings. For each page on the site, you can choose wich template * you want. It's a very good tool when you use the template swapping and * the template doesn't work correctly. * * Copyright: Copyright (c) 2002 * Company: Jahia Ltd * * @author Alexandre Kraft * @version 1.0 */public class ManagePages{ private static final String CLASS_NAME = JahiaAdministration.CLASS_NAME; private static final String JSP_PATH = JahiaAdministration.JSP_PATH; private JahiaSite site; /** * Default constructor. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ public ManagePages( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws Throwable { // get the current website. get the jahiaserver if it's null... site = (JahiaSite) session.getAttribute( ParamBean.SESSION_SITE ); if(site==null) { JahiaSitesService sitesService = ServicesRegistry.getInstance().getJahiaSitesService(); site = sitesService.getSite( 0 ); session.setAttribute( ParamBean.SESSION_SITE, site ); } userRequestDispatcher( request, response, session ); } // end constructor /** * This method is used like a dispatcher for user requests. * @author Alexandre Kraft * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void userRequestDispatcher( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws Throwable { String operation = request.getParameter("sub"); if(operation.equals("display")) { displayPagesSettings( request, response, session ); } else if(operation.equals("process")) { processPagesSettings( request, response, session ); } } // userRequestDispatcher /** * Display the pages settings view, using doRedirect(). It's on this * page where you can change the template for each page on your Jahia * portal. * @author Alexandre Kraft * @author Khue Nguyen * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ private void displayPagesSettings( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { try { // get all pages id... JahiaPageBaseService pageService = JahiaPageBaseService.getInstance(); Vector allPagesIDVector = pageService.getPageIDsInSite(site.getID(), org.jahia.services.pages.PageInfoInterface.TYPE_DIRECT); // get all pages infos... Vector allPagesInfosVector = new Vector(); Enumeration allPagesIDEnumeration = allPagesIDVector.elements(); while(allPagesIDEnumeration.hasMoreElements()) { Integer pageID = (Integer) allPagesIDEnumeration.nextElement(); try { allPagesInfosVector.add ((JahiaPage)pageService.lookupPageWhitoutTemplates (pageID.intValue())); } catch (JahiaTemplateNotFoundException jtnfe) { } } // get homepage id for the current site... Integer homePageID = new Integer( site.getHomePageID() ); // retrieve previous form values... Integer basePageID = (Integer) request.getAttribute(CLASS_NAME + "basePageID"); Integer baseTemplateID = (Integer) request.getAttribute(CLASS_NAME + "baseTemplateID"); // get only visible templates Enumeration allTemplatesEnumeration = ServicesRegistry.getInstance().getJahiaPageTemplateService().getPageTemplates (site.getID(), true); // set default values... if(basePageID == null) { basePageID = new Integer(0); } if(baseTemplateID == null) { baseTemplateID = new Integer(0); } if(homePageID == null) { homePageID = new Integer(0); } // set all pages infos into an enumeration and redirect... request.setAttribute("homePageID", homePageID); request.setAttribute("basePageID", basePageID); request.setAttribute("baseTemplateID", baseTemplateID); request.setAttribute("allTemplatesEnumeration", allTemplatesEnumeration); request.setAttribute("allPagesInfosEnumeration", allPagesInfosVector.elements()); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "pages_settings.jsp" ); // reset message... session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", Jahia.COPYRIGHT); } catch (JahiaException je) { } } // end displayPagesSettings /** * Process and determine which template the user want for wich * page. It's a simple process, but check if the user has choosed * a page and a template in select boxs. * @author Alexandre Kraft * @author Khue Nguyen * * @param request Servlet request. * @param response Servlet response. * @param session Servlet session for the current user. */ protected void processPagesSettings( HttpServletRequest request, HttpServletResponse response, HttpSession session ) throws IOException, ServletException { int idPage = 0; int idTemplate = 0; JahiaPage page = null; try { JahiaPageService pageServ = ServicesRegistry.getInstance() .getJahiaPageService(); if ( pageServ == null ){ throw new JahiaException( "Unavailable Services", "Unavailable Services", JahiaException.SERVICE_ERROR, JahiaException.ERROR ); } String subAction = (String)request.getParameter("subaction"); // get form values... String idPageString = (String)request.getParameter("pageid").trim(); try { idPage = Integer.parseInt(idPageString); if ( idPage != 0 ){ page = pageServ.lookupPage(idPage); if ( page != null ){ JahiaPageDefinition pageDef = page.getPageTemplate(); if ( pageDef != null ){ idTemplate = pageDef.getID(); } } } } catch (NumberFormatException nfe) { throw new JahiaException( "ManagePages", "page not found", JahiaException.DATA_ERROR, JahiaException.ERROR ); // Mik - 13.06.2001 } catch (JahiaTemplateNotFoundException jtnfe) { // idTemplate remains 0 ... the template referenced by this page has been deleted // so we want to set a new template. } if ( subAction.equals("save") ) { // check form validity... if(idPageString.equals("0")) { session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Please choose a page in the upper box."); idTemplate = 0; } else if ( page!=null ) { String idTemplateString = (String) request.getParameter("templateid").trim(); try { idTemplate = Integer.parseInt(idTemplateString); if ( idTemplate != 0 ){ // set new settings for this JahiaPage... page.setPageTemplateID (idTemplate); page.commitChanges (true); session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Change successfully updated."); } else { session.setAttribute(CLASS_NAME + "jahiaDisplayMessage", "Please choose a template first."); } } catch (NumberFormatException nfe) { throw new JahiaException( "ManagePages", nfe.getMessage(), JahiaException.DATA_ERROR, JahiaException.ERROR ); } } else { throw new JahiaException( "ManagePages", "Page not found [" + idPage +"]", JahiaException.DATA_ERROR, JahiaException.ERROR ); } } request.setAttribute(CLASS_NAME + "basePageID", new Integer(idPage)); request.setAttribute(CLASS_NAME + "baseTemplateID", new Integer(idTemplate)); displayPagesSettings( request, response, session ); } catch ( JahiaException je ){ request.setAttribute("jahiaDisplayMessage", "An error occured while processing your request"); JahiaAdministration.doRedirect( request, response, session, JSP_PATH + "menu.jsp" ); } } // end processPagesSettings} // end ManagePages
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -