1 package org.jahia.taglibs.declarations; 2 3 import java.util.Vector ; 4 5 import javax.servlet.ServletRequest ; 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.tagext.BodyContent ; 8 import javax.servlet.jsp.tagext.BodyTagSupport ; 9 10 import org.jahia.data.JahiaData; 11 import org.jahia.exceptions.JahiaException; 12 import org.jahia.resourcebundle.ResourceBundleMarker; 13 14 24 25 public class DeclareContainerListTag extends BodyTagSupport { 26 27 private static org.apache.log4j.Logger logger = 28 org.apache.log4j.Logger.getLogger(DeclareContainerListTag.class); 29 30 public DeclareContainerListTag () { 31 } 32 33 private String listName = ""; 34 private String title = ""; 35 36 private int intWindowSize = -1; private int intWindowOffset = -1; 40 41 private String windowSize; 42 private String windowOffset; 43 44 private String containerBeanName; 45 private String validatorKey; 46 47 private JahiaData jData = null; 48 private boolean hasParent = false; 49 private String parentListName = ""; 50 private String titleKey = null; 51 private String bundleKey = null; 52 private java.util.Vector children = new Vector (); 53 54 public void setName (String name) { 55 this.listName = name; 56 } 57 58 public String getName () { 59 return this.listName; 60 } 61 62 public void setTitle (String title) { 63 this.title = title; 64 } 65 66 public String getTitle () { 67 return this.title; 68 } 69 70 public void setWindowSize (String windowSize) { 71 try { 72 this.windowSize = windowSize; 73 this.intWindowSize = Integer.parseInt(windowSize); 74 } catch (NumberFormatException nfe) { 75 this.windowSize = ""; 76 this.intWindowSize = -1; 77 } 78 } 79 80 public String getWindowSize () { 81 return this.windowSize; 82 } 83 84 public void setWindowOffset (String windowOffset) { 85 try { 86 this.windowOffset = windowOffset; 87 this.intWindowOffset = Integer.parseInt(windowOffset); 88 } catch (NumberFormatException nfe) { 89 this.intWindowOffset = -1; 90 } 91 } 92 93 public String getWindowOffset () { 94 return this.windowOffset; 95 } 96 97 public String getTitleKey () { 98 return titleKey; 99 } 100 101 public void setTitleKey (String titleKey) { 102 this.titleKey = titleKey; 103 } 104 105 public String getBundleKey () { 106 return bundleKey; 107 } 108 109 public void setBundleKey (String bundleKey) { 110 this.bundleKey = bundleKey; 111 } 112 113 114 public void addChild (String childName) { 115 this.children.add(childName); 116 } 117 118 public int doStartTag () { 119 120 ServletRequest request = pageContext.getRequest(); 121 jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 122 123 DeclareContainerListTag parentDeclareContainerListTag = ( 127 DeclareContainerListTag) findAncestorWithClass(this, 128 DeclareContainerListTag.class); 129 if (parentDeclareContainerListTag != null) { 130 parentListName = parentDeclareContainerListTag.getName(); 131 hasParent = true; 132 } 133 134 logger.debug("Beginning declaration of container list '" + 135 this.listName + "'"); 136 137 return EVAL_BODY_BUFFERED; 138 } 139 140 public int doAfterBody () { 142 143 144 145 if ( (intWindowSize >= 1) && (intWindowOffset == -1)) { 146 intWindowOffset = 0; 148 } 149 if ( (intWindowSize >= 1) && (intWindowOffset >= 0) && 150 (intWindowOffset < intWindowSize)) { 151 if (jData.params().getParameter("ctnscroll_" + this.listName) == null) { 154 logger.debug("Setting window parameters to window size " + 155 Integer.toString(this.intWindowSize) + 156 " and offset " + 157 Integer.toString(this.intWindowOffset)); 158 jData.params().setParameter("ctnscroll_" + this.listName, 159 Integer.toString(this.intWindowSize) + 160 "_" + 161 Integer.toString(this. 162 intWindowOffset)); 163 } 164 } 165 166 DeclareContainerListTag parentDeclareContainerListTag = ( 168 DeclareContainerListTag) findAncestorWithClass(this, 169 DeclareContainerListTag.class); 170 DeclareContainerTag declareContainerTag = (DeclareContainerTag) 171 findAncestorWithClass(this, 172 DeclareContainerTag.class); 173 if (parentDeclareContainerListTag != null) { 174 176 try { 178 logger.debug("Declaring embedded container list with name " + 179 this.listName + " title=" + this.title + 180 " size=" + this.children.size()); 181 jData.containers().declareContainer(this.listName, resolveTitle(), 182 getChildren(), intWindowSize, intWindowOffset, validatorKey, 183 containerBeanName); 184 185 parentDeclareContainerListTag.addChild(this.listName); 186 187 return SKIP_BODY; } catch (JahiaException je) { 190 logger.error("Error:", je); 191 } 192 } else { 193 try { 197 checkAttributes(jData); 199 try { 200 checkDeclaration(jData); 201 } catch (JahiaException je) { 202 logger.info("Container has already been defined, ignoring re-definition and loading content..."); 203 } 204 } catch (JahiaException je) { 205 logger.error("Error:", je); 206 } 207 } 208 209 BodyContent body = getBodyContent(); 212 body.clearBody(); 213 return SKIP_BODY; 214 } 215 216 219 protected void checkAttributes (JahiaData jData) 220 throws JahiaException { 221 } 222 223 protected void checkDeclaration (JahiaData jData) 224 throws JahiaException { 225 logger.debug("Declaring container list with name " + 226 this.listName + " title=" + this.title + 227 " size=" + this.children.size()); 228 jData.containers().declareContainer(this.listName, resolveTitle(), 229 getChildren(), intWindowSize, 230 intWindowOffset, validatorKey, 231 containerBeanName); 232 233 logger.debug("End declareContainer call with name " + 234 this.listName); 235 236 } 237 238 245 public boolean isChildAlreadyDeclared (String name) { 246 int size = children.size(); 247 String fieldName = ""; 248 for (int i = 0; i < size; i++) { 249 fieldName = (String ) children.get(i); 250 if (fieldName.equals(name)) 251 return true; 252 } 253 return false; 254 } 255 256 public int doEndTag () 257 throws JspException { 258 listName = ""; 261 title = ""; 262 children = new Vector (); 263 264 intWindowSize = -1; intWindowOffset = -1; 266 267 windowSize = null; 268 windowOffset = null; 269 270 jData = null; 271 272 hasParent = false; 273 parentListName = ""; 274 275 titleKey = null; 276 bundleKey = null; 277 278 return EVAL_PAGE; 279 } 280 281 282 public java.util.Vector getChildren() { 283 return children; 284 } 285 286 private String resolveTitle() { 287 if ((titleKey != null) && (bundleKey != null)) { 288 return ResourceBundleMarker.drawMarker(bundleKey, titleKey, title); 289 } else { 290 return title; 291 } 292 } 293 294 297 public String getContainerBeanName() { 298 return containerBeanName; 299 } 300 301 304 public String getValidatorKey() { 305 return validatorKey; 306 } 307 308 311 public void setContainerBeanName(String string) { 312 containerBeanName = string; 313 } 314 315 318 public void setValidatorKey(String string) { 319 validatorKey = string; 320 } 321 } 322 | Popular Tags |