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

📄 logout_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  Logout_Engine//	(No user interaction, just plain raw hardkore logout ;)//  EV  23.01.2001////  getInstance()//  authoriseRender()//  renderLink()//  needsJahiaData()//  handleActions()//package org.jahia.engines.logout;import java.util.*;                                 // HashMapimport javax.servlet.http.*;                        // HttpSessionimport org.jahia.exceptions.*;                  // JahiaExceptionimport org.jahia.utils.*;                       // JahiaConsoleimport org.jahia.data.*;                        // JahiaData, ConnectionTypesimport org.jahia.params.*;                      // ParamBeanimport org.jahia.registries.*;                  // ServicesRegistryimport org.jahia.engines.*;                     // JahiaEngine interfaceimport org.jahia.engines.core.*;                // JahiaCoreEngineimport org.jahia.data.events.*;                 // JahiaEventimport org.jahia.services.pages.*;		        // JahiaPageimport org.jahia.services.sites.*;		        // JahiaSiteimport org.jahia.services.usermanager.*;        // JahiaUserManagerpublic class Logout_Engine implements JahiaEngine {    private static          Logout_Engine        theObject   = null;    private                 String              engineName  = "logout";    private                 EngineToolBox       toolBox;    /***        * constructor        *        */    private Logout_Engine()    {        // JahiaConsole.println( "Engine", "***** Starting Logout Engine *****" );        toolBox = EngineToolBox.getInstance();    } // end constructor    /***        * returns a single instance of the object        *        */    public static synchronized Logout_Engine getInstance()    {        if (theObject == null) {            theObject = new Logout_Engine();        }        return theObject;    } // end getInstance    /***        * authorises engine render        *        */    public boolean authoriseRender( ParamBean jParams )    {        return true;					// always allowed to render logout!    } // end authoriseRender    /***        * renders link to pop-up window        *        */    public String renderLink( ParamBean jParams, Object theObj )    throws JahiaException    {        /**         * @todo This is very ugly... what are we doing here exactly ?         */        String theUrl = jParams.composeEngineUrl( engineName, "" );        if (theObj != null)  {            // we remove the /pid/../ part of the URL here ?            int pidNamePos = theUrl.indexOf( "/pid/" );            int pidValuePos = theUrl.indexOf( "/", pidNamePos + 5 );            pidValuePos = (pidValuePos > -1) ? pidValuePos : theUrl.length();            String myString = theObj.toString();            myString.replace('&','/');            myString.replace(';','/');            theUrl = theUrl.substring(0,pidNamePos) + theUrl.substring(pidValuePos,theUrl.length()) + myString;            theUrl += "?engine_params=logout";        }        return jParams.getResponse().encodeURL(theUrl);    } // end renderLink    /***        * specifies if the engine needs the JahiaData object        *        */    public boolean needsJahiaData( ParamBean jParams )    {        return false;		// we need the jData because we are forwarding the request                            // to the "core" engine!    } // 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    {        String engineParams	= jParams.getRequest().getParameter ( "engine_params" );        JahiaPage logoutPage = null;        // if there is no engineparams, it just means that the engine is still set to        // logout, but in fact the user wants to call "core". This is because a user        // logs outs, the page is reloaded but still with engine "logout".        if ((engineParams!=null) && (engineParams.equals("logout")))        {            JahiaConsole.finalPrintln("Logout_Engine","User " + jParams.getUser().getName() + " logged out.");            // send a new logout event !            JahiaEvent theEvent = new JahiaEvent( this, jParams, jParams.getUser() );            ServicesRegistry.getInstance().getJahiaEventService().fireLogout( theEvent );            logoutPage = getLogoutPage(jData);            // if we were in edit mode, let's destroy the cache's entry for this page and this user.            if (jParams.EDIT.equals(jParams.getOperationMode())) {                ServicesRegistry.getInstance().getCacheServerService().removeUserEntries(jParams.getUser().getUsername());            }            // destroys all the session objects and creates a new one            // jParams.invalidateSession();            jParams.purgeSession();            // set current user to guest            jParams.setUserGuest(jParams.getSiteID());        }        if ( logoutPage == null ){            // current page do not have read            throw new JahiaException( "403 Forbidden - Page:"+ jParams.getPageID(),                        "No read access for page " + jParams.getPageID(),                        JahiaException.SECURITY_ERROR,                        JahiaException.ERROR );        } else {            // get the logout page with template            try {                JahiaPageBaseService pageService = JahiaPageBaseService.getInstance();                logoutPage = (JahiaPage)pageService                    .lookupPage (logoutPage.getID(),jParams);            } catch ( Throwable t ){                t.printStackTrace();            }            if ( logoutPage == null ) {                throw new JahiaException( "404 Page not found "+ logoutPage.getID(),                        "Logout page not found " + logoutPage.getID(),                        JahiaException.SECURITY_ERROR,                        JahiaException.ERROR );            }            // change the page            jParams.changePage(logoutPage);        }        JahiaData jData2 = new JahiaData( jParams );        ((JahiaEngine)EnginesRegistry.getInstance().getEngine("core")).handleActions( jParams, jData2 );    } // end handleActions    //--------------------------------------------------------------------------    /**     * Check for a "friendly" logout page instead of a "403 Forbidden " page,     * when the user loggout.     *     * @param JahiaPage a page, can be null if no page available.     * @auhtor NK     */    private JahiaPage getLogoutPage( JahiaData jData ){        JahiaUser user = jData.params().getUser();        JahiaPage page = jData.params().getPage();        JahiaSite site = jData.params().getSite();        if ( page == null || user == null || site == null )            return null;        if ( page.checkGuestAccess(site.getID()) )            // he can stay at current page.            return page;        // look at the user homepages        try {            JahiaPageBaseService pageService = JahiaPageBaseService.getInstance();            // get user home page            if ( user.getHomepageID() >= 0 ){                try {                    page = (JahiaPage)pageService                                .lookupPageWhitoutTemplates (user.getHomepageID());                    if ( (page != null) && page.checkGuestAccess(site.getID()) )                        return page; // return the user home page                } catch ( Throwable t ){                    t.printStackTrace();                }            }            // get group homepages            JahiaGroupManagerService grpServ =                    ServicesRegistry.getInstance().getJahiaGroupManagerService();            Vector v = grpServ.getUserMembership(user);            int size = v.size();            String grpKey = null;            JahiaGroup grp = null;            for ( int i=0 ; i<size ; i++ ){                grpKey = (String)v.get(i);                grp = grpServ.lookupGroup(grpKey);                if ( grp != null                        && grp.getSiteID() == site.getID()                        && grp.getHomepageID() >=0 ){                    try {                        page = (JahiaPage)pageService                            .lookupPageWhitoutTemplates (grp.getHomepageID());                        if ( (page != null) && page.checkGuestAccess(site.getID()) )                            return page;// return the user first available group home page                                        // TODO -> have a default homepage per user !!! Pol is doing it                    } catch ( Throwable t ){                        t.printStackTrace();                    }                }            }            // if none available check if user has guest access on the site's homepage            try {                page = (JahiaPage)pageService                    .lookupPageWhitoutTemplates (site.getHomePageID());                if ( (page != null) && page.checkGuestAccess(site.getID()) )                    return page;            } catch ( Throwable t ){                t.printStackTrace();            }        } catch (Throwable t) {            t.printStackTrace();        }        return null; // no page available...    }} // end Logout_Engine

⌨️ 快捷键说明

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