⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 template_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  Template_Engine//  NK  27.01.2002//package org.jahia.engines.template;import java.io.*;                                   // Fileimport 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.params.*;                      // ParamBeanimport org.jahia.registries.*;                  // ServicesRegistryimport org.jahia.engines.*;                     // JahiaEngine interfaceimport org.jahia.data.events.*;                 // JahiaEventimport org.jahia.engines.rights.*;              // ViewRightsimport org.jahia.engines.audit.*;               // ManageLogs_Engineimport org.jahia.services.usermanager.*;        // JahiaUserimport org.jahia.services.pages.*;        		// JahiaPageDefinitionimport org.jahia.services.acl.*;        		// ACLResourceWrapperimport org.jahia.content.*;/** * Engine for editing and setting rights on template * * @author  Khue Nguyen */public class Template_Engine implements JahiaEngine {    private static final String CLASS_NAME = Template_Engine.class.getName();    private static final String TEMPLATE_JSP = "manage_template";	public  static final String TEMPLATE_SESSION_NAME = "theTemplate";	// the temporary template to hold change until they have to be saved.	private  static final String TEMPORARY_TEMPLATE_SESSION_NAME = "theTemporaryTemplate";    private static Template_Engine theObject;    private String engineName = "template";    private EngineToolBox toolBox;	/**     * constructor     *     */    private Template_Engine()    {        // JahiaConsole.println( "Engine", "***** Starting Template Engine *****" );        toolBox = EngineToolBox.getInstance();    }    /**     * getInstance	 *     */    public static synchronized Template_Engine getInstance()    {        if (theObject == null) {            theObject = new Template_Engine();        }        return theObject;    }    /**     * authoriseRender     *     */    public boolean authoriseRender( ParamBean jParams )    {        return true; // we do not check if we are in Edit mode    }    /**     * renderLink     *     */    public String renderLink( ParamBean jParams, Object theObj )    throws JahiaException    {        JahiaPageDefinition theTemplate = (JahiaPageDefinition) theObj;        String params = "";        params += "?mode=display";        params += "&templateid=" + theTemplate.getID();        return jParams.composeEngineUrl( engineName, params );    }    /**     * needsJahiaData     *     */    public boolean needsJahiaData( ParamBean jParams )    {        return false;    }    //--------------------------------------------------------------------------    /**     * 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(jData);        // checks if the user has the right to display the engine        JahiaPageDefinition theTemplate =        			(JahiaPageDefinition)engineMap.get(TEMPLATE_SESSION_NAME);        JahiaUser   theUser = jParams.getUser();        if (ACLResource.checkAdminAccess(theTemplate,theUser, theTemplate.getJahiaID())) {            engineMap.put ("adminAccess", Boolean.TRUE);            engineMap.put ("writeAccess", Boolean.TRUE);        } else if (ACLResource.checkWriteAccess(theTemplate,theUser, theTemplate.getJahiaID())) {            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 );   	}    //--------------------------------------------------------------------------    /**     * processes the last screen sent by the user     *     * @param jParams,  a ParamBean object     * @HashMap engineMap, the engine Map     */    public void processLastScreen( ParamBean jParams, HashMap engineMap )        throws  JahiaException,        		JahiaForbiddenAccessException    {        JahiaPageDefinition theTemplate =        			(JahiaPageDefinition) engineMap.get(TEMPLATE_SESSION_NAME);        // gets the last screen        // lastscreen   = edit, rights, logs        String lastScreen = jParams.getRequest().getParameter( "lastscreen" );        if (lastScreen == null) {            lastScreen = "edit";        }        int mode = JahiaEngine.UPDATE_MODE;        if (lastScreen.equals( "edit" ))  {            if (!processTemplateEdit( 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, theTemplate.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();            }        }    }    //--------------------------------------------------------------------------    /**     * prepares the screen requested by the user     *     * @param jParams a ParamBean object     */    public void processCurrentScreen( ParamBean jParams, HashMap engineMap )        throws  JahiaException,                JahiaForbiddenAccessException    {        // gets the current screen        // screen   = edit, rights, logs        String theScreen    = (String)      engineMap.get( "screen" );        JahiaPageDefinition theTemplate =        			(JahiaPageDefinition) engineMap.get(TEMPLATE_SESSION_NAME);        // 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" ))  {            processTemplateEdit( jParams, mode, engineMap );        } else if (theScreen.equals("logs")) {            toolBox.loadLogData( jParams, JahiaObjectTool.TEMPLATE_TYPE, engineMap );        } else if (theScreen.equals("rightsMgmt")) {            if (engineMap.get("adminAccess") != null) {                ManageRights.getInstance()                .handleActions( jParams, mode,engineMap, theTemplate.getAclID() );            } else {                throw new JahiaForbiddenAccessException();            }        } else if (theScreen.equals("save") || theScreen.equals ("apply")) {            mode = JahiaEngine.SAVE_MODE;            if ( processTemplateSave( jParams, engineMap ) ){	            if (engineMap.get("adminAccess") != null) {	                engineMap.put("logObjectType", Integer.toString(JahiaObjectTool.TEMPLATE_TYPE));	                engineMap.put("logObject", theTemplate);	                ManageRights.getInstance()	                .handleActions( jParams, mode, engineMap, theTemplate.getAclID() );	            }	            JahiaEvent theEvent = new JahiaEvent( this, jParams, theTemplate );	            ServicesRegistry.getInstance().getJahiaEventService().fireUpdateTemplate( theEvent );            } else {                // if there was an error, come back to last screen                engineMap.put( "screen", "edit" );                engineMap.put( "jspSource", TEMPLATE_JSP );			}            if (theScreen.equals ("apply")) {				JahiaPageDefinitionTemp theTemporaryTemplate = ( JahiaPageDefinitionTemp )				engineMap.get( TEMPORARY_TEMPLATE_SESSION_NAME );	            // remove template context and the sitekey from the source path	            String templateContext = jParams.settings().getTemplatesContext() + jParams.getSite().getSiteKey() + "/";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -