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

📄 jahiacontainerset.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @param        windowSize      an integer specifying the size of the     * display window in number of containers. Valid values are >= 1, -1 to     * deactivate this feature     * @param        windowOffset    an integer specifying the offset in the     * list of containers, to be used only when windowSize >= 1. Valid values are     * >= 0, and -1 is used to deactivate this feature     *     * @exception    raises a critical JahiaException if the container has been already declared     * @exception    raises a critical JahiaException if one of the containerFields have not been declared     * @exception    raises a critical JahiaException if one of the fields has the same name as the container     *     * In order to let a container include itself, the keyword "_self" in the containeFields must be used.     *     */    public void declareContainer( String containerName, String containerTitle,                                  Vector containerFields, int windowSize,                                  int windowOffset )    throws JahiaException {        // ensure that the data provided by the user has no special chars in it        containerName    = FormDataManager.getInstance().encode( containerName );        containerTitle   = FormDataManager.getInstance().encode( containerTitle );        // check if a container has already been declared with the same name        if ((!checkDeclared(containerName)) &&        // checks if container name and title are not empty            (!containerName.equals("")) && (!containerTitle.equals("")) &&        // checks if a field has not the same name            (!jData.fields().checkDeclared(containerName)) && (!checkDeclaredField(containerName)))        {            // first, let's check that all the fields in the containerFields exist            for (int i=0; i < containerFields.size(); i++) {                String theName = (String) containerFields.elementAt(i);                if (theName.equals("_self")) {                    containerFields.setElementAt( containerName, i );                } else if ((!checkDeclared(theName)) && (!checkDeclaredField(theName))) {                    // one of the fields or containers in containerFields doesn't exist !!                    String errorMsg = "Element not defined in container " + containerName + " : " + theName;                    JahiaConsole.println( "JahiaContainerSet.declareContainer", errorMsg + " -> BAILING OUT" );                    throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                    JahiaException.CRITICAL );                }            }            // second, let's build the property set of the container definition            Properties ctnDefProperties = new Properties();            if ( (windowSize >= 1) ) {                if (windowOffset < 0) {                    windowOffset = 0;                }                ctnDefProperties.setProperty("windowSize", Integer.toString(windowSize));                ctnDefProperties.setProperty("windowOffset", Integer.toString(windowOffset));            }            // third, let's check to see if the declared container has already a container definition in the            // ContainersDefinitionsRegistry            JahiaContainerDefinition aDef = JahiaContainerDefinitionsRegistry.getInstance().getDefinition( jData.params().getSiteID(), containerName );            int pageDefID = jData.params().getPage().getPageTemplateID();            if (aDef != null) {                // okay, it seems the definition already exists.                // now has it the same data than in the database ?                boolean havePropertiesChanged = aDef.mergeProperties(ctnDefProperties);                // checks if title changed                if ( (!aDef.getTitle(pageDefID).equals(containerTitle)) ||                // checks if structure changed                     (aDef.structureChanged( containerFields, pageDefID )) ||                     (havePropertiesChanged) ) {                    // well, data is not the same in the registry and in the declare() method !                    // this means the user has changed the container declaration in the template...                    aDef.setTitle( containerTitle, pageDefID );                    aDef.composeStructure( containerFields, pageDefID );                    // okay, let's synchronize the data between :                    //  - the template declaration (file)                    //  - the database declaration (database)                    //  - the registry declaration (memory)                    JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );                    /** @todo we should now reload the container list since a lot                     *  of things have changed, including window parameters.                     */                    if (havePropertiesChanged) {                        JahiaConsole.println("JahiaContainerSet.declareContainer",                                             "Reloading containerList "+                                             containerName + "...");                        // small hack to avoid doing this everywhere and to                        // be able to call checkDeclared in the next call...                        declaredContainers.add( containerName );                        containerLists.remove(containerName);                        getContainerList(containerName);                        // hack, will be added below...                        declaredContainers.remove(containerName);                    }                }            } else {                // hell, the definition doesn't exist in the memory !                // this can mean two things :                //  - either this is the first time Jahia encounters this template                //  - or the database data was screwed                // in any case, we got to :                //  - add it into the registry (memory)                //  - add it into the database (database)                //  - change the values in jData (memory)                Hashtable subDefs = new Hashtable();                JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition( 0, pageDefID, containerTitle, null );                subDefs.put( new Integer(pageDefID), subDef );                aDef = new JahiaContainerDefinition( 0, jData.params().getPage().getJahiaID(),                                                containerName, subDefs );                // insert new properties.                aDef.setProperties(ctnDefProperties);                JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );                aDef.composeStructure( containerFields, pageDefID );                JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );                /*                Hashtable subDefs = new Hashtable();                JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition( 0, pageDefID, containerTitle, null );                subDef.composeStructure( containerFields );                subDefs.put( new Integer(pageDefID), subDef );                aDef = new JahiaContainerDefinition( 0, jData.params().getPage().getJahiaID(),                                                containerName, subDefs );                JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );                */            }            // fourth, we declare that the container has been loaded, in order to avoid double definitions            declaredContainers.add( containerName );            // last, we create a new fake container list if the container list is empty            if (getContainerList(containerName) == null) {                // we create a fake container list, and save it into memory                JahiaContainerList fakeContainerList = new JahiaContainerList( 0, 0, jData.params().getPage().getID(),                            aDef.getID(), 0 );                addContainerList( fakeContainerList );            }        } else {            // the container is already declared, or has a null name/title : let the user have it... ;)            String errorMsg = "Container already declared or has a null name - title : " + containerName;            JahiaConsole.println( "JahiaContainerSet.declareContainer", errorMsg + " -> BAILING OUT" );            throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                    JahiaException.CRITICAL );        }    }    //-------------------------------------------------------------------------    /** @todo fix this implementation. It is extremely costly in performance. */    /***        * enables a jahia template developer to update a container definition        * used in the Jahia custom tag : org.jahia.tags.jahia.containers.ContainerListTag        *        * When meeting in a template the custom tag "<containerList>", Jahia declares a new        * container with empty field list; but after reading the <field> or <containerList>        * tags enclosed in the <containerList> tag, the container definition must be updated        * in order to add these fields and/or containers.        *        * @param        containerName   the container name        * @param        containerTitle  the container title        * @param        containerFields the fields (or containers) in the container        *        * @exception    raises a critical JahiaException if one of the containerFields have not been declared        * @exception    raises a critical JahiaException if one of the fields has the same name as the container        *        * In order to let a container include itself, the keyword "_self" in the containerFields must be used.        *        * @author  Jerome Tamiotti        */    public void updateContainerDefinition( String containerName,                                           String containerTitle,                                           Vector containerFields )    throws JahiaException    {        JahiaConsole.println("JahiaContainerSet.updateContainerDefinition",                             "Updating definition for container name=" + containerName +                             " title=" + containerTitle +                             " with " + Integer.toString(containerFields.size()) + " fields");        // checks if container name and title are not empty        if ( (!containerName.equals("")) && (!containerTitle.equals("")) &&             // checks if a field has not the same name            (!jData.fields().checkDeclared(containerName)) && (!checkDeclaredField(containerName)) )        {            // first, let's check that all the fields in the containerFields exist            for (int i=0; i < containerFields.size(); i++) {                String theName = (String) containerFields.elementAt(i);                if (theName.equals("_self")) {                    containerFields.setElementAt( containerName, i );                } else if ((!checkDeclared(theName)) && (!checkDeclaredField(theName))) {                    // one of the fields or containers in containerFields doesn't exist !!                    String errorMsg = "Element not defined in container " + containerName + " : " + theName;                    JahiaConsole.println( "JahiaContainerSet.updateContainerDefinition", errorMsg + " -> BAILING OUT" );                    throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                    JahiaException.CRITICAL );                }            }            // Retrieves the container definition in the registry            JahiaContainerDefinition aDef = JahiaContainerDefinitionsRegistry.getInstance().getDefinition( jData.params().getSiteID(), containerName );            int pageDefID = jData.params().getPage().getPageTemplateID();            if (aDef != null) {                if (!aDef.structureChanged(containerFields, pageDefID)) {                    // structure has not changed, let's exit right now...                    JahiaConsole.println("JahiaContainerSet.updateContainerDefinition",                                         "No changes in definition of " + containerTitle + ", updating cancelled");                    return;                }                // update structure                aDef.composeStructure( containerFields, pageDefID );                JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );            } else {                // hell, the definition doesn't exist in the memory !                // declare it !                JahiaConsole.println("JahiaContainerSet.updateContainerDefinition",                                     "Meeting with a new container definition for the very first time, let's create " + containerTitle + "...");                Hashtable subDefs = new Hashtable();                JahiaContainerSubDefinition subDef = new JahiaContainerSubDefinition( 0, pageDefID, containerTitle, null );                subDefs.put( new Integer(pageDefID), subDef );                aDef = new JahiaContainerDefinition( 0, jData.params().getPage().getJahiaID(),                                                containerName, subDefs );                JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef ); /** @todo FIXME : do we really need this twice ? */                aDef.composeStructure( containerFields, pageDefID );                JahiaContainerDefinitionsRegistry.getInstance().setDefinition( aDef );            }            // third, we declare that the container has been loaded, in order to avoid double definitions            declaredContainers.add( containerName );            // last, we create a new fake container list if the container list is empty            if (getContainerList(containerName) == null) {                // we create a fake container list, and save it into memory                JahiaContainerList fakeContainerList = new JahiaContainerList( 0, 0, jData.params().getPage().getID(),                            aDef.getID(), 0 );                addContainerList( fakeContainerList );            }        } else {            // the container is already declared, or has a null name/title : let the user have it... ;)            String errorMsg = "Container has a null name - title : " + containerName;            JahiaConsole.println( "JahiaContainerSet.updateContainerDefinition", errorMsg + " -> BAILING OUT" );            throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                    JahiaException.CRITICAL );        }    } // end updateContainerDefinition    //-------------------------------------------------------------------------    /***        * checks if a container has already been declared        * Note : we don't need to call this before a container declaration,        * this is already done in the declareContainer implementation        *        * @param        containerName   the container name        * @return       true if already declared, false if not        *        */    public boolean checkDeclared( String containerName )    {        return declaredContainers.contains(containerName);    } // end checkDeclared    //-------------------------------------------------------------------------    /***        * checks if a container field has already been declared        * Note : we don't need to do this before a container declaration. This        * is already done for us in the declareContainer and declareField        * implementations.        *        * @param        containerName   the container name        * @return       true if already declared, false if not        *        */    public boolean checkDeclaredField( String fieldName )    {        return declaredFields.contains(fieldName);    } // end checjDeclaredField    //-------------------------------------------------------------------------    /***        * gets the first occurence of a container list        *        * @param        containerName   the container name        * @return       a JahiaContainer object        * @see          org.jahia.data.containers.JahiaContainer        *        */    public JahiaContainer getContainer( String containerName )    throws JahiaException    {        return getContainer( containerName, 0 );    } // end getContainer    //-------------------------------------------------------------------------    /***        * gets an occurence of a container list        *        * @param        containerName   the container name        * @param        index           the occurence        * @return       a JahiaContainer object        * @see          org.jahia.data.containers.JahiaContainer        *        * @exception    raises a critical JahiaException if container not found        *        */    public JahiaContainer getContainer( String containerName, int index )    throws JahiaException    {    	checkContainerStructure();        if (checkDeclared( containerName ))        {            JahiaContainerList theContainerList = (JahiaContainerList) containerLists.get( containerName );            if (theContainerList != null) {                JahiaContainer theContainer = theContainerList.getContainer( index );                if (theContainer != null) {                    return theContainer;                } else {                    String errorMsg = "Container is null : " + containerName + "[" + index + "] -> BAILING OUT";                    JahiaConsole.println( "JahiaContainerSet.getContainer", errorMsg );                    throw new JahiaException( "Error while returning field " + containerName, errorMsg,                                                JahiaException.TEMPLATE_ERROR, JahiaException.CRITICAL );                }            } else {                String errorMsg = "Container not declared : " + containerName;                JahiaConsole.println( "JahiaContainerSet.getContainer", errorMsg + " -> BAILING OUT" );                throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                        JahiaException.CRITICAL );            }        } else {            String errorMsg = "Container not declared : " + containerName;            JahiaConsole.println( "JahiaContainerSet.getContainer", errorMsg + " -> BAILING OUT" );

⌨️ 快捷键说明

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