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

📄 containerlisttag.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
package org.jahia.taglibs.container;import org.jahia.data.JahiaData;import org.jahia.data.containers.*;import org.jahia.exceptions.JahiaException;import org.jahia.taglibs.util.Utils;import org.jahia.utils.JahiaConsole;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;/** * Class ContainerListTag : initializes Jahia in order to display a container list. * *    A container list is a list of containers; container lists can be imbricated *    The name of the container list must be changed in this case, so that all the *    container lists of this page have an unique name * * @author  Jerome Tamiotti */public class ContainerListTag extends BodyTagSupport {    private String listName  =  "";    private String title  =  "";    private Vector fields = new Vector();    private JahiaContainerList containerList = null;    // we have two versions of these properties because we have to respect the    // JavaBeans design pattern.    private int intWindowSize = -1; // -1 means functionality is deactivated by default    private int intWindowOffset = -1;    private String windowSize;    private String windowOffset;    private JahiaData jData = null;    private boolean display = true;    private boolean declarationPass = true;    private boolean hasParent = false;    private String parentListName = "";    public boolean displayBody() {        return display;    }    public void setName(String name) {        this.listName = name;    }    public String getName() {        return this.listName;    }    public boolean isDeclarationPass() {        return declarationPass;    }    public void setTitle(String title) {        this.title = title;    }    public String getTitle() {        return this.title;    }    public int getSize() {        if ( this.getContainerList() != null )        {            return this.getContainerList().size();        }        return 0;    }    public void setWindowSize(String windowSize) {        try {            this.windowSize = windowSize;            this.intWindowSize = Integer.parseInt(windowSize);        } catch (NumberFormatException nfe) {            this.windowSize="";            this.intWindowSize = -1;        }    }    public String getWindowSize() {        return this.windowSize;    }    public void setWindowOffset(String windowOffset) {        try {            this.windowOffset = windowOffset;            this.intWindowOffset = Integer.parseInt(windowOffset);        } catch (NumberFormatException nfe) {            this.intWindowOffset = -1;        }    }    public String getWindowOffset() {        return this.windowOffset;    }    public Vector getFields() {        return this.fields;    }    public void addField(String fieldName) {        if (isDeclarationPass()) {            // JahiaConsole.println("ContainerListTag.addField",            //                      "Adding field <"+ fieldName + ">");            this.fields.add(fieldName);        } else {            JahiaConsole.println("ContainerListTag.addField",                                 "Not allowed to add field <" + fieldName +                                 "> when out of declaration pass, aborting...");        }    }    public JahiaContainerList getContainerList() {        if (isDeclarationPass()) {            JahiaConsole.println("ContainerListTag.getContainerList",                                 "ERROR : Can't call this in declaration phase, returning null...");            return null;        }        return this.containerList;    }    public int doStartTag() {        // default behavior is to activate declaration pass        declarationPass = true;        ServletRequest request = pageContext.getRequest();        jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");        if (jData == null) {            HashMap tempEngineMap = (HashMap) request.getAttribute("org.jahia.engines.EngineHashMap");            jData                 = (JahiaData) tempEngineMap.get("jData");        }        // but we must also test the case where this containerList is enclosed        // in a parent containerList in which case we just trickle down the        // state of the parent list...        ContainerListTag parentContainerListTag = (ContainerListTag) findAncestorWithClass(this,ContainerListTag.class);        if (parentContainerListTag != null) {            parentListName = parentContainerListTag.getName();            // we are in an embedded containerList tag, let's check in which            // pass we are...            declarationPass = parentContainerListTag.isDeclarationPass();            hasParent = true;            if (!declarationPass) {                JahiaConsole.println("ContainerListTag.doStartTag",                                     "Getting pass status from parent container list...IN DISPLAY MODE");                // let's do remaining initialisation necessary to do our work...                this.listName = Utils.buildUniqueName(parentListName, this.listName);                ContainerTag parentContainerTag = (ContainerTag) findAncestorWithClass(this,ContainerTag.class);                try {                    // this is not right we must attach the right instance of the container to the parent container...                    if (parentContainerTag != null) {                        JahiaContainer parentContainer = parentContainerTag.getContainer();                        if (parentContainer != null) {                            this.containerList = parentContainer.getContainerList(this.listName);                        } else {                            JahiaConsole.println("ContainerListTag.doStartTag",                                                 "Parent container not found...");                        }                    } else {                        JahiaConsole.println("ContainerListTag.doStartTag",                                             "Parent container tag not found...");                    }                } catch (JahiaException je) {                    JahiaConsole.println("ContainerListTag.doStartTag",je.toString());                }            } else {                JahiaConsole.println("ContainerListTag.doStartTag",                                     "Getting pass status from parent container list...IN DECLARATION MODE");            }        } else {        }        JahiaConsole.println("ContainerListTag.doStartTag",                             "Beginning declaration pass for container list '" +                             this.listName + "'");        return EVAL_BODY_BUFFERED;    }    // Body is evaluated one time, so just writes it on standard output    public int doAfterBody() {        if (declarationPass) {            declarationPass = false;            /* let's do all declarative pass stuff here */            if ((intWindowSize >= 1) && (intWindowOffset == -1)) {                // we allow a windowSize alone.                intWindowOffset = 0;            }            if ((intWindowSize >= 1) && (intWindowOffset >= 0) && (intWindowOffset < intWindowSize)) {                // let's set the parameter to be retrieved by the display                // system. This is why we do this at declaration time.                if (jData.params().getParameter("ctnscroll_" + this.listName) == null) {                    JahiaConsole.println("ContainerListTag.doAfterBody",                                         "Setting window parameters to window size " +                                         Integer.toString(this.intWindowSize) +                                         " and offset " +                                         Integer.toString(this.intWindowOffset));                    jData.params().setParameter("ctnscroll_" + this.listName,                                                Integer.toString(this.intWindowSize) +                                                "_" +                                                Integer.toString(this.intWindowOffset));                }            }            //  searches the current container list inside a container or at root            ContainerListTag parentContainerListTag = (ContainerListTag) findAncestorWithClass(this,ContainerListTag.class);            ContainerTag containerTag = (ContainerTag) findAncestorWithClass(this,ContainerTag.class);            if (parentContainerListTag != null) {                // we are in an embedded containerList tag, let's check in which                // pass we are...                if (parentContainerListTag.isDeclarationPass()) {                    JahiaConsole.println("ContainerListTag.doAfterBody",                                         "ContainerList has a parent container list in declaration pass");                    // builds the complete list name                    this.listName = Utils.buildUniqueName(parentContainerListTag.getName(), this.listName);                    // checks if the container list has been declared in the current container                    try {                        JahiaConsole.println("ContainerListTag.doAfterBody",                                             "Declaring embedded container list with name " +                                             this.listName + " title=" + this.title +                                             " size=" + this.fields.size());                        jData.containers().declareContainer(this.listName, this.title, this.fields, intWindowSize, intWindowOffset);                        this.display = false;                        return SKIP_BODY; // exit the parsing of this containerList while still in parent declaration pass...                        // update attribute                    } catch (JahiaException je) {                        JahiaConsole.println("ContainerListTag.doAfterBody",je.toString());                    }                } else {                    JahiaConsole.println("ContainerListTag.doAfterBody",                                         "ContainerList has a parent container list in display pass");                    // normally we should never reach this state...                }            } else {                // at root: WARNING : the container list can be absolute !                // that explains the usage of the methods "checkAttributes()" and "checkDeclaration()"                // whose code differs in case of absolute container list                try {                    // first, check if the list has been declared                    checkAttributes(jData);                    try {                        checkDeclaration(jData);                    } catch (JahiaException je) {                        JahiaConsole.println("ContainerListTag.doAfterBody",                                             "Container has already been defined, ignoring re-definition and loading content...");                    }                    // update attribute                    this.containerList = getContainerList(jData, this.listName);                } catch (JahiaException je) {                    JahiaConsole.println("ContainerListTag.doAfterBody",je.toString());                }            }            // JahiaConsole.println("ContainerListTag.doAfterBody","End of declaration pass for container list '" + this.listName + "'");            // let's clear the evaluated body content since we won't use it on this pass...            BodyContent body= getBodyContent();            body.clearBody();            return EVAL_BODY_BUFFERED;        }        // JahiaConsole.println("ContainerListTag.doAfterBody", "Post-Declaration Pass");        if (this.display) {            try {                bodyContent.writeOut(bodyContent.getEnclosingWriter());            } catch (IOException ioe) {                JahiaConsole.println("ContainerListTag: doAfterBody ", ioe.toString());            }        }        return SKIP_BODY;    }    // the methods below are defined in order to be overrided in the subclasses    // AbsoluteContainerListTag and RelativeContainerListTag    protected void checkAttributes(JahiaData jData) throws JahiaException {    }    protected void checkDeclaration(JahiaData jData) throws JahiaException {        /** @todo : this was commented out by Serge Huber         *  because the call to declareContainer already does these verifications         *  for us at the beginning of the call.         */        JahiaConsole.println("ContainerListTag.checkDeclaration",                             "Declaring container list with name " +                             this.listName + " title=" + this.title +                             " size=" + this.fields.size());        jData.containers().declareContainer(this.listName, this.title, this.fields, intWindowSize, intWindowOffset);        JahiaConsole.println("ContainerListTag.checkDeclaration",                             "End declareContainer call with name " +                             this.listName);    }    // reads the container list from a container set    protected JahiaContainerList getContainerList( JahiaData jData,                                                   String listName ) throws JahiaException {        return jData.containers().getContainerList(listName);    }    //--------------------------------------------------------------------------    /**     * Called by AbstractFieldTag to check if this container list already     * contains a field of the given name.     *     * Author NK     */    public boolean isFieldAlreadyDeclared(String name){        int size = fields.size();        String fieldName = "";        for ( int i=0 ; i<size ; i++ ){            fieldName = (String)fields.get(i);            if ( fieldName.equals(name) )                return true;        }        return false;    }}

⌨️ 快捷键说明

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