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

📄 copytree_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                JahiaForbiddenAccessException    {        toDebug(">> CopyTree_Engine :: handleActions");        // initalizes the hashmap        HashMap engineMap = initEngineMap( jData );        HttpSession theSession =  jParams.getSession();        JahiaUser theUser  =  (JahiaUser) engineMap.get("theUser");        // checks if the user has the right to display the engine        JahiaPage   thePage    =  (JahiaPage)engineMap.get ("thePage");        if (thePage.checkWriteAccess (theUser)) {            engineMap.put("writeAccess", Boolean.TRUE);        }        if (engineMap.get ("writeAccess") != null)        {            processLastScreen (jData.params(), engineMap);            processCurrentScreen (jData.params(), engineMap);        } else {            throw new JahiaForbiddenAccessException ();        }        // displays the screen        toolBox.displayScreen( jData.params(), engineMap );    } // end handleActions    /***        * processes the last screen sent by the user        *        * @param        jParams             a ParamBean object        * @param        engineMap           the engine context        *        */    public void processLastScreen (ParamBean jParams, HashMap engineMap)        throws  JahiaException,                JahiaForbiddenAccessException    {        // gets the last screen        String lastScreen = jParams.getRequest().getParameter( "lastscreen" );        if (lastScreen == null) {            updateCopyData( jParams, engineMap );            return;        } else if (lastScreen.equals( "source" ))  {            String sourcePageIDStr = jParams.getRequest().getParameter( "sourcepageid" );            String sourcePageTitle = "";            try {                int sourcePageID = Integer.parseInt(sourcePageIDStr);                engineMap.put(SOURCEPAGE_ID, new Integer(sourcePageID));                sourcePageTitle = getPageTitle(sourcePageIDStr);                engineMap.put("sourcePageTitle", sourcePageTitle);            } catch (Exception e) {                toDebug(">> CopyTree_Engine :: processLastScreen :: invalid source page ID: [" + sourcePageIDStr + "]");                engineMap.put( SOURCEPAGE_ID, null );            }            String operation = (String)engineMap.get("operation");            if(operation.equals(COPY_OPERATION)) {            String maxLevelsStr = jParams.getRequest().getParameter( "maxlevels" );                if(maxLevelsStr != null) {                    try {                        Integer maxLevels    =  new Integer(maxLevelsStr);                        Integer targetPageID =  (Integer)   engineMap.get( "targetPageID"  );                        engineMap.put("maxLevels", maxLevels);                    } catch(NumberFormatException nfe) {                        engineMap.put( "maxLevels", null );                    }                } else {                    engineMap.put( "maxLevels", null );                }            }            if (!updateCopyData( jParams, engineMap )) {                // if there was an error, come back to last screen                engineMap.put( "screen", lastScreen );                engineMap.put( "jspSource", CHOOSESOURCE_JSP );            } else {                try {                    //GenericTree treeData = (GenericTree)engineMap.get("treeData");                    //GenericTree sourceBranch = initTreeData.getSubTree(Integer.parseInt(sourcePageIDStr), "org.jahia.services.pages.JahiaTreeViewPageWrapper");                    //engineMap.put( "souceBranch", sourceBranch );                } catch(NumberFormatException nfe) {                    toDebug("invalid page ID");                    engineMap.put( "screen", lastScreen );                    engineMap.put( "jspSource", CHOOSESOURCE_JSP );                }            }        }    } // end processLastScreen    /****        * prepares the screen requested by the user        *        * @param        jParams             a ParamBean object        * @param        engineMap           the engine context        *        */    public void processCurrentScreen (ParamBean jParams, HashMap engineMap)        throws  JahiaException,                JahiaForbiddenAccessException    {        toDebug(">> CopyTree_Engine :: processCurrentScreen");        // gets the current screen        // screen   = source, target        String theScreen = (String) engineMap.get ("screen");        String operation = (String) engineMap.get ("operation");        if ( operation == null ){            operation = CHOOSE_OPERATION;        }        // dispatches to the appropriate sub engine        if (theScreen.equals ("save")) {            // set choiceID for the Page_Field engine : 3 for move/copy, 2 for link            HashMap   sharedEngineMap =  (HashMap) jParams.getRequest().getSession().getAttribute( "jahia_session_engineMap" );            if ( sharedEngineMap == null )                sharedEngineMap = new HashMap();            Integer   choiceID        =  new Integer(1);            if (operation.equals(MOVE_OPERATION)) {                choiceID = new Integer(3);            }            if (operation.equals(COPY_OPERATION)) {                choiceID = new Integer(5);                Integer  targetPageID  =  (Integer)   engineMap.get( "targetPageID"  );                Integer  sourcePageID  =  (Integer)   engineMap.get( SOURCEPAGE_ID  );                Integer  maxLevels     =  (Integer)   engineMap.get( "maxLevels"     );                // avoid copying target page over itself                if(getLevelsBetween(targetPageID.intValue(), sourcePageID.intValue()) >= maxLevels.intValue()) {                    ArrayList errors = (ArrayList)engineMap.get("errors");                    errors.add("Can't copy target page over itself... please restrict levels to be copied.");                    engineMap.put( "screen", "source" );                    engineMap.put( "jspSource", CHOOSESOURCE_JSP );                }            }            if ( !operation.equals(CHOOSE_OPERATION) ){                sharedEngineMap.put( "choiceID"+engineMap.get("fieldName"), choiceID );                sharedEngineMap.put( "fieldName", engineMap.get("fieldName") );                toDebug(">> CopyTree_Engine :: processCurrentScreen : choiceID_"+engineMap.get("fieldName")+": ["+choiceID+"]");            } else {                sharedEngineMap.put( SOURCEPAGE_ID, (Integer) engineMap.get(SOURCEPAGE_ID) );            }            if ( engineMap.get(ENGINE_LAUNCHER_NAME) != null )                sharedEngineMap.put(ENGINE_LAUNCHER_NAME , (String)engineMap.get(ENGINE_LAUNCHER_NAME) );            sharedEngineMap.put("operation",operation);            jParams.getRequest().getSession().setAttribute( "jahia_session_engineMap", sharedEngineMap );            // sets engineMap for JSPs            jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", sharedEngineMap );            // 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()));        }    } // end processCurrentScreen    /***        * get POST data from the JSP form        *        * @param        jParams             a ParamBean object        * @param        engineMap           the engine context        *        */    private boolean updateCopyData( ParamBean jParams, HashMap engineMap )    throws JahiaException    {        toDebug(">> CopyTree_Engine :: updateCopyData");        HttpSession sess            =  jParams.getSession();        String    errorMsg          =  (String)    engineMap.get( "errorMsg"      );        // generate sitemap Vector for JSP's        JahiaPage thePage           =  (JahiaPage) engineMap.get( "thePage"       );        JahiaData jData             =  (JahiaData) engineMap.get( "jData"         );        Integer   homePageID        =  (Integer)   engineMap.get( "homePageID"    );        Integer   sourcePageID      =  (Integer)   engineMap.get( SOURCEPAGE_ID   );        Integer   targetPageID      =  (Integer)   engineMap.get( "targetPageID"  );        String    theURL            =  jParams.settings().getJahiaEnginesHttpPath();        int       siteID            =  ((JahiaSite)jParams.getSession().getAttribute(ParamBean.SESSION_SITE)).getID();        int       viewLevels        =  4;        GenericTree  topTree        = tSrv.buildTree(homePageID.intValue(), viewLevels, jParams);        // if requested, collapse or extend branches, expanding them on the fly if necessary...        String  modif   = jParams.getRequest().getParameter( "modif"  );        String  pageID  = jParams.getRequest().getParameter( "pageid" );        if ((modif != null) && (pageID != null)) {            try {                topTree = (GenericTree) sess.getAttribute( "treeData_" + jParams.getSite().getSiteKey() );                if (topTree != null) {                    GenericTree subTree = topTree.getSubTree(Integer.parseInt(pageID), "org.jahia.services.pages.JahiaTreeViewPageWrapper");                    if (subTree != null) {                        Node node = subTree.getRoot();                        if (node != null) {                            JahiaTreeViewPageWrapper pageWrapper = (JahiaTreeViewPageWrapper) node.getData();                            if (modif.equals( "expand" )) {                                pageWrapper.expand();                                if(subTree.getChildren().size() == 0) {                                    topTree = tSrv.extendTree(Integer.parseInt(pageID), topTree, PageLoadFlags.DIRECT, 4, jParams);                                }                            } else if (modif.equals( "collapse" )) {                                pageWrapper.collapse();                            }                        }                    }                }            } catch (NumberFormatException nfe) {                JahiaConsole.println("SiteMap Engine", nfe.getMessage());            }        }        if ( (sourcePageID != null) && ( sourcePageID.intValue() != -1 ) ){            expandSourcePageBranch(sourcePageID.intValue(),topTree,jParams);        }        engineMap.put    ( "siteTree",                                    topTree      );//        engineMap.put    ( "targetBranch",                                targetBranch );        Vector outputTree = drawSubTree( engineMap, topTree, new Vector(), new Vector(), true, true);        engineMap.put    ( "treeData",                                    outputTree   );        sess.setAttribute( "treeData_" + jParams.getSite().getSiteKey(),  topTree      );        return true;    } // end updateCopyData    /***        * prepare a preview for a move tree operation        *        * @param        jParams             a ParamBean object        * @param        engineMap           the engine context        * @param        sourcePage          the <code>JahiaPage</code> object to be moved        * @param        targetPage          the <code>JahiaPage</code> to be made the new parent of the moved page        *        */    private boolean prepareMovePreview( ParamBean jParams, HashMap engineMap, JahiaPage sourcePage, JahiaPage targetPage )    throws JahiaException    {        toDebug(">> CopyTree_Engine :: prepareMovePreview ");        //////////////////////////////////////////////////////////////////////////        // FIXME -Mik-        //  is this needed ?        //////////////////////////////////////////////////////////////////////////        JahiaData jData             =  (JahiaData) engineMap.get("jData");//////////////////////////////////////////////////////////////////////////////////////  For the time being, we force the target to be the current page/////////////////////////////////////////////////////////////////////////////////////*        if(targetPageID == null) {            errorMsg = "No target page selected";            engineMap.put("errorMsg", errorMsg);            return false;        } else {            engineMap.put("errorMsg", null);        }*/        // build the treeList ( a Vector of {int pageID, int parentPageID} )        Vector      treeList      =  new Vector();        Vector      treeData      =  (Vector)  engineMap.get("tmpTreeData");        Enumeration treeDataEnum  =  treeData.elements();        Integer     homePageIDObj =  (Integer) engineMap.get("homePageID");        // treeList : array of record[] = { int pageID, int parentPageID, int origPageID }        while(treeDataEnum.hasMoreElements()) {            int[]   record        =  new int[3];            HashMap lineMap       =  (HashMap) treeDataEnum.nextElement();            Integer pageIDObj     =  (Integer)lineMap.get("pageID");            int     pageID        =  pageIDObj.intValue();

⌨️ 快捷键说明

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