1 package org.jahia.deprecated.taglibs.container; 2 3 import java.io.IOException ; 4 import java.util.Vector ; 5 6 import javax.servlet.ServletRequest ; 7 import javax.servlet.jsp.JspException ; 8 import javax.servlet.jsp.tagext.BodyContent ; 9 import javax.servlet.jsp.tagext.BodyTagSupport ; 10 11 import org.jahia.data.JahiaData; 12 import org.jahia.data.containers.JahiaContainer; 13 import org.jahia.data.containers.JahiaContainerList; 14 import org.jahia.deprecated.taglibs.util.Utils; 15 import org.jahia.exceptions.JahiaException; 16 import org.jahia.utils.JahiaConsole; 17 18 19 20 29 public class ContainerListTag extends BodyTagSupport { 30 31 private String listName = ""; 32 private String title = ""; 33 private Vector fields = new Vector (); 34 private JahiaContainerList containerList = null; 35 36 private int intWindowSize = -1; private int intWindowOffset = -1; 40 41 private String windowSize; 42 private String windowOffset; 43 44 private JahiaData jData = null; 45 46 private boolean display = true; 47 private boolean declarationPass = true; 48 private boolean hasParent = false; 49 private String parentListName = ""; 50 51 52 public boolean displayBody() { 53 return display; 54 } 55 56 public void setName(String name) { 57 this.listName = name; 58 } 59 60 public String getName() { 61 return this.listName; 62 } 63 64 public boolean isDeclarationPass() { 65 return declarationPass; 66 } 67 68 public void setTitle(String title) { 69 this.title = title; 70 } 71 72 public String getTitle() { 73 return this.title; 74 } 75 76 public int getSize() { 77 if ( this.getContainerList() != null ) 78 { 79 return this.getContainerList().size(); 80 } 81 return 0; 82 } 83 84 public void setWindowSize(String windowSize) { 85 try { 86 this.windowSize = windowSize; 87 this.intWindowSize = Integer.parseInt(windowSize); 88 } catch (NumberFormatException nfe) { 89 this.windowSize=""; 90 this.intWindowSize = -1; 91 } 92 } 93 94 public String getWindowSize() { 95 return this.windowSize; 96 } 97 98 public void setWindowOffset(String windowOffset) { 99 try { 100 this.windowOffset = windowOffset; 101 this.intWindowOffset = Integer.parseInt(windowOffset); 102 } catch (NumberFormatException nfe) { 103 this.intWindowOffset = -1; 104 } 105 } 106 107 public String getWindowOffset() { 108 return this.windowOffset; 109 } 110 111 public Vector getFields() { 112 return this.fields; 113 } 114 115 public void addField(String fieldName) { 116 if (isDeclarationPass()) { 117 this.fields.add(fieldName); 120 } else { 121 JahiaConsole.println("ContainerListTag.addField", 122 "Not allowed to add field <" + fieldName + 123 "> when out of declaration pass, aborting..."); 124 } 125 } 126 127 public JahiaContainerList getContainerList() { 128 if (isDeclarationPass()) { 129 JahiaConsole.println("ContainerListTag.getContainerList", 130 "ERROR : Can't call this in declaration phase, returning null..."); 131 return null; 132 } 133 return this.containerList; 134 } 135 136 public int doStartTag() { 137 138 declarationPass = true; 140 141 ServletRequest request = pageContext.getRequest(); 142 jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 143 144 ContainerListTag parentContainerListTag = (ContainerListTag) findAncestorWithClass(this,ContainerListTag.class); 148 if (parentContainerListTag != null) { 149 parentListName = parentContainerListTag.getName(); 150 declarationPass = parentContainerListTag.isDeclarationPass(); 153 hasParent = true; 154 155 if (!declarationPass) { 156 JahiaConsole.println("ContainerListTag.doStartTag", 157 "Getting pass status from parent container list...IN DISPLAY MODE"); 158 this.listName = Utils.buildUniqueName(parentListName, this.listName); 160 ContainerTag parentContainerTag = (ContainerTag) findAncestorWithClass(this,ContainerTag.class); 161 try { 162 if (parentContainerTag != null) { 164 JahiaContainer parentContainer = parentContainerTag.getContainer(); 165 if (parentContainer != null) { 166 this.containerList = parentContainer.getContainerList(this.listName); 167 } else { 168 JahiaConsole.println("ContainerListTag.doStartTag", 169 "Parent container not found..."); 170 } 171 } else { 172 JahiaConsole.println("ContainerListTag.doStartTag", 173 "Parent container tag not found..."); 174 } 175 } catch (JahiaException je) { 176 JahiaConsole.println("ContainerListTag.doStartTag",je.toString()); 177 } 178 } else { 179 JahiaConsole.println("ContainerListTag.doStartTag", 180 "Getting pass status from parent container list...IN DECLARATION MODE"); 181 } 182 } else { 183 } 184 185 JahiaConsole.println("ContainerListTag.doStartTag", 186 "Beginning declaration pass for container list '" + 187 this.listName + "'"); 188 189 190 return EVAL_BODY_BUFFERED; 191 } 192 193 194 public int doAfterBody() { 196 197 if (declarationPass) { 198 declarationPass = false; 199 200 201 if ((intWindowSize >= 1) && (intWindowOffset == -1)) { 202 intWindowOffset = 0; 204 } 205 if ((intWindowSize >= 1) && (intWindowOffset >= 0) && (intWindowOffset < intWindowSize)) { 206 if (jData.params().getParameter("ctnscroll_" + this.listName) == null) { 209 JahiaConsole.println("ContainerListTag.doAfterBody", 210 "Setting window parameters to window size " + 211 Integer.toString(this.intWindowSize) + 212 " and offset " + 213 Integer.toString(this.intWindowOffset)); 214 jData.params().setParameter("ctnscroll_" + this.listName, 215 Integer.toString(this.intWindowSize) + 216 "_" + 217 Integer.toString(this.intWindowOffset)); 218 } 219 } 220 221 ContainerListTag parentContainerListTag = (ContainerListTag) findAncestorWithClass(this,ContainerListTag.class); 223 ContainerTag containerTag = (ContainerTag) findAncestorWithClass(this,ContainerTag.class); 224 if (parentContainerListTag != null) { 225 if (parentContainerListTag.isDeclarationPass()) { 228 JahiaConsole.println("ContainerListTag.doAfterBody", 229 "ContainerList has a parent container list in declaration pass"); 230 this.listName = Utils.buildUniqueName(parentContainerListTag.getName(), this.listName); 232 try { 234 JahiaConsole.println("ContainerListTag.doAfterBody", 235 "Declaring embedded container list with name " + 236 this.listName + " title=" + this.title + 237 " size=" + this.fields.size()); 238 jData.containers().declareContainer(this.listName, this.title, this.fields, intWindowSize, intWindowOffset); 239 this.display = false; 240 return SKIP_BODY; } catch (JahiaException je) { 243 JahiaConsole.println("ContainerListTag.doAfterBody",je.toString()); 244 } 245 } else { 246 JahiaConsole.println("ContainerListTag.doAfterBody", 247 "ContainerList has a parent container list in display pass"); 248 } 250 } else { 251 try { 255 checkAttributes(jData); 257 try { 258 checkDeclaration(jData); 259 } catch (JahiaException je) { 260 JahiaConsole.println("ContainerListTag.doAfterBody", 261 "Container has already been defined, ignoring re-definition and loading content..."); 262 } 263 this.containerList = getContainerList(jData, this.listName); 265 } catch (JahiaException je) { 266 JahiaConsole.println("ContainerListTag.doAfterBody",je.toString()); 267 } 268 } 269 270 BodyContent body= getBodyContent(); 273 body.clearBody(); 274 return EVAL_BODY_BUFFERED; 275 } 276 277 279 if (this.display) { 280 try { 281 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 282 } catch (IOException ioe) { 283 JahiaConsole.println("ContainerListTag: doAfterBody ", ioe.toString()); 284 } 285 } 286 return SKIP_BODY; 287 } 288 289 292 protected void checkAttributes(JahiaData jData) throws JahiaException { 293 } 294 295 protected void checkDeclaration(JahiaData jData) throws JahiaException { 296 300 JahiaConsole.println("ContainerListTag.checkDeclaration", 301 "Declaring container list with name " + 302 this.listName + " title=" + this.title + 303 " size=" + this.fields.size()); 304 jData.containers().declareContainer(this.listName, this.title, this.fields, intWindowSize, intWindowOffset); 305 JahiaConsole.println("ContainerListTag.checkDeclaration", 306 "End declareContainer call with name " + 307 this.listName); 308 309 } 310 311 protected JahiaContainerList getContainerList( JahiaData jData, 313 String listName ) throws JahiaException { 314 315 return jData.containers().getContainerList(listName); 316 } 317 318 325 public boolean isFieldAlreadyDeclared(String name){ 326 int size = fields.size(); 327 String fieldName = ""; 328 for ( int i=0 ; i<size ; i++ ){ 329 fieldName = (String )fields.get(i); 330 if ( fieldName.equals(name) ) 331 return true; 332 } 333 return false; 334 } 335 336 public int doEndTag() throws JspException { 337 listName = ""; 340 title = ""; 341 fields = new Vector (); 342 containerList = null; 343 344 intWindowSize = -1; intWindowOffset = -1; 346 347 windowSize = null; 348 windowOffset = null; 349 350 jData = null; 351 352 display = true; 353 declarationPass = true; 354 hasParent = false; 355 parentListName = ""; 356 return EVAL_PAGE; 357 } 358 359 360 } 361 | Popular Tags |