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

📄 enginetoolbox.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////// $Id: EngineToolBox.java,v 1.2 2002/05/31 16:56:37 shuber Exp $////  EngineToolBox//  EV  10.01.20001////  authoriseRender()//  processFieldTypes( jParams, mode )//  displayScreen( jParams )//  loadLogData( jParams, objectType, engineMap )   MJ//  unAuthorized()//package org.jahia.engines;import java.util.*;                                 // HashMapimport javax.servlet.http.*;                        // HttpSessionimport java.lang.reflect.*;                         // Method, Classimport org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaUpdateLockException;import org.jahia.utils.*;                       // JahiaConsole, JahiaObjectToolimport org.jahia.data.*;                        // JahiaDataimport org.jahia.services.pages.JahiaPage;import org.jahia.data.containers.*;             // JahiaContainerimport org.jahia.data.fields.*;                 // JahiaField, FieldTypesimport org.jahia.params.*;                      // ParamBeanimport org.jahia.engines.shared.*;              // Smalltext, Bigtext, etc.import org.jahia.registries.*;                  // ServicesRegistryimport org.jahia.services.audit.*;              // LoggingEventListener, AuditLogManagerServiceimport org.jahia.engines.audit.*;               // ManageLogs_Enginepublic class EngineToolBox{    private static       EngineToolBox               theObject           = null;    private static final String                      MSG_INTERNAL_ERROR  = new String ("Audit Log Manager internal error");    private static final String                      JSP_LOGFORM         = "/jsp/jahia/engines/audit/viewlogs.jsp";    private static final String                      JSP_SENDLOG         = "/jsp/jahia/engines/audit/sendlogs.jsp";    private static final String                      JSP_FLUSHCONFIRM    = "/jsp/jahia/engines/audit/flushconfirm.jsp";    // references to needed services.    private              JahiaAuditLogManagerService mAuditLogManager    = null;    /***        * constructor        *        */    private EngineToolBox()    {        JahiaConsole.println( "Engine",                        "***** Starting EngineToolBox *****" );    } // end constructor    /***        * returns a single instance of the object        *        */    public static synchronized EngineToolBox getInstance()    {        if (theObject == null) {            theObject = new EngineToolBox();        }        return theObject;    } // end getInstance    /***        * authoriseRender        *        */    public boolean authoriseRender( ParamBean jParams )    {        return (jParams.getOperationMode() == jParams.EDIT);    } // end authoriseRender    /**     * dispatches to an engine according to the field type     *     * @param        jParams             a ParamBean object     *     */    public boolean processFieldTypes(   ParamBean   jParams,                                        int         mode,                                        HashMap     engineMap )        throws  JahiaException,                JahiaUpdateLockException    {        boolean out = true;        JahiaField theField = (JahiaField) engineMap.get( "theField" );        int pageDefID = jParams.getPage().getPageTemplateID();        int fieldType = theField.getDefinition().getType( pageDefID );        JahiaConsole.println("EngineToolBox.processFieldTypes"," field type is " + fieldType);        if ((fieldType == FieldTypes.UNDEFINED) || (fieldType < 0)) {            fieldType = theField.getType();        }       // get the engine className        String engineName = theField.getEngineName();        if (fieldType == FieldTypes.UNDEFINED)        {                out = Undefined_Field.getInstance().                      handleField( jParams, new Integer(mode), engineMap );        } else {        // replace the switch-case statements        // avoid to modify the method when adding a field type        try {            Class theParams[] = null;            //System.out.println("EngineToolBox - processFieldTypes - engineName: "             //                  +engineName+", call getInstance");            Method thisMethod = Class.forName(engineName).                                getDeclaredMethod("getInstance",theParams);            Object args[] = null;            Object engine = thisMethod.invoke(null, args);            Class theParams2[] = {Class.forName(                                        "org.jahia.params.ParamBean"),                                  Class.forName("java.lang.Integer"),                                  Class.forName("java.util.HashMap")};            //System.out.println("EngineToolBox - processFieldTypes - engineName: "             //                 +engineName+", call handleField");            Method thisMethod2 = Class.forName(engineName).                                 getDeclaredMethod("handleField",theParams2);            Object args2[] = {jParams, new Integer(mode), engineMap};            out = ( (Boolean)thisMethod2.invoke(engine, args2) ).booleanValue();            JahiaConsole.println("EngineToolBox.processFieldTypes","Editing "+engineName.                substring(engineName.lastIndexOf("."))+" !" );        } catch(ClassNotFoundException cnfe) {                throw new JahiaException ("EngineToolBox:processFieldTypes",                "Class not found!",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL, cnfe);        } catch(NoSuchMethodException nsme) {                throw new JahiaException ("EngineToolBox:processFieldTypes",                "Method not found!",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL, nsme);        } catch(IllegalAccessException iae) {                throw new JahiaException ("EngineToolBox:processFieldTypes",                "Illegal access",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL, iae);        } catch(InvocationTargetException ite) {            ite.printStackTrace();            throw new JahiaException ("EngineToolBox:processFieldTypes",                "InvocationTarget exception",                JahiaException.PAGE_ERROR, JahiaException.CRITICAL, ite);        }        }        return out;    } // end processFieldTypes    /***        * displays the screen requested by the user        *        * @param        jParams             a ParamBean object        *        */    public void displayScreen( ParamBean jParams, HashMap engineMap )    throws JahiaException    {        engineMap.put( "jParams", jParams );        EngineRenderer.getInstance().render( jParams, engineMap );    } // end displayScreen    /***        * loads log data for the JSP file        *        * @author       MJ        *        * @param        jParams             a ParamBean object        *                                   (with request and response)        * @param        objectType          an <code>int</code> representing        *                                   the type of the object processed        * @param        engineMap           then engine map, to be forwarded        *                                   to the JSP file        *        */    public void loadLogData( ParamBean jParams, int objectType, HashMap engineMap )    throws JahiaException    {        // set default values        int flushLogs         = 0;        String output         = "";        int deletedRows       = 0;        // get parameters        String  userAgent     = jParams.getRequest().getHeader("user-agent");        boolean sendAsFile    = ( jParams.getRequest().getParameter("send") != null );        if( jParams.getRequest().getParameter("flush") != null ) {                flushLogs     = Integer.parseInt( jParams.getRequest().getParameter("flush") );        }        int     objectID      = JahiaObjectTool.getInstance().getObjectID( objectType, engineMap );        String  objectName    = JahiaObjectTool.getInstance().getObjectName( objectType, engineMap );        // Try to get the Audit Log Manager Service        ServicesRegistry registry = ServicesRegistry.getInstance();        if (registry != null) {            mAuditLogManager = registry.getJahiaAuditLogManagerService();            if (mAuditLogManager == null) {                throw new JahiaException (MSG_INTERNAL_ERROR, "Properties Engine could not get the Audit Log Manager Service instance.",                                            JahiaException.SERVICE_ERROR, JahiaException.CRITICAL);            }        } else {            throw new JahiaException (MSG_INTERNAL_ERROR, "Properties Engine could not get the Service Registry instance.",                                      JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL);        }        // logs        engineMap.put( "flushLogs",      new Integer(flushLogs) );        engineMap.put( "sendLogsURL",    ManageLogs_Engine.getInstance().renderLink( jParams, "" ) );        engineMap.put( "objectTypeName", JahiaObjectTool.getInstance().getObjectTypeName(objectType) );        engineMap.put( "objectIDObj",    new Integer(objectID) );        engineMap.put( "objectName",     objectName );        engineMap.put( "userAgent",      userAgent );        // flushLogs cases :        //  - null : just display current log entries        //  - 1    : user has clicked "Flush" in viewlogs.jsp -> display confirmation request        //  - 2    : user has confirmed flush in flushconfirm.jsp -> call flushlogs() method        //                                                           and display clean log window        switch ( flushLogs ) {            case 1:                     output            = registry.getJahiaFetcherService().fetchServlet( jParams, JSP_FLUSHCONFIRM );                     break;            case 2:  deletedRows       = mAuditLogManager.flushLogs( objectType, objectID, jParams );            default: ArrayList logData = (ArrayList) mAuditLogManager.getLog ( objectType, objectID );                     engineMap.put( "logData", logData );                     engineMap.put( "deletedRows", new Integer(deletedRows) );                     output = registry.getJahiaFetcherService().fetchServlet( jParams, JSP_LOGFORM );        }        engineMap.put( "logForm", output );    } // end loadLogData} // end EngineToolBox

⌨️ 快捷键说明

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