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

📄 deletecontainer_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  DeleteContainer_Engine//  EV  28.01.20001////  getInstance()//  authoriseRender()//  renderLink()//  needsJahiaData()//  handleActions()//package org.jahia.engines.deletecontainer;import java.util.*;                                 // HashMapimport javax.servlet.http.*;                        // HttpSessionimport org.jahia.exceptions.*;                  // JahiaExceptionimport org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.exceptions.JahiaForbiddenAccessException;import org.jahia.utils.*;                       // JahiaConsoleimport org.jahia.data.*;                        // JahiaData, ConnectionTypesimport org.jahia.services.pages.JahiaPage;import org.jahia.services.pages.PageLoadFlags;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.services.usermanager.*;        // JahiaUserimport org.jahia.content.*;public class DeleteContainer_Engine implements JahiaEngine {    private static  final   String              TEMPLATE_JSP = "delete_container";    private static          DeleteContainer_Engine  theObject   = null;    private                 String              engineName  = "deletecontainer";    private                 EngineToolBox       toolBox;    /***        * constructor        *        */    private DeleteContainer_Engine()    {        // JahiaConsole.println( "Engine", "***** Starting DeleteContainer Engine *****" );        toolBox = EngineToolBox.getInstance();    } // end constructor    /***        * returns a single instance of the object        *        */    public static synchronized DeleteContainer_Engine getInstance()    {        if (theObject == null) {            theObject = new DeleteContainer_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    {        JahiaContainer   theContainer    = (JahiaContainer) theObj;        String params = "";//        params += "&mode=display";        params += "?mode=display";        params += "&cid=" + theContainer.getID();        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    {        // initalizes the hashmap        HashMap engineMap = initEngineMap( jParams );        // checks if the user has the right to display the engine        JahiaContainer  theContainer = (JahiaContainer)engineMap.get("theContainer");        JahiaUser       theUser = jParams.getUser();        if (theContainer.checkWriteAccess (theUser)) {            engineMap.put( "writeAccess", Boolean.TRUE );            processScreen( jParams, engineMap );        } else {            throw new JahiaForbiddenAccessException ();        }        // displays the screen        toolBox.displayScreen( jParams, engineMap );    } // end handleActions    /***        * prepares the screen requested by the user        *        * @param        jParams             a ParamBean object        *        */    public void processScreen( ParamBean jParams, HashMap engineMap )        throws JahiaException    {        // gets the current screen        // screen   = edit, rights, logs        String theScreen    = (String)      engineMap.get( "screen" );        JahiaContainer theContainer = (JahiaContainer)  engineMap.get( "theContainer" );        // dispatches to the appropriate sub engine        if (theScreen.equals("edit")) {            composeWarningMessages( jParams, engineMap );        } else if (theScreen.equals("save")) {            if (engineMap.get("writeAccess") != null) {                JahiaEvent theEvent = new JahiaEvent( this, jParams, theContainer );                ServicesRegistry.getInstance().getJahiaEventService().fireDeleteContainer( theEvent );                ServicesRegistry.getInstance().getJahiaContainersService().deleteContainer( theContainer.getID(), jParams );                JahiaContainerList theList = ServicesRegistry.getInstance().                    getJahiaContainersService().loadContainerListInfo( theContainer.getListID() );                // since we have made modifications concerning this page, let's flush                // the content cache for all the users and browsers as well as all                // pages that display this containerList...                if (theList != null) {                    Set containerPageRefs = ContainerListsXRefManager.getInstance().                        getAbsoluteContainerListPageIDs(jParams.getSiteKey(),                                                        theList.getDefinition().getName(),                                                        theList.getPageID());                    if (containerPageRefs != null) {                        Iterator pageRefIDs = containerPageRefs.iterator();                        while (pageRefIDs.hasNext()) {                            Integer curPageID = (Integer) pageRefIDs.next();                            ServicesRegistry.getInstance().getCacheServerService().                                removeEntry(curPageID.toString());                        }                    } else {                        JahiaConsole.println("AddContainer_Engine.processCurrentScreen",                                             "Why is cross ref list empty ?");                    }                } else {                    JahiaConsole.println("AddContainer_Engine.processCurrentScreen",                                         "Couldn't retrieve parent containerList, why is that ?");                }                // since we have made modifications concerning this page, let's flush                // the content cache for all the users and browsers...                ServicesRegistry.getInstance().getCacheServerService().                    removeEntry(Integer.toString(jParams.getPageID()));            } else {                throw new JahiaForbiddenAccessException();            }        }    } // end processScreen    /***        * inits the engine map        *        * @param        jParams             a ParamBean object (with request and response)        * @return       a HashMap object containing all the basic values needed by an engine        *        */    private HashMap initEngineMap( ParamBean jParams  )        throws  JahiaException,                JahiaSessionExpirationException    {        HashMap engineMap = new HashMap();        JahiaContainer  theContainer;        // gets session values        //HttpSession theSession = jParams.getRequest().getSession( true );        HttpSession theSession = jParams.getSession ();        // gets container id        String ctnidStr = jParams.getRequest().getParameter( "cid" );        int ctnid = 0;        try {            ctnid = Integer.parseInt( ctnidStr );        } catch (NumberFormatException nfe) {            String errorMsg = "Error in parameters : cid (" + ctnidStr + ") cannot be converted in int";            throw new JahiaException( "Error in parameters", errorMsg,                        JahiaException.DATA_ERROR, JahiaException.CRITICAL );        }        // tries to find if this is the first screen generated by the engine        String theScreen = jParams.getRequest().getParameter( "screen" );        if (theScreen != null) {            // if no, load the field value from the session            engineMap = (HashMap) theSession.getAttribute( "jahia_session_engineMap" );            ///////////////////////////////////////////////////////////////////////////////////////            // FIXME -Fulco-            //            //      This is a quick hack, engineMap should not be null if the session didn't            //      expired. Maybe there are other cases where the engineMap can be null, I didn't            //      checked them at all.            ///////////////////////////////////////////////////////////////////////////////////////            if (engineMap == null) {                throw new JahiaSessionExpirationException ();            }            theContainer = (JahiaContainer) engineMap.get( "theContainer" );        } else {            theContainer = ServicesRegistry.getInstance().getJahiaContainersService().                        loadContainer( ctnid, LoadFlags.ALL, jParams );            theScreen = "edit";            // init engine map            engineMap = new HashMap();            engineMap.put( "theContainer", theContainer );            engineMap.put( "jParams", jParams );            engineMap.put( "renderType", new Integer(JahiaEngine.RENDERTYPE_FORWARD) );            engineMap.put( "engineName", engineName );            engineMap.put( "engineUrl", jParams.composeEngineUrl( engineName, "?cid=" + theContainer.getID() ) );            theSession.setAttribute( "jahia_session_engineMap", engineMap );        }        // sets screen        engineMap.put( "screen", theScreen );        if (!theScreen.equals("save")) {            engineMap.put( "jspSource", TEMPLATE_JSP );        } else {            engineMap.put( "jspSource", "close" );        }        // sets engineMap for JSPs        jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", engineMap );        return engineMap;    } // end initEngineMap    /***        * composes warning messages        *        * @param        jParams             a ParamBean object (with request and response)        * @param        engineMap           the engine parameters        * @return       a HashMap object containing all the basic values needed by an engine        *        */    private void composeWarningMessages( ParamBean jParams, HashMap engineMap )    throws JahiaException    {        JahiaContainer theContainer = (JahiaContainer)  engineMap.get( "theContainer" );        engineMap.put( "deletedPages", new Vector() );        engineMap.put( "deletedLinks", new Vector() );        engineMap.put( "warning", Boolean.FALSE );        Enumeration theFields = theContainer.getFields();        JahiaPage page = ServicesRegistry.getInstance().getJahiaPageService().lookupPage (theContainer.getPageID(), jParams);        int pageDefID = page.getPageTemplateID();        while (theFields.hasMoreElements()) {            JahiaField theField = (JahiaField) theFields.nextElement();            int fieldType = theField.getDefinition().getType( pageDefID );            fieldType = (fieldType != 0) ? fieldType : theField.getType();            // checks if deleting the container means deleting pages            if (fieldType == FieldTypes.PAGE) {                JahiaPage thePage = (JahiaPage) theField.getObject();                if (thePage != null) {                    Vector deletedPages = ServicesRegistry.getInstance().getJahiaPageService().                            getPageSubTree (thePage.getID(), PageLoadFlags.DIRECT, jParams);                    Vector deletedLinks = new Vector();                    deletedLinks.addAll (ServicesRegistry.getInstance().getJahiaPageService().getPagesPointingOnPage (thePage.getID(), jParams));                    for (int i=0; i < deletedPages.size(); i++) {                        JahiaPage aPage = (JahiaPage) deletedPages.elementAt(i);                        deletedLinks.addAll (ServicesRegistry.getInstance().getJahiaPageService().getPagesPointingOnPage (aPage.getID(), jParams));                    }                    engineMap.put( "deletedPages", deletedPages );                    engineMap.put( "deletedLinks", deletedLinks );                    if ((deletedPages.size() > 0) || (deletedLinks.size() > 0)) {                        engineMap.put( "warning", Boolean.TRUE );                    }                }            }        }    } // end composeWarningMessages} // end DeleteContainer_Engine

⌨️ 快捷键说明

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