📄 sitemap_engine.java
字号:
// $Id: SiteMap_Engine.java,v 1.4 2002/11/12 16:41:38 shuber Exp $//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// SiteMap_Engine// MJ 18.07.2001// NK 08.01.2002 Extends jsp output file customization.//// getInstance()// authoriseRender()// renderLink()// needsJahiaData()// handleActions()//package org.jahia.engines.sitemap;import java.util.*; // HashMapimport java.io.*; // Fileimport javax.servlet.http.*; // HttpSessionimport org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.data.*; // JahiaData, ConnectionTypesimport org.jahia.params.*; // ParamBeanimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.engines.*; // JahiaEngine interfaceimport org.jahia.data.events.*; // JahiaEventimport org.jahia.services.pages.*; // JahiaPage, PageLoadFlagsimport org.jahia.tools.*; // Tools, Pairimport org.jahia.tools.tree.*; // GenericTree, Node, ImageDescriptor/** * Manage a tree view of a Site Map for a Jahia Site. * A JSP view is uses to format the output. * This implementation builds upon the first version by J閞鬽e Bedat and adds extensive * use of the GenericTree library by St閜hane Boury. * * Copyright: Copyright (c) 2002 * Company: Jahia Ltd * * @author Mikha雔 Janson * @version 2.0 */public class SiteMap_Engine implements JahiaEngine { private static final String SITEMAP_JSP_NAME = "sitemap.jsp"; private static final int DEFAULT_LEVELS = 5; private static SiteMap_Engine theObject = null; private String engineName = "sitemap"; private String siteKey; private EngineToolBox toolBox; private ServicesRegistry sReg; private JahiaTreeViewService tSrv; private GenericTree topTree; /** * The default output file is the file in the engine directory. * This file is used only when then page is null or not available. */ private String outputFile = "/jsp/jahia/engines/sitemap/sitemap.jsp"; /*** * constructor * */ private SiteMap_Engine() { // JahiaConsole.println( "Engine", "***** Starting Site Map Engine *****" ); toolBox = EngineToolBox.getInstance(); sReg = ServicesRegistry.getInstance(); tSrv = sReg.getJahiaTreeViewService(); } // end constructor /*** * returns a single instance of the object * */ public static synchronized SiteMap_Engine getInstance() { if (theObject == null) { theObject = new SiteMap_Engine(); } return theObject; } // end getInstance /*** * authorises engine render * */ public boolean authoriseRender( ParamBean jParams ) { return true; } // end authoriseRender /*** * renders link to pop-up window * */ public String renderLink( ParamBean jParams, Object theObj ) throws JahiaException { String theUrl = jParams.composeEngineUrl( engineName, "" ); if (theObj != null) theUrl = theUrl + theObj; return jParams.getResponse().encodeURL(theUrl); } // end renderLink /*** * specifies if the engine needs the JahiaData object * * @param the ParamBean object */ public boolean needsJahiaData( ParamBean jParams ) { return true; } // end needsJahiaData /*** * handles the engine actions * * @param jParams a ParamBean object * @param jData a JahiaData object * */ public void handleActions( ParamBean jParams, JahiaData jData ) throws JahiaException { topTree = null; // initalizes the hashmap HashMap engineMap = initEngineMap (jParams, jData); process( jParams, jData, engineMap ); // displays the screen toolBox.displayScreen( jParams, engineMap ); } // end handleActions /*** * Retrieve the engine context or build a new one if none was found. * * @param jParams a ParamBean object * @param jData a JahiaData object * @return a HashMap object containing all the basic values * needed by an engine */ private HashMap initEngineMap( ParamBean jParams, JahiaData jData ) throws JahiaException { HashMap engineMap = (HashMap)jParams.getRequest().getAttribute( "engineMap" ); if (engineMap == null) { engineMap = new HashMap(); // check if a Site Map template exists in the template // directory, else uses the standard template found in the // jsp/engines directory String theTemplate = ""; String fileName = null; String iconsPath = null; if ( (jParams!=null) ) { if ( (jParams.getPage()!=null) && (jParams.getPage().getPageTemplate()!=null) ){ fileName = jParams.getPage().getPageTemplate().getSourcePath(); if (fileName.lastIndexOf ("/") != -1) { fileName = fileName.substring (0, fileName.lastIndexOf("/")+1) + SITEMAP_JSP_NAME; iconsPath = fileName.substring(0, fileName.lastIndexOf("/")+1) + "sitemap.properties"; iconsPath = jParams.getContext().getRealPath("/") + iconsPath; } } else { // use the default jsp out put file JahiaConsole.println("SiteMap_Engine.initEngineMap","the page is null"); fileName = getOutputFile(); iconsPath = fileName.substring(0, fileName.lastIndexOf("/")+1) + "sitemap.properties"; iconsPath = jParams.getContext().getRealPath("/") + iconsPath; } theTemplate = fileName; JahiaConsole.println("SiteMap_Engine.initEngineMap","output jsp =" + fileName); engineMap.put( "engineOutputFile", theTemplate ); engineMap.put( "jParams", jParams ); engineMap.put( "jData", jData ); engineMap.put( "renderType", new Integer(JahiaEngine.RENDERTYPE_FORWARD) ); engineMap.put( "engineName", engineName ); engineMap.put( "engineUrl", jParams.composeEngineUrl( engineName, "" ) ); engineMap.put( "jahiaBuild", new Integer(jParams.settings().getBuildNumber())); engineMap.put( "javascriptUrl", jParams.settings().getJsHttpPath() ); engineMap.put( "iconsPath", iconsPath); } } return engineMap; } /*** * Prepare a GUI for display to the user. * * @param jParams a ParamBean object * @param jData a JahiaData object * @param engineMap a partially populated engine context * */ private void process( ParamBean jParams, JahiaData jData, HashMap engineMap ) throws JahiaException { int levels = DEFAULT_LEVELS; int flag = PageLoadFlags.DIRECT; boolean changed = false; if (jParams.getRequest().getParameter("levels") != null ) { String changedStr = jParams.getRequest().getParameter( "changed" ); if ((changedStr != null) && (changedStr.equals("true"))) { changed = true; } String levelsStr = jParams.getRequest().getParameter( "levels" ); try { levels = Integer.parseInt(levelsStr); levels = (levels < 1) ? 1 : levels ; } catch (NumberFormatException nfe) { JahiaConsole.println("SiteMap_Engine", nfe.getMessage()); } } if (jParams.getRequest().getParameter("flag") != null ) { String flagStr = jParams.getRequest().getParameter( "flag" ); try { flag = Integer.parseInt(flagStr); } catch (NumberFormatException nfe) { JahiaConsole.println("SiteMap_Engine", nfe.getMessage()); } } engineMap.put("levels", new Integer(levels)); engineMap.put("flag", new Integer(flag)); // get tree from session or build it if none found... // topTree = changed ? null : (GenericTree) jParams.getSession().getAttribute("treeData") ; if (topTree == null) { // find home page JahiaPage homePage = jData.gui().getHomePage(); //JahiaPage homePage = jParams.getSite().getHomePage(); // draws home page's childs, recursive if (homePage != null) { topTree = tSrv.buildTree(homePage.getID(), flag, levels, jParams); } } String modif = jParams.getRequest().getParameter( "modif" ); String pageID = jParams.getRequest().getParameter( "pageid" ); if ((modif != null) && (pageID != null)) { try { // topTree = (GenericTree) jParams.getSession().getAttribute("treeData_" + jParams.getSite().getSiteKey()); if (topTree != null) { GenericTree subTree = topTree.getSubTree(Integer.parseInt(pageID), "org.jahia.services.pages.JahiaTreeViewPageWrapper"); if (subTree != null) { Node node = subTree.getRoot(); if (node != null) { JahiaTreeViewPageWrapper pageWrapper = (JahiaTreeViewPageWrapper) node.getData(); if (modif.equals("expand")) { pageWrapper.expand(); if(subTree.getChildren().size() == 0) { topTree = tSrv.extendTree(Integer.parseInt(pageID), topTree, flag, 2, jParams); } } else if (modif.equals("collapse")) { pageWrapper.collapse(); } } } } } catch (NumberFormatException nfe) { JahiaConsole.println("SiteMap Engine", nfe.getMessage()); } } engineMap .put ( "treeData", topTree ); // jParams.getSession().setAttribute( "treeData_" + jParams.getSite().getSiteKey(), topTree ); jParams.getRequest().setAttribute( "engineMap", engineMap ); jParams.getRequest().setAttribute( "jData", jData ); } // end processScreen //-------------------------------------------------------------------------- /** * When the page is null, you should explicitely provide an output jsp file * A full qualified path is like : jsp/jahia/administration/sitemap.jsp * * @param String the output file * @author Khue NGuyen */ public void setOutputFile ( String outputFile ){ this.outputFile = outputFile; } //-------------------------------------------------------------------------- /** * Return the jsp output file that will be used if the page returned by jParams * is null or not available. * * @param String the output file * @author Khue NGuyen */ public String getOutputFile (){ return outputFile; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -