📄 addcontainer_engine.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// AddContainer_Engine// EV 10.01.2001// NK 05.02.2002 Added Multiple fields (JahiaSimpleField) edit at once support// NK 05.02.2002 Version 2.0 Multiple field edit + customisable field ( read/write permission check )////// getInstance()// authoriseRender()// renderLink()// needsJahiaData()// handleActions()//package org.jahia.engines.addcontainer;import java.util.*; // HashMapimport javax.servlet.http.*; // HttpSessionimport org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.utils.*; // JahiaConsoleimport org.jahia.data.*; // JahiaDataimport org.jahia.services.acl.*;import org.jahia.services.pages.JahiaPage;import org.jahia.data.fields.*; // JahiaField, FieldTypesimport org.jahia.data.containers.*; // JahiaContainerimport org.jahia.params.*; // ParamBeanimport org.jahia.registries.*; // ServicesRegistryimport org.jahia.engines.*; // JahiaEngine interfaceimport org.jahia.engines.copytree.*; // CopyTree_Engineimport 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.*;import org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.exceptions.JahiaForbiddenAccessException;/** * Display the popup that let the user add a new container. * * @author EV * @author NK * @version 2.0 */public class AddContainer_Engine implements JahiaEngine { private static final String CLASS_NAME = AddContainer_Engine.class.getName(); private static final String TEMPLATE_JSP = "add_container"; private static AddContainer_Engine theObject = null; private String engineName = "addcontainer"; private EngineToolBox toolBox; private boolean flagStayOnSameField = false; /*** * constructor * */ private AddContainer_Engine() { //JahiaConsole.println( "Engine", // "***** Starting AddContainer Engine *****" ); toolBox = EngineToolBox.getInstance(); } // end constructor /*** * returns a single instance of the object * */ public static synchronized AddContainer_Engine getInstance() { if (theObject == null) { theObject = new AddContainer_Engine(); } return theObject; } // end getInstance /*** * authoriseRender * */ public boolean authoriseRender( ParamBean jParams ) { return toolBox.authoriseRender( jParams ); } // end authoriseRender /*** * renderLink * */ public String renderLink( ParamBean jParams, Object theObj ) throws JahiaException { JahiaContainerList theContainerList = (JahiaContainerList) theObj; String params = ""; params += "?mode=display"; params += "&clistid=" + theContainerList.getID(); params += "&cdefid=" + theContainerList.getctndefid(); params += "&cpid=" + theContainerList.getPageID(); params += "&cparentid=" + theContainerList.getParentEntryID(); return jParams.composeEngineUrl( engineName, params ); } // end renderLink /*** * needsJahiaData * */ 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 { toDebug("=== AddContainer_Engine :: handleActions ==="); // initalizes the hashmap HashMap engineMap = initEngineMap (jParams); String theScreen = (String) engineMap.get( "screen" ); // init the flag flagStayOnSameField = false; // checks if the user has the right to display the engine JahiaUser theUser = jParams.getUser(); JahiaContainer theContainer = (JahiaContainer)engineMap.get("theContainer"); if (theContainer.getListID() != 0) { JahiaContainerList theContainerList = ServicesRegistry.getInstance(). getJahiaContainersService().loadContainerListInfo( theContainer.getListID() ); if (theContainerList.checkAdminAccess (theUser, jParams.getSiteID())) { engineMap.put ("adminAccess", Boolean.TRUE); engineMap.put ("writeAccess", Boolean.TRUE); } else if (theContainerList.checkWriteAccess (theUser,jParams.getSiteID())) { engineMap.put ("writeAccess", Boolean.TRUE); } } else { JahiaPage thePage = jParams.getPage(); if (thePage.checkAdminAccess (theUser)) { engineMap.put( "adminAccess", Boolean.TRUE ); engineMap.put( "writeAccess", Boolean.TRUE ); } else if (thePage.checkWriteAccess (theUser)) { 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 { toDebug("=== AddContainer_Engine :: processLastScreen ==="); // gets the last screen // lastscreen = edit, rights, logs String lastScreen = jParams.getRequest().getParameter( "lastscreen" ); boolean lastScreenWasNull = false; if (lastScreen == null) { lastScreen = "edit"; //lastScreen = ""; // reset session var jParams.getSession().removeAttribute("UpdateContainer"); } // indicates to sub engines that we are processing last screen int mode = JahiaEngine.UPDATE_MODE; // Sets the last field JahiaField theField = null; JahiaContainer theContainer = (JahiaContainer) engineMap.get( "theContainer" ); String lastFieldIDStr = jParams.getRequest().getParameter( "lastfid" ); if (lastScreen.equals( "edit" )) { int lastFieldID = -1; try { lastFieldID = Integer.parseInt( lastFieldIDStr ); } catch (NumberFormatException nfe) { String reload = (String) jParams.getRequest().getParameter("reload"); if ( (reload != null) && reload.equals("true") ){ JahiaField lastField = (JahiaField)jParams.getRequest().getAttribute("lastField"); if ( lastField != null ){ lastFieldID = lastField.getID(); } } else { return; } } // get the lists Vector neighbourSimpleFields = getNeighbourSimpleFields(theContainer,lastFieldID,true,(HashMap)engineMap.get("ctnListVisibleFields")); if ( neighbourSimpleFields.size()<=0 ){ // single field edit, we add the current field to the vector neighbourSimpleFields.add(new Integer(lastFieldID)); } // dispatches to the appropriate sub engine int size = neighbourSimpleFields.size(); Integer I = null; for ( int i=0 ; i<size ; i++ ){ I = (Integer) neighbourSimpleFields.get(i); theField = theContainer.getField(I.intValue()); if ( theField != null ){ JahiaConsole.println(CLASS_NAME+".processLastScreen", "Update container field " + theField.getDefinition().getName() + "..." ); engineMap.put( "theField", theField ); engineMap.put( "isSelectedField", new Boolean(false) ); boolean doUpdate = false; if ( theContainer.getListID()!=0 ){ JahiaBaseACL acl = JahiaEngineTools.getCtnListFieldACL((HashMap)engineMap.get("ctnListFieldAcls"), theField.getID());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -