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

📄 updatecontainer_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        int     fieldID     = -1;        Integer fieldInt;        try {            fieldID = Integer.parseInt( fieldIDStr );        } catch (NumberFormatException nfe) {            try {                fieldID = (((Integer)engineMap.get( "field_id" ))).intValue();            } catch (Exception e) {                fieldID = -1;            }        }        /*        if ( fieldID == -1 ){            Enumeration fields = theContainer.getFields();            if (fields.hasMoreElements()) {                fieldID = ((JahiaField) fields.nextElement()).getID();            }        }        */        // get first visible field        fieldID = AddContainer_Engine.getFirstVisibleField(theContainer,jParams,engineMap,jParams.getUser(),(HashMap)engineMap.get("ctnListFieldAcls"),fieldID);        if ( fieldID !=0 )            theField = theContainer.getField(fieldID);        JahiaField selectedField = theField;        engineMap.put( "field_id", new Integer(fieldID) );        if (theScreen.equals( "edit" ))  {            Vector neighbourSimpleFields = new Vector();            Vector fieldIDs = new Vector();            if ( theField != null ){                // at least one visible field                if ( theField instanceof JahiaSimpleField ) {                    // multiple simple field edit                    neighbourSimpleFields = AddContainer_Engine.getNeighbourSimpleFields(theContainer,fieldID,true,(HashMap)engineMap.get("ctnListVisibleFields"));                    // dispatches to the appropriate sub engine                    int size = neighbourSimpleFields.size();                    Integer I = null;                    for ( int i=0 ; i<size ; i++ ){                        I = (Integer) neighbourSimpleFields.get(i);                        theField = theContainer.getField(I.intValue());                        if ( theField != null ){                            engineMap.put("fieldForm",null); // reset field form                            HashMap map = (HashMap)engineMap.get("ctnListVisibleFields");                            if ( map == null )                                map = new HashMap();                            boolean visible = ( (theContainer.getListID()==0) || (map.get(new Integer(theField.getID()))!=null) );                            if ( visible ){                                // JahiaConsole.println(CLASS_NAME+".processCurrentScreen",                                //                      "the field value is now [" + theField.getValue() + "]" );                                engineMap.put( "theField", theField );                                engineMap.put( "isSelectedField", new Boolean(theField.getID()==fieldID) );                                engineMap.put( "fieldID", new Integer(theField.getID()) );                                toolBox.processFieldTypes( jParams, mode, engineMap );                            }                            if ( engineMap.get("fieldForm") != null ){                                fieldIDs.add(new Integer(theField.getID()));                                Hashtable fieldForms = (Hashtable)engineMap.get("fieldForms");                                fieldForms.put(new Integer(theField.getID()),(String)engineMap.get("fieldForm"));                            }                        }                    }                } else {                    // single field edit                    // JahiaConsole.println(CLASS_NAME+".processCurrentScreen",                    //                      "the field value is now [" + theField.getValue() +" ]");                    engineMap.put( "theField", theField );                    engineMap.put( "isSelectedField", new Boolean(theField.getID()==fieldID) );                    engineMap.put( "fieldID", new Integer(theField.getID()) );                    toolBox.processFieldTypes( jParams, mode, engineMap );                    if ( engineMap.get("fieldForm") != null ){                        fieldIDs.add(new Integer(theField.getID()));                        Hashtable fieldForms = (Hashtable)engineMap.get("fieldForms");                        fieldForms.put(new Integer(theField.getID()),(String)engineMap.get("fieldForm"));                    }                }            }            engineMap.put( "fieldID", new Integer(fieldID) );            engineMap.put( "theField", selectedField );            engineMap.put( "fieldIDs", fieldIDs );            engineMap.put( "simpleFieldIDs", neighbourSimpleFields );        } else if (theScreen.equals("logs")) {            toolBox.loadLogData( jParams, LoggingEventListener.CONTAINER_TYPE, engineMap );        } else if (theScreen.equals("rightsMgmt")) {            if (engineMap.get("adminAccess") != null) {                ManageRights.getInstance().handleActions( jParams, mode, engineMap, theContainer.getAclID() );            } else {                throw new JahiaForbiddenAccessException();            }        } else if (theScreen.equals("save") || theScreen.equals ("apply")) {            mode = JahiaEngine.SAVE_MODE;            // save the container info            JahiaContainerList theList = ServicesRegistry.getInstance().                getJahiaContainersService().loadContainerListInfo( theContainer.getListID() );            // 0 for parentAclID in saveContainerInfo, because container already exists            //  -> container already has an aclID            //  -> no need to create a new one            ServicesRegistry.getInstance().getJahiaContainersService().                        saveContainerInfo( theContainer, theList.getParentEntryID(), 0, jParams );            // save fields, one by one            Enumeration fields = theContainer.getFields();            while (fields.hasMoreElements()) {                JahiaField containerField = (JahiaField) fields.nextElement();                JahiaConsole.println(CLASS_NAME+".processCurrentScreen",                                     "Saving container field " + containerField.getDefinition().getName() + "..." );                containerField.setctnid( theContainer.getID() );                engineMap.put( "theField", containerField );                toolBox.processFieldTypes( jParams, mode, engineMap );            }            // save rights            if (engineMap.get("adminAccess") != null) {                engineMap.put("logObjectType", Integer.toString(LoggingEventListener.CONTAINER_TYPE));                engineMap.put("logObject", theContainer);                //ViewRights.getInstance().handleActions( jParams, mode, engineMap, theContainer.getAclID() );                ManageRights.getInstance().handleActions( jParams, mode, engineMap, theContainer.getAclID() );            }            // 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...            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(CLASS_NAME+".processCurrentScreen",                                     "Why is cross ref list empty ?");            }            // this is still necessary in the case we are on the page itself            // and the containerList is not referenced in an absolute way.            ServicesRegistry.getInstance().getCacheServerService().                removeEntry(Integer.toString(jParams.getPageID()));            // fire event            JahiaEvent theEvent = new JahiaEvent( this, jParams, theContainer );            ServicesRegistry.getInstance().getJahiaEventService().fireUpdateContainer(theEvent);            // flag for subEngine: means that is a call from  updateContainer, reset the flag            jParams.getSession().setAttribute("UpdateContainer", "false");            /*            // Hollis : set the container anchor            jParams.setAnchor("container_" + theField.getID());            engineMap.put( "theContainer", theContainer );            engineMap.put( "engineOutputFile", this.CLOSE_JSP );            */            if (theScreen.equals ("apply")) {                engineMap.put( "screen", (String)jParams.getRequest().getParameter("lastscreen"));            }            JahiaConsole.println(CLASS_NAME+".processCurrentScreen", "Changes applied and saved !");        } else if (theScreen.equals ("cancel")) {            ///////////////////////////////////////////////////////////////////////////////////////            // FIXME -Fulco-            //            //      Add here code to release the update lock on the related object            //      (page/container/...).            //            ///////////////////////////////////////////////////////////////////////////////////////            // flag for subEngine: means that is a call from  updateContainer, reset the flag            jParams.getSession().setAttribute("UpdateContainer", "false");        }    } // end processCurrentScreen    /***        * 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();        JahiaConsole.println(CLASS_NAME+".initEngineMap","Start initEngineMap");        // flag for subEngine: means that is a call from  updateContainer        jParams.getSession().setAttribute("UpdateContainer", "true");        JahiaContainer  theContainer;        String theScreen   = jParams.getRequest().getParameter( "screen" );        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 );        }        // gets session values        //HttpSession theSession = jParams.getRequest().getSession( true );        HttpSession theSession = jParams.getSession();        engineMap = (HashMap) theSession.getAttribute( "jahia_session_engineMap" );        // get the choiceID from copytreeEngine        Integer choiceID = null;        String fieldName = "";        if (engineMap != null)        {            fieldName = (String) engineMap.get("fieldName");            choiceID = (Integer) engineMap.get("choiceID"+fieldName);        }        JahiaConsole.println("UpdateContainer_Engine.initEngineMap","choiceId("+fieldName+"): "+choiceID);        if (theScreen != null) {            JahiaConsole.println(CLASS_NAME+".initEngineMap", "The Screen is not null, load it from session");            // if no, load the container 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 {            JahiaConsole.println("UpdateContainer_Engine.initEngineMap","the Screen is null load from storage");            theContainer = ServicesRegistry.getInstance().getJahiaContainersService().                        loadContainer( ctnid, LoadFlags.ALL, jParams );			// let's order the container fields in the exact order in which they are decrared in the template			// ( not as in the order in which they are stored in db )			if ( theContainer != null ){				theContainer.fieldsStructureCheck(jParams);			}            theScreen = "edit";            // init engine map            engineMap = new HashMap();            engineMap.put( "theContainer", theContainer );            engineMap.put( "jParams", jParams );            // set choiceID in engineMap            if( choiceID != null)            {                engineMap.put( "choiceID"+fieldName, choiceID );            }            // init container list field acls            HashMap ctnListFieldAcls = AddContainer_Engine.getCtnListFieldAclMap(theContainer,jParams);            engineMap.put( "ctnListFieldAcls", ctnListFieldAcls );            engineMap.put( "ctnListVisibleFields", AddContainer_Engine.getCtnListVisibleFieldsMap(jParams,theContainer,jParams.getUser(),ctnListFieldAcls) );        }        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", "close" );        } else if (theScreen.equals ("apply")) {            engineMap.put( "jspSource", "apply" );        } else if (theScreen.equals ("cancel")) {            engineMap.put( "jspSource", "close" );        } else {            engineMap.put( "jspSource", TEMPLATE_JSP );        }        // sets engineMap for JSPs        engineMap.put("fieldForms",new Hashtable());        jParams.getRequest().setAttribute( "engineTitle", "Update Container" );        jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", engineMap );        return engineMap;    } // end initEngineMap} // end UpdateContainer_Engine

⌨️ 快捷键说明

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