1 package org.jahia.deprecated.taglibs.container; 2 3 import java.io.IOException ; 4 import java.util.Enumeration ; 5 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.JspTagException ; 8 import javax.servlet.jsp.tagext.BodyTagSupport ; 9 10 import org.jahia.data.containers.JahiaContainer; 11 import org.jahia.data.containers.JahiaContainerList; 12 13 14 20 public class ContainerTag extends BodyTagSupport { 21 22 23 private Enumeration containers; 24 25 private boolean first = true; 26 private boolean last = true; 27 private JahiaContainer container = null; 28 private JahiaContainer firstContainer = null; 29 private int counter = 1; 30 31 private boolean initLoop = true; 32 33 private boolean display = true; 34 35 public boolean displayBody() { 36 return display; 37 } 38 39 public boolean isFirst() { 40 return this.first; 41 } 42 43 public boolean isLast() { 44 return this.last; 45 } 46 47 public JahiaContainer getContainer() { 48 return this.container; 49 } 50 51 public int getCounter() { 52 return this.counter; 53 } 54 55 public boolean isDeclarationPass() { 56 ContainerListTag cListTag = (ContainerListTag) getParent(); 58 if (cListTag == null) { 59 return false; 60 } else { 61 return cListTag.isDeclarationPass(); 62 } 63 } 64 65 66 public int doStartTag() { 67 initLoop = true; 68 69 ContainerListTag cListTag = (ContainerListTag) findAncestorWithClass(this, ContainerListTag.class); 70 if (cListTag.isDeclarationPass()) { 71 } else { 74 JahiaContainerList containerList = cListTag.getContainerList(); 75 if (containerList == null) 76 return SKIP_BODY; 77 78 if (initLoop) { 79 containers = containerList.getContainers(); 82 int ct = 0; 83 if (containers.hasMoreElements()) { 84 this.container = (JahiaContainer)containers.nextElement(); 85 if (getId() != null) { 86 pageContext.setAttribute(getId(), this.container); 87 } 88 if (ct == 0) { 89 this.firstContainer = this.container; 90 } 91 if (containers.hasMoreElements()) { 92 this.last = false; 93 } 94 } else { 95 this.counter = 0; 96 this.display = false; 97 } 98 containers = containerList.getContainers(); 99 if (containers.hasMoreElements()) { 100 this.container = (JahiaContainer) containers.nextElement(); 101 if (getId() != null) { 102 pageContext.setAttribute(getId(), this.container); 103 } 104 } else { 105 return SKIP_BODY; 106 } 107 initLoop = false; 108 } 109 } 110 return EVAL_BODY_BUFFERED; 111 } 112 113 114 public int doAfterBody() throws JspException { 116 ContainerListTag cListTag = (ContainerListTag) findAncestorWithClass(this, ContainerListTag.class); 118 if (cListTag.isDeclarationPass()) { 119 return SKIP_BODY; 122 } 123 124 128 129 130 if (this.display) { 131 try { 132 getBodyContent().writeOut(getPreviousOut()); 133 getBodyContent().clear(); 134 this.counter++; 135 } catch (IOException ioe) { 136 throw new JspTagException (); 137 } 138 if (containers.hasMoreElements()) { 139 this.container = (JahiaContainer)containers.nextElement(); 141 if (getId() != null) { 142 pageContext.setAttribute(getId(), this.container); 143 } 144 this.first = false; 146 if (!containers.hasMoreElements()) { 148 this.last = true; 149 } 150 return EVAL_BODY_BUFFERED; 151 } else { 152 this.display = false; 153 } 154 } 155 return SKIP_BODY; 156 } 157 158 public int doEndTag() throws JspException { 159 super.doEndTag(); 162 containers = null; 163 164 first = true; 165 last = true; 166 container = null; 167 firstContainer = null; 168 counter = 1; 169 170 initLoop = true; 171 172 display = true; 173 if (getId() != null) { 174 pageContext.removeAttribute(getId()); 175 } 176 return EVAL_PAGE; 177 } 178 179 180 } 181 | Popular Tags |