📄 applications_engine.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////// Applications_Engine// NK 10.02.2001// NK 19.04.2001 Lots of changes to work with new user/group and in multi site// NK 02.05.2001 bug session corrected//package org.jahia.engines.applications;import java.io.*;import java.util.*; // HashMapimport java.security.acl.Group;import java.security.Principal;import javax.servlet.*; // ServletContextimport javax.servlet.http.*; // HttpServletRequestimport org.jahia.exceptions.*; // JahiaExceptionimport org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.utils.*; // JahiaConsoleimport org.jahia.data.*; // JahiaDataimport 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.shared.*; // SmallText, BigText, etc.import org.jahia.data.events.*; // JahiaEventimport org.jahia.engines.rights.*; // ViewRightsimport org.jahia.services.acl.*;import org.jahia.data.applications.*;import org.jahia.services.usermanager.*;/** * Applications Engine, to manage roles,... * * @author Khue ng * @version 1.0 */public class Applications_Engine implements JahiaEngine { private static Applications_Engine m_Instance = null; private static String engineName = "applications"; private EngineToolBox toolBox; private static final String TEMPLATE_JSP = "roles_manager"; private static final String CLOSE_JSP = "roles_manager_close"; /** The requested action **/ private final String ACTION_REQ = "actionreq"; private final String SUB_ACTION = "subAction"; /*** * constructor * */ protected Applications_Engine() { //JahiaConsole.println( "Engine", // "***** Starting Applications Engine *****" ); toolBox = EngineToolBox.getInstance(); } // end constructor /*** * returns a single instance of the object * */ public static synchronized Applications_Engine getInstance() { if (m_Instance == null) { m_Instance = new Applications_Engine(); } return m_Instance; } // end getInstance /*** * authoriseRender * */ public boolean authoriseRender( ParamBean jParams ) { return toolBox.authoriseRender( jParams ); } // end authoriseRender /*** * renderLink * */ public String renderLink( ParamBean jParams, Object theObj ) throws JahiaException { String theUrl = ""; String params = "?mode=display"; //String params += "&fid=" + jParams.getFieldID(); if ( jParams != null ){ theUrl = jParams.composeEngineUrl( engineName, params ); } return theUrl ; } // end renderLink /*** * needsJahiaData * */ public boolean needsJahiaData( ParamBean jParams ) { return false; } // end needsJahiaData /*** * handdles the engine actions * * @param jParams a ParamBean object * @param jData a JahiaData object (not mandatory) * */ public void handleActions( ParamBean jParams, JahiaData jData ) throws JahiaException { HashMap engineMap = initEngineMap( jParams ); boolean displayScreen = true; String action = jParams.getParameter(ACTION_REQ); JahiaConsole.println("Applications_Engine.handleActions","actionreq=" + action); String subAction = jParams.getRequest().getParameter("subaction"); if ( subAction == null || subAction.equals("") ){ handleDisplayRoles(jParams,engineMap); } else if ( subAction.equals("save") ){ handleSaveRoles(jParams,engineMap); } if ( displayScreen ){ // sets engineMap for JSPs jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", engineMap ); // displays the screen toolBox.displayScreen( jParams, engineMap ); } } // end handleActions private void handleDisplayRoles( ParamBean jParams, HashMap engineMap) throws JahiaException { int fieldID = Integer.parseInt(jParams.getRequest().getParameter("fid")); int appID = Integer.parseInt(jParams.getParameter("appid")); String role = ""; JahiaConsole.println("Applications_Engine.handleDisplayRoles", "fieldID=" + fieldID + " appID=" + appID); // get the application's roles list ApplicationContext appContext = ServicesRegistry.getInstance() .getJahiaApplicationContextService() .getApplicationContext(appID); Enumeration roles = appContext.getRoles().elements(); engineMap.put( "roles", roles ); if ( appID != -1 ){ if ( jParams.getParameter("roles") != null ){ role = jParams.getParameter("roles"); } else { // get the application's roles list Vector v = appContext.getRoles(); if ( v.size()>0 ){ role = (String)v.get(0); } } } // get the mode ( users or groups ) String switchUG = jParams.getRequest().getParameter("switchug"); String prevSwitchUG = jParams.getRequest().getParameter("prevswitchug"); if ( switchUG == null ){ switchUG = "groups"; prevSwitchUG = "groups"; } // handle the previous role // save change the previous role Vector authMembers = new Vector(); String currentRole = ""; if ( jParams.getParameter("currentRole") != null ){ currentRole = jParams.getParameter("currentRole"); JahiaConsole.println("Applications_Engine.handleDisplayRoles", "handle previous role " + currentRole); // check the previous mode if ( prevSwitchUG.equals("users") ){ String[] usrKeys = (String[])jParams.getRequest().getParameterValues("authMembers"); if ( usrKeys != null ){ JahiaUser user = null; for ( int i=0 ; i<usrKeys.length ; i++ ){ user = ServicesRegistry.getInstance() .getJahiaUserManagerService() .lookupUser(usrKeys[i]); if ( user != null ){ authMembers.add(user); JahiaConsole.println("Applications_Engine.handleDisplayRoles", "in users mode, added member= " + user.getUsername()); } } } engineMap.put( "authUsers" + currentRole, authMembers ); } else if ( prevSwitchUG.equals("groups") ){ String[] grpKeys = (String[])jParams.getRequest().getParameterValues("authMembers"); if ( grpKeys != null ){ JahiaGroup grp = null; for ( int i=0 ; i<grpKeys.length ; i++ ){ grp = ServicesRegistry.getInstance() .getJahiaGroupManagerService() .lookupGroup(grpKeys[i]); if ( grp != null ){ authMembers.add(grp); } } } engineMap.put( "authGroups" + currentRole, authMembers ); } } if ( switchUG.equals("users") ){ JahiaConsole.println("Applications_Engine.handleDisplayRoles","in users mode"); // build authorized users for new role Vector allUsers = ServicesRegistry.getInstance().getJahiaSiteUserManagerService().getMembers(jParams.getSiteID()); Vector authUsersVec = new Vector(); JahiaUser user = null; if ( role != null && !role.equals("") ){ if ( engineMap.get( "authUsers" + role ) != null ){ JahiaConsole.println("Applications_Engine.handleDisplayRoles","get authUsers from session"); authMembers = (Vector)engineMap.get( "authUsers" + role ); } else { JahiaConsole.println("Applications_Engine.handleDisplayRoles","get authUsers from db"); JahiaGroup grp = ServicesRegistry.getInstance() .getJahiaGroupManagerService()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -