📄 containertag.java
字号:
package org.jahia.taglibs.container;import org.jahia.data.JahiaData;import org.jahia.data.containers.*;import org.jahia.exceptions.JahiaException;import org.jahia.utils.JahiaConsole;import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;/** * Class ContainerTag : retrieves the container list which it belongs to, loops through the * containers and displays the fields of each container * * @author Jerome Tamiotti */public class ContainerTag extends BodyTagSupport { private Enumeration containers; private boolean first = true; private boolean last = true; private JahiaContainer container = null; private JahiaContainer firstContainer = null; private int counter = 1; private boolean initLoop = true; private boolean display = true; public boolean displayBody() { return display; } public boolean isFirst() { return this.first; } public boolean isLast() { return this.last; } public JahiaContainer getContainer() { return this.container; } public int getCounter() { return this.counter; } public boolean isDeclarationPass() { // gets the current container list ContainerListTag cListTag = (ContainerListTag) getParent(); if (cListTag == null) { return false; } else { return cListTag.isDeclarationPass(); } } public int doStartTag() { initLoop = true; ContainerListTag cListTag = (ContainerListTag) getParent(); if (cListTag.isDeclarationPass()) { // JahiaConsole.println("ContainerTag.doStartTag", // cListTag.getName() + " : Declaration Pass Beginning..."); } else { JahiaContainerList containerList = cListTag.getContainerList(); if (containerList == null) return SKIP_BODY; if (initLoop) { // here is stuff we need to do only once... // reads the containers of this list containers = containerList.getContainers(); int ct = 0; if (containers.hasMoreElements()) { this.container = (JahiaContainer)containers.nextElement(); if (ct == 0) { this.firstContainer = this.container; } if (containers.hasMoreElements()) { this.last = false; } } else { this.counter = 0; this.display = false; } containers = containerList.getContainers(); if (containers.hasMoreElements()) { this.container = (JahiaContainer) containers.nextElement(); } else { return SKIP_BODY; } initLoop = false; } } return EVAL_BODY_BUFFERED; } // loops through the next elements public int doAfterBody() throws JspException { // gets the current container list ContainerListTag cListTag = (ContainerListTag) getParent(); if (cListTag.isDeclarationPass()) { //JahiaConsole.println("ContainerTag.doAfterBody", // cListTag.getName() + " : Declaration Pass Ended."); return SKIP_BODY; } /* JahiaConsole.println("ContainerTag.doAfterBody", cListTag.getName() + " : Post-declaration pass (counter=" + Integer.toString(this.counter) + ")"); */ if (this.display) { try { getBodyContent().writeOut(getPreviousOut()); getBodyContent().clear(); this.counter++; } catch (IOException ioe) { throw new JspTagException(); } if (containers != null){ if (containers.hasMoreElements()) { // JahiaConsole.println("ContainerTag.doAfterBody", "Processing next container in list"); this.container = (JahiaContainer)containers.nextElement(); // not the first one anymore this.first = false; // checks if it's the last one if (!containers.hasMoreElements()) { this.last = true; } return EVAL_BODY_BUFFERED; } else { this.display = false; } } } return SKIP_BODY; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -