📄 copytree_engine.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// CopyTree_Engine// AK 14.12.2000 original implementation// MJ 04.04.2001 adapted for copy tree// NK 16.01.2002 Adapted as a page chooser engine for use in Jahia Administration too// NK 31.01.2002 Session conflict when switching between site in JahiaAdmin corrected.// NK 31.01.2002 Yes! expanding the tree up to the source page when needed ok !//// getInstance()// authoriseRender()// renderLink()// needsJahiaData()// handleActions()//package org.jahia.engines.copytree;import java.util.*; // HashMap, HashTable, Vector, ArrayListimport javax.servlet.http.*; // HttpSessionimport org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.data.*; // JahiaData, ConnectionTypesimport org.jahia.data.fields.*;import org.jahia.data.files.*;import org.jahia.data.containers.*;import org.jahia.params.*; // ParamBeanimport org.jahia.services.pages.*; // JahiaPage, PageLoadFlagsimport org.jahia.services.containers.*; // JahiaContainersServiceimport org.jahia.services.fields.*; // JahiaFieldServiceimport org.jahia.services.acl.*; // JahiaBaseACL, JahiaAbstractACL, JahiaACLManagerServiceimport org.jahia.services.usermanager.*; // JahiaUserimport org.jahia.services.sites.*; // JahiaSiteimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.engines.*; // JahiaEngine interfaceimport org.jahia.data.events.*; // JahiaEventimport org.jahia.exceptions.*;import org.jahia.tools.tree.*; // GenericTree, Node/** * Manage GUI for tree manipulation. * * @author Mikhael Janson */public class CopyTree_Engine implements JahiaEngine { private static final String CLASS_NAME = CopyTree_Engine.class.getName(); /** * the selected page id session name */ public static final String SOURCEPAGE_ID = "org.jahia.engines.CopyTree_Engine.sourcePageID"; public static final String ENGINE_LAUNCHER_NAME = "org.jahia.engines.CopyTree_Engine.engineLauncherName"; private static final String ATTRIBUTE_CLASS = "org.jahia.engines.CopyTree_Engine.engineMap"; private static final String CHOOSESOURCE_JSP = "copy_tree_choose_source"; private static final String PREVIEW_JSP = "copy_tree_preview"; private static final String CLOSE_JSP = "copy_tree_close"; public static final String COPY_OPERATION = "copy"; public static final String MOVE_OPERATION = "move"; public static final String LINK_OPERATION = "link"; public static final String CHOOSE_OPERATION = "choose"; private static CopyTree_Engine theObject = null; private String engineName = "copytree"; private EngineToolBox toolBox; private ServicesRegistry sReg; private JahiaPageService pSrv; private JahiaTreeViewService tSrv; private JahiaContainersService ctnSrv; private JahiaFieldService fldSrv; /*** * constructor * AK 14.12.2000 * */ private CopyTree_Engine() { // JahiaConsole.println( "Engine", "***** Starting Copy Tree Engine *****" ); sReg = ServicesRegistry.getInstance(); pSrv = sReg.getJahiaPageService(); tSrv = sReg.getJahiaTreeViewService(); ctnSrv = sReg.getJahiaContainersService(); fldSrv = sReg.getJahiaFieldService(); toolBox = EngineToolBox.getInstance(); } // end constructor /*** * returns a single instance of the object * AK 14.12.2000 * */ public static synchronized CopyTree_Engine getInstance() { if (theObject == null) { theObject = new CopyTree_Engine(); } return theObject; } // end getInstance /*** * authorises engine render * AK 14.12.2000 * */ public boolean authoriseRender( ParamBean jParams ) { return true; } // end authoriseRender /*** * renders link to pop-up window * AK 14.12.2000 * */ public String renderLink( ParamBean jParams, Object theObj ) throws JahiaException { String params = ""; params += "?mode=display"; return jParams.composeEngineUrl( engineName, params ); } // end renderLink /*** * specifies if the engine needs the JahiaData object * */ public boolean needsJahiaData( ParamBean jParams ) { return true; } // end needsJahiaData /*** * inits the engine map * * @param jData theJahiaData object * (with request and response) * @return the EngineMap * */ private HashMap initEngineMap( JahiaData jData ) throws JahiaException, JahiaSessionExpirationException, JahiaForbiddenAccessException { HashMap engineMap = new HashMap(); ParamBean jParams = jData.params(); String theScreen = jParams.getRequest().getParameter ("screen"); // gets session values HttpSession theSession = jParams.getSession (); if (theScreen != null) { engineMap = (HashMap) theSession.getAttribute( ATTRIBUTE_CLASS ); if (engineMap == null) { throw new JahiaSessionExpirationException (); } } else { String operation = jParams.getRequest().getParameter ("operation"); if(operation == null) { try { operation = (String)((HashMap)theSession.getAttribute( ATTRIBUTE_CLASS )) .get("operation"); } catch(Exception e) { operation = CHOOSE_OPERATION; } } toDebug(">> CopyTree_Engine :: initEngineMap :: operation ["+operation+"]"); JahiaPage thePage = jParams.getPage(); int homePageID = ((JahiaSite)jParams.getSession().getAttribute(ParamBean.SESSION_SITE)).getHomePageID(); if ( thePage == null ){ thePage = pSrv.lookupPage(homePageID,jParams); } toDebug(">> CopyTree_Engine :: initEngineMap :: home page ["+thePage.getTitle()+"]"); // In case we have problems finding a targetPageID in the session reference // to a container, set it to a default value of the current page ID. int targetPageID = thePage.getID(); // If we've got a container (e.g. called by AddContainer_Engine) // try to set the targetPageID to the one the container is linked to HashMap sessionMap = (HashMap) theSession.getAttribute( "jahia_session_engineMap" ); if (sessionMap != null) { JahiaContainer ctn = (JahiaContainer) sessionMap.get( "theContainer" ); if (ctn != null) { targetPageID = ctn.getPageID(); } } theScreen = "source"; String fieldName = jParams.getRequest().getParameter ("fname"); // init engine map engineMap.put ("fieldName", fieldName); engineMap.put ("jData", jData); engineMap.put ("thePage", thePage); engineMap.put ("tslMap", new HashMap()); engineMap.put ("revTslMap", new HashMap()); engineMap.put ("homePageID", new Integer(homePageID)); engineMap.put ("targetPageID", new Integer(targetPageID)); engineMap.put ("maxLevels", new Integer(3)); engineMap.put ("renderType", new Integer(JahiaEngine.RENDERTYPE_FORWARD)); engineMap.put ("engineName", engineName); engineMap.put ("engineUrl", jParams.composeEngineUrl( engineName, "" )); engineMap.put ("errors", new ArrayList()); engineMap.put ("theUser", jParams.getUser()); HashMap prevEngineMap = (HashMap) theSession.getAttribute( ATTRIBUTE_CLASS ); if(prevEngineMap != null) { // NK : Multisite session conflict check. // we need to check if the site has changed by checking the home page id Integer prevHomepageID = (Integer) prevEngineMap.get("homePageID"); if ( (prevHomepageID != null) && (prevHomepageID.intValue() == homePageID )){ engineMap = prevEngineMap; } } engineMap.put ("operation", operation); // get the name of the engine Launcher String value = jParams.getRequest().getParameter ("enginelauncher"); if ( value != null ) engineMap.put(ENGINE_LAUNCHER_NAME,value); // get the initial source page value = jParams.getRequest().getParameter ("sourcepageid"); if ( value != null ){ int i = Integer.parseInt(value); engineMap.put(SOURCEPAGE_ID,new Integer(i)); } else { engineMap.put(SOURCEPAGE_ID,new Integer(-1)); } } theSession.setAttribute( ATTRIBUTE_CLASS, engineMap ); // sets screen engineMap.put ("screen", theScreen); toDebug(">> CopyTree_Engine :: initEngineMap :: theScreen ["+theScreen+"]"); if (theScreen.equals ("preview")) { engineMap.put( "jspSource", PREVIEW_JSP ); } else if (theScreen.equals ("save")) { engineMap.put( "jspSource", CLOSE_JSP ); } else if (theScreen.equals ("cancel")) { engineMap.put( "jspSource", CLOSE_JSP ); // default is to choose the source } else { engineMap.put( "jspSource", CHOOSESOURCE_JSP ); } // sets engineMap for JSPs jParams.getRequest().setAttribute( "engineTitle", "Tree Engine" ); jParams.getRequest().setAttribute( "engineMap", engineMap ); return engineMap; } // end initEngineMap /*** * handles the engine actions * AK 04.01.2001 * * @param jParams a ParamBean object * @param jData a JahiaData object (not mandatory) * */ public void handleActions (ParamBean jParams, JahiaData jData) throws JahiaException, JahiaUpdateLockException,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -