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

📄 addcontainer_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        HashMap engineMap = new HashMap();        JahiaContainer  theContainer;        String theScreen = jParams.getRequest().getParameter ("screen");        toDebug("=== AddContainer_Engine :: initEngineMap :: screen ["+theScreen+"] ===");        // gets session values        //HttpSession theSession = jParams.getRequest().getSession( true );        HttpSession theSession = jParams.getSession();        // flag for subEngine: means that is a call from  AddContainer        theSession.setAttribute("AddContainer", "true");        // gets parent container id        String  parentIDStr = jParams.getRequest().getParameter ("cparentid");        int     parentID    = 0;        try {            parentID = Integer.parseInt( parentIDStr );        } catch (NumberFormatException nfe) {            String errorMsg = "Error in parameters : parentid (" + parentID + ") cannot be converted in int";            throw new JahiaException( "Error in parameters", errorMsg,                        JahiaException.DATA_ERROR, JahiaException.CRITICAL );        }        if (theScreen != null) {            // 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 {            // init engine map            engineMap = new HashMap();            // retrieve the choice ID if the screen is reloaded. Otherwise it should be set            // to a default value, to avoid having it set to 3 (tree operation) if no source            // page has been selected            String  reload   = (String) jParams.getRequest().getParameter("reload");            JahiaConsole.println(CLASS_NAME+".initEngineMap"," reload = " + reload);            if(reload != null) {                if(reload.equals("true")) {                    HashMap previousEngineMap = (HashMap) theSession.getAttribute( "jahia_session_engineMap" );                    if(previousEngineMap != null) {                        JahiaConsole.println(CLASS_NAME+".initEngineMap"," previous session is not null");                        String fieldName = jParams.getRequest().getParameter( "lastfname" );                        Integer choiceID = (Integer) previousEngineMap.get("choiceID"+fieldName);                        if( choiceID != null) {                            engineMap.put( "choiceID"+fieldName, choiceID );                            JahiaConsole.println(CLASS_NAME+".initEngineMap"," choiceID=" + choiceID.intValue() + " fieldName=" + fieldName);                        }                        JahiaField lastField = (JahiaField)previousEngineMap.get("theField");                        if ( lastField != null ){                            jParams.getRequest().setAttribute("lastField",lastField);                            JahiaConsole.println(CLASS_NAME+".initEngineMap","LastField is " + lastField.getID());                        }                        theSession.removeAttribute( "jahia_session_engineMap" );                    }                }            }            theContainer = createFakeContainer( jParams, engineMap );            theScreen = "edit";            engineMap.put( "theContainer", theContainer );            engineMap.put( "jParams", jParams );            engineMap.put( "containerParentID", new Integer(parentID) );            // init container list field acls            HashMap ctnListFieldAcls = getCtnListFieldAclMap(theContainer,jParams);            engineMap.put( "ctnListFieldAcls", ctnListFieldAcls );            engineMap.put( "ctnListVisibleFields", getCtnListVisibleFieldsMap(jParams,theContainer,jParams.getUser(),ctnListFieldAcls) );        }        engineMap.put("noApply", "");        engineMap.put( "renderType", new Integer(JahiaEngine.RENDERTYPE_FORWARD) );        engineMap.put( "engineName", engineName );        engineMap.put( "engineUrl", jParams.composeEngineUrl( engineName,                "?clistid=" + theContainer.getListID() +                "&cdefid=" + theContainer.getctndefid() +                "&cpid=" + theContainer.getPageID() +                "&cparentid=" + parentID ) );        theSession.setAttribute( "jahia_session_engineMap", engineMap );        // init map        engineMap.put( "screen", theScreen );        if (!theScreen.equals("save") && !theScreen.equals("cancel")) {            engineMap.put( "jspSource", TEMPLATE_JSP );        //} else if (theScreen.equals ("apply")) {        //    engineMap.put( "jspSource", "apply" );        } else {            engineMap.put( "jspSource", "close" );        }        // sets engineMap for JSPs        engineMap.put("fieldForms",new Hashtable());        jParams.getRequest().setAttribute( "engineTitle", "Add Container" );        jParams.getRequest().setAttribute( "org.jahia.engines.EngineHashMap", engineMap );        return engineMap;    } // end initEngineMap    /***        * composes the fake container        *        * @param        jParams             a ParamBean object (with request and response)        * @param        engineMap           the engine parameters        * @return       the fake container object        *        */    private JahiaContainer createFakeContainer( ParamBean jParams, HashMap engineMap )    throws JahiaException    {        JahiaContainer theContainer = null;        String  listIDStr   = jParams.getRequest().getParameter( "clistid" );        int     listID      = 0;        String  defIDStr    = jParams.getRequest().getParameter( "cdefid" );        int     defID       = 0;        String  pageIDStr   = jParams.getRequest().getParameter( "cpid" );        int     pageID      = 0;        try {            listID = Integer.parseInt( listIDStr );            defID  = Integer.parseInt( defIDStr );            pageID = Integer.parseInt( pageIDStr );        } catch (NumberFormatException nfe) {            String errorMsg = "Error in parameters : clistid (" + listIDStr                        + ") or cdefid (" + defIDStr + ") cannot be converted in int";            throw new JahiaException( "Error in parameters", errorMsg,                        JahiaException.DATA_ERROR, JahiaException.CRITICAL );        }        // source page        JahiaPage sourcePage = ServicesRegistry.getInstance().getJahiaPageService().lookupPage (pageID, jParams);        if (sourcePage == null) {            throw new JahiaException( "Page missing",                "Trying to add a container on a non-existing page (" + pageID + ")",                JahiaException.PAGE_ERROR, JahiaException.ERROR );        }        // creates container info        theContainer = new JahiaContainer(                        0, sourcePage.getJahiaID(), sourcePage.getID(),                        listID, 0, sourcePage.getAclID(), defID );        // creates fake fields        int fakeID = -1; // new single fields start at -1.        int pageDefID = sourcePage.getPageTemplateID();        Enumeration structure = theContainer.getDefinition().getStructure(                        "", pageDefID, JahiaContainerStructure.JAHIA_FIELD );        while (structure.hasMoreElements()) {            JahiaContainerStructure theStruct =                        (JahiaContainerStructure) structure.nextElement();            JahiaFieldDefinition theDef =                        (JahiaFieldDefinition) theStruct.getObjectDef();            theContainer.addField(                        createFakeField( theDef, sourcePage, listID, fakeID, engineMap , jParams) );            fakeID--;        }        toDebug("=== AddContainer_Engine :: createFakeContainer :: return ===");        return theContainer;    } // end createFakeContainer    /***        * composes a fake field        *        * @param        theDef              the field definition        * @param        thePage             the current JahiaPage object        * @param        listID              the container list id        * @param        fakeID              a fake id        * @param        engineMap           the engine parameters        *        * @return       the fake field object        *        */    private JahiaField createFakeField( JahiaFieldDefinition theDef,                        JahiaPage thePage, int listID, int fakeID,                        HashMap engineMap, ParamBean jParams )    throws JahiaException    {        int     ID          = fakeID;        int     jahiaID     = thePage.getJahiaID();        int     pageID      = thePage.getID();        int     ctnid = 0;        int     fieldDefID  = theDef.getID();        int     fieldType   = theDef.getType( thePage.getPageTemplateID() );        int     connectType = 0;        String  fieldValue  = theDef.getDefaultValue( thePage.getPageTemplateID() );        // to avoid to display the undefined field default value        if (fieldValue != null && fieldValue.toUpperCase().indexOf("JAHIA_MASKTYPE") != -1)        {            fieldValue = "";        }        // MJ : for tree copy        if( (engineMap.get("choice") != null) && (engineMap.get(CopyTree_Engine.SOURCEPAGE_ID) != null) ) {            if( ((Integer) engineMap.get("choiceID")).intValue() == 3 ) {                fieldValue  = (String) engineMap.get(CopyTree_Engine.SOURCEPAGE_ID);            }        }        int     rank        = 0;        int     aclID       = 0;        // used in SmallText & Bigtext's handleField method        //JahiaConsole.println("AddContainer_Engine.createFakeField"," defName=" + theDef.getName() );        engineMap.put( theDef.getName() + "_rawData", Boolean.TRUE );        // returns new JahiaField        toDebug("call createField - fieldType: " + fieldType);        JahiaField theField = ServicesRegistry.getInstance().                               getJahiaFieldService().                               createJahiaField( ID, jahiaID, pageID,                               ctnid, fieldDefID, fieldType,                               connectType, fieldValue, rank, aclID );        return theField;        //return new JahiaField( ID, jahiaID, pageID,        //                ctnid, fieldDefID, fieldType,        //                connectType, fieldValue, rank, aclID );    } // end createFakeField    //--------------------------------------------------------------------------    /**     * Return the first available field ( at least with READ or WRITE or ADMIN permission for a given user ).     * If the startFieldID is itselft visible, return it. Else look for the next available field.     * @param JahiaContainer the container     * @param JahiaUser the user to check access     * @param HashMap aclsMap, the key is the fieldID and the value is the aclID     * @param startFieldID     * @return int, the first visible field id else returns 0     * @author Khue Nguyen     */    static public int getFirstVisibleField( JahiaContainer theContainer,                                            ParamBean jParams,                                            HashMap engineMap,                                            JahiaUser user,                                            HashMap aclsMap, int startFieldID ){        JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","Started for user[" + user.getUsername() + "] and start field id[" + startFieldID + "]");        if ( theContainer.getListID()!=0 ){            // this could be a patch for old database without container list properties            if ( aclsMap.size()==0 ){                // this should not, so create missing acl.                JahiaContainerList cList = null;                try {                    cList = ServicesRegistry.getInstance().                        getJahiaContainersService().loadContainerListInfo( theContainer.getListID() );                    if ( cList != null ){                        JahiaConsole.println(CLASS_NAME+".getFirstVisibleField","container list ["+ cList.getID()+"]");                        String prop = null;                        JahiaField aField = null;                        Enumeration fList = theContainer.getFields();                        while (fList.hasMoreElements())

⌨️ 快捷键说明

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