📄 updatefield_engine.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//// EV 10.01.20001package org.jahia.engines.updatefield;import java.util.*; // HashMapimport javax.servlet.http.*; // HttpSessionimport org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.exceptions.JahiaForbiddenAccessException;import org.jahia.utils.*; // JahiaConsole, JahiaObjectToolimport org.jahia.data.*; // JahiaData, ConnectionTypesimport org.jahia.services.pages.JahiaPage;import org.jahia.data.fields.*; // JahiaField, FieldTypesimport org.jahia.params.*; // ParamBeanimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.engines.*; // JahiaEngine interfaceimport org.jahia.engines.shared.*; // SmallText, BigText, etc.import org.jahia.data.events.*; // JahiaEventimport org.jahia.engines.rights.*; // ViewRightsimport org.jahia.services.usermanager.*; // JahiaUserimport org.jahia.content.*;public class UpdateField_Engine implements JahiaEngine { private static final String CLASS_NAME = UpdateField_Engine.class.getName(); private static final String TEMPLATE_JSP = "update_field"; private static UpdateField_Engine theObject = null; private String engineName = "updatefield"; private EngineToolBox toolBox; /*** * constructor * AK 19.12.2000 * */ private UpdateField_Engine() { // JahiaConsole.println( "Engine", "***** Starting UpdateField Engine *****" ); toolBox = EngineToolBox.getInstance(); } // end constructor /*** * getInstance * AK 19.12.2000 * */ public static synchronized UpdateField_Engine getInstance() { if (theObject == null) { theObject = new UpdateField_Engine(); } return theObject; } // end getInstance /*** * authoriseRender * AK 19.12.2000 * */ public boolean authoriseRender( ParamBean jParams ) { return toolBox.authoriseRender( jParams ); } // end authoriseRender /*** * renderLink * AK 19.12.2000 * AK 04.01.2001 add the select parameter * MJ 21.03.2001 mode is now the first URL parameter * */ public String renderLink( ParamBean jParams, Object theObj ) throws JahiaException { JahiaField theField = (JahiaField) theObj; String params = ""; params += "?mode=display"; params += "&fid=" + theField.getID(); return jParams.composeEngineUrl( engineName, params ); } // end renderLink /*** * needsJahiaData * AK 19.12.2000 * */ public boolean needsJahiaData( ParamBean jParams ) { return false; } // end needsJahiaData /*** * handles the engine actions * * @param jParams a ParamBean object * @param jData a JahiaData object (not mandatory) * */ public void handleActions( ParamBean jParams, JahiaData jData ) throws JahiaException, JahiaSessionExpirationException, JahiaForbiddenAccessException { // initalizes the hashmap HashMap engineMap = initEngineMap( jParams ); // checks if the user has the right to display the engine JahiaField theField = (JahiaField)engineMap.get("theField"); JahiaUser theUser = jParams.getUser(); if (theField.checkAdminAccess(theUser,jParams.getSiteID())) { engineMap.put ("adminAccess", Boolean.TRUE); engineMap.put ("writeAccess", Boolean.TRUE); } else if (theField.checkWriteAccess(theUser,jParams.getSiteID())) { engineMap.put ("writeAccess", Boolean.TRUE); } if (engineMap.get ("writeAccess") != null) { processLastScreen( jParams, engineMap ); processCurrentScreen( jParams, engineMap ); } else { throw new JahiaForbiddenAccessException(); } // displays the screen toolBox.displayScreen( jParams, engineMap ); } // end handleActions /*** * processes the last screen sent by the user * * @param jParams a ParamBean object * */ public void processLastScreen( ParamBean jParams, HashMap engineMap ) throws JahiaException, JahiaForbiddenAccessException { JahiaConsole.println(CLASS_NAME+".processLastScreen","started"); JahiaField theField = (JahiaField) engineMap.get( "theField" ); // gets the last screen // lastscreen = edit, rights, logs String lastScreen = jParams.getRequest().getParameter( "lastscreen" ); if (lastScreen == null) { lastScreen = "edit"; } JahiaConsole.println(CLASS_NAME+".processLastScreen","lastscreen=" + lastScreen); // indicates to sub engines that we are processing last screen int mode = JahiaEngine.UPDATE_MODE; // dispatches to the appropriate sub engine if (lastScreen.equals( "edit" )) { if (!toolBox.processFieldTypes( jParams, mode, engineMap )) { // if there was an error, come back to last screen engineMap.put( "screen", lastScreen ); engineMap.put( "jspSource", TEMPLATE_JSP ); } } else if (lastScreen.equals("rightsMgmt")) { if (engineMap.get("adminAccess") != null) { ManageRights.getInstance().handleActions( jParams, mode, engineMap, theField.getAclID() ); } else { throw new JahiaForbiddenAccessException(); } } else if (lastScreen.equals("logs")) { if (engineMap.get("adminAccess") != null) { // ManageLogs_Engine.getInstance().handleActions( jParams, null ); } else { throw new JahiaForbiddenAccessException(); } } } // end processLastScreen /*** * prepares the screen requested by the user * * @param jParams a ParamBean object * */ public void processCurrentScreen( ParamBean jParams, HashMap engineMap ) throws JahiaException, JahiaForbiddenAccessException { JahiaConsole.println(CLASS_NAME+".processCurrentScreen","started"); // gets the current screen // screen = edit, rights, logs String theScreen = (String) engineMap.get( "screen" ); JahiaField theField = (JahiaField) engineMap.get( "theField" ); JahiaConsole.println(CLASS_NAME+".processCurrentScreen","screen=" + theScreen); // indicates to sub engines that we are processing last screen int mode = JahiaEngine.LOAD_MODE; // dispatches to the appropriate sub engine if (theScreen.equals( "edit" )) { toolBox.processFieldTypes( jParams, mode,engineMap ); } else if (theScreen.equals("logs")) { toolBox.loadLogData( jParams, JahiaObjectTool.FIELD_TYPE, engineMap ); } else if (theScreen.equals("rightsMgmt")) { if (engineMap.get("adminAccess") != null) { ManageRights.getInstance().handleActions( jParams, mode,engineMap, theField.getAclID() ); } else { throw new JahiaForbiddenAccessException(); } } else if (theScreen.equals("save") || theScreen.equals ("apply")) { mode = JahiaEngine.SAVE_MODE; toolBox.processFieldTypes( jParams,mode,engineMap ); if (engineMap.get("adminAccess") != null) { engineMap.put("logObjectType", Integer.toString(JahiaObjectTool.FIELD_TYPE)); engineMap.put("logObject", theField); //ViewRights.getInstance().handleActions( jParams, mode, engineMap, theField.getAclID() ); ManageRights.getInstance().handleActions(jParams, mode, engineMap, theField.getAclID()); } // since we have made modifications concerning this page, let's flush // the content cache for all the users and browsers as well as all // pages that display this containerList... Set fieldPageRefs = FieldXRefManager.getInstance(). getAbsoluteFieldPageIDs(jParams.getSiteKey(), theField.getDefinition().getName(), theField.getPageID()); if (fieldPageRefs != null) { Iterator pageRefIDs = fieldPageRefs.iterator(); while (pageRefIDs.hasNext()) { Integer curPageID = (Integer) pageRefIDs.next(); ServicesRegistry.getInstance().getCacheServerService(). removeEntry(curPageID.toString()); } } else { JahiaConsole.println(CLASS_NAME+".processCurrentScreen", "Why is cross ref list empty ?"); } // since we have made modifications concerning this page, let's flush // the content cache for all the users and browsers... ServicesRegistry.getInstance().getCacheServerService().removeEntry(Integer.toString(jParams.getPageID())); JahiaEvent theEvent = new JahiaEvent( this, jParams, theField ); ServicesRegistry.getInstance().getJahiaEventService().fireUpdateField( theEvent ); if (theScreen.equals ("apply")) { engineMap.put( "screen", (String)jParams.getRequest().getParameter("lastscreen")); } JahiaConsole.println(CLASS_NAME+".processCurrentScreen", "Changes applied and saved !"); } } // end processCurrentScreen /*** * inits the engine map * * @param jParams a ParamBean object (with request and response) * @return a HashMap object containing all the basic values needed by an engine * */ private HashMap initEngineMap (ParamBean jParams) throws JahiaException, JahiaSessionExpirationException { JahiaConsole.println(CLASS_NAME+".initEngineMap","started"); HashMap engineMap = new HashMap(); JahiaField theField; // gets session values //HttpSession theSession = jParams.getRequest().getSession( true ); HttpSession theSession = jParams.getSession (); // tries to find if this is the first screen generated by the engine String theScreen = jParams.getRequest().getParameter( "screen" ); JahiaConsole.println(CLASS_NAME+".initEngineMap", "theScreen=" + theScreen); if (theScreen != null) { // if no, load the field value from the session engineMap = (HashMap) theSession.getAttribute( "jahia_session_engineMap" ); /////////////////////////////////////////////////////////////////////////////////////// // FIXME -Fulco- // // This is a quick hack, engineMap should not be null if the session didn't // expired. Maybe there are other cases where the engineMap can be null, I didn't // checked them at all. /////////////////////////////////////////////////////////////////////////////////////// if (engineMap == null) { throw new JahiaSessionExpirationException (); } theField = (JahiaField) engineMap.get( "theField" ); //if (theField == null) { // int fieldID = jParams.getFieldID(); // theField = ServicesRegistry.getInstance().getJahiaFieldService().loadField( fieldID, jParams ); // engineMap.put( "theField", theField ); // } } else { // first screen generated by engine -> init sessions int fieldID = jParams.getFieldID(); theField = ServicesRegistry.getInstance().getJahiaFieldService().loadField( fieldID, jParams ); theScreen = "edit"; // init session engineMap.put( "theField", theField ); engineMap.put( "isSelectedField", new Boolean(true) ); engineMap.put( "jParams", jParams ); } engineMap.put( "renderType", new Integer(JahiaEngine.RENDERTYPE_FORWARD) ); engineMap.put( "engineName", engineName ); engineMap.put( "engineUrl", jParams.composeEngineUrl( "updatefield", "?fid=" + theField.getID() ) ); engineMap.put( "updateField", "updateField"); theSession.setAttribute( "jahia_session_engineMap", engineMap ); // sets screen engineMap.put( "screen", theScreen ); if (theScreen.equals ("save")) { engineMap.put( "jspSource", "close" ); } else if (theScreen.equals ("apply")) { engineMap.put( "jspSource", "apply" ); } else if (theScreen.equals ("cancel")) { engineMap.put( "jspSource", "close" ); } else { engineMap.put( "jspSource", TEMPLATE_JSP ); } // sets engineMap for JSPs jParams.getRequest().setAttribute( "engineTitle", "Update Field" ); jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", engineMap ); return engineMap; } // end initEngineMap} // end UpdateField_Engine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -