1 18 package org.apache.beehive.netui.tags.tree; 19 20 import org.apache.beehive.netui.tags.AbstractSimpleTag; 21 import org.apache.beehive.netui.tags.html.IUrlParams; 22 import org.apache.beehive.netui.tags.internal.PageFlowTagUtils; 23 import org.apache.beehive.netui.util.Bundle; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.PageContext ; 28 import javax.servlet.jsp.tagext.JspTag ; 29 import java.io.IOException ; 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 33 34 54 public class TreeItem extends AbstractSimpleTag implements IUrlParams 55 { 56 private String _action; private String _clientAction; private boolean _expanded; private boolean _expandOnServer; private boolean _disabled; private String _href; private String _scope; private String _icon; private TreeElement _treeElement; private String _target; private String _title; private String _tagId; private ArrayList _attributes; private InheritableState _state; 71 private boolean _child = false; private String _childLabel; private String _childContent; 75 76 79 public String getTagName() 80 { 81 return "TreeItem"; 82 } 83 84 86 95 public void setAction(String action) 96 throws JspException 97 { 98 _action = setRequiredValueAttribute(action, "action"); 99 } 100 101 110 public void setClientAction(String action) 111 throws JspException 112 { 113 _clientAction = setRequiredValueAttribute(action, "clientAction"); 114 } 115 116 125 public void setTagId(String tagId) 126 throws JspException 127 { 128 _tagId = setRequiredValueAttribute(tagId, "tagId"); 129 } 130 131 140 public void setExpanded(boolean expanded) 141 { 142 _expanded = expanded; 143 } 144 145 154 public void setDisabled(boolean disabled) 155 { 156 _disabled = disabled; 157 } 158 159 172 public void setExpandOnServer(boolean expandOnServer) 173 { 174 _expandOnServer = expandOnServer; 175 } 176 177 186 public void setHref(String href) 187 throws JspException 188 { 189 _href = setRequiredValueAttribute(href, "href"); 190 } 191 192 201 public void setTitle(String title) 202 { 203 _title = setNonEmptyValueAttribute(title); 204 } 205 206 223 public void setScope(String scope) 224 { 225 _scope = setNonEmptyValueAttribute(scope); 226 } 227 228 237 public void setIcon(String icon) 238 { 239 _icon = setNonEmptyValueAttribute(icon); 240 } 241 242 244 250 public void setItemLabel(String label) 251 { 252 _child = true; 253 _childLabel = label; 254 } 255 256 259 public void setItemContent(String content) 260 { 261 _child = true; 262 _childContent = content; 263 } 264 265 270 public void setItemAttribute(TreeHtmlAttributeInfo attr) 271 { 272 _child = true; 273 if (_attributes == null) 274 _attributes = new ArrayList (); 275 _attributes.add(attr); 276 } 277 278 public void setItemInheritableState(InheritableState state) 279 { 280 _child = true; 281 _state = state; 282 } 283 284 public void setAddedChild() 285 { 286 _child = true; 287 } 288 289 292 public TreeElement getNode() 293 { 294 return _treeElement; 295 } 296 297 306 public void setTarget(String target) 307 { 308 _target = target; 309 } 310 311 312 public void addParameter(String name, Object value, String facet) throws JspException 313 { 314 _treeElement.addParameter(name, value, facet); 315 } 316 317 318 320 324 public void doTag() 325 throws JspException , IOException 326 { 327 int have = 0; 330 if (_href != null) have++; 331 if (_action != null) have++; 332 if (have > 1) { 333 String s = Bundle.getString("Tags_Node_InvalidNode", new Object []{"href, action"}); 334 registerTagError(s, null); 335 } 336 337 PageContext pageContext = getPageContext(); 339 if (_action != null) { 340 HttpServletRequest request = (HttpServletRequest ) pageContext.getRequest(); 341 boolean isAction = PageFlowTagUtils.isAction(request, _action); 342 if (!isAction) { 343 registerTagError(Bundle.getString("Tags_BadAction", _action), null); 344 } 345 } 346 347 JspTag parentTag = getParent(); 349 if (parentTag instanceof Tree) { 350 _treeElement = new TreeRootElement(); 351 } 352 else { 353 _treeElement = new TreeElement(); 354 } 355 356 _treeElement.setIcon(_icon); 358 _treeElement.setClientAction(_clientAction); 359 _treeElement.setScope(_scope); 360 _treeElement.setTitle(_title); 361 _treeElement.setTagId(_tagId); 362 _treeElement.setExpandOnServer(_expandOnServer); 363 _treeElement.setExpanded(_expanded); 364 _treeElement.setDisabled(_disabled); 365 _treeElement.setTarget(_target); 366 _treeElement.setHref(_href); 367 _treeElement.setAction(_action); 368 369 boolean inlineError = false; 370 if (hasErrors()) { 371 String s = getInlineError(); 372 if (s == null) 373 s = Bundle.getString("Tags_TreeItemErrorNoInline"); 374 else 375 inlineError = true; 376 _treeElement.setContent(s); 377 } 378 379 if (parentTag instanceof Tree) { 381 Tree parentTree = (Tree) parentTag; 382 if (parentTree.getRootNode() != null) { 383 String s = Bundle.getString("Tags_TreeMultipleRootNodes"); 384 parentTree.registerTagError(s, null); 385 return; 387 } 388 parentTree.setRootNode(_treeElement); 389 } 390 else if (parentTag instanceof TreeItem) { 391 TreeItem parentNode = (TreeItem) parentTag; 392 parentNode.getNode().addChild(_treeElement); 393 parentNode.setAddedChild(); 394 } 395 else { 396 String s = Bundle.getString("Tags_InvalidNodeParent"); 398 registerTagError(s, null); 399 reportErrors(); 400 return; 401 } 402 403 String content = getBufferBody(true); 404 if (!_child) { 405 if (content != null) 406 _childLabel = content; 407 } 408 409 if (_childLabel != null) { 411 _treeElement.setLabel(_childLabel); 412 } 413 414 if (hasErrors()) { 415 if (!inlineError) 416 reportErrors(); 417 return; 418 } 419 420 if (_childContent != null) { 422 _treeElement.setContent(_childContent); 423 } 424 425 if (_state != null) { 427 _treeElement.setInheritableState(_state); 428 } 429 430 if (_attributes != null && _attributes.size() > 0) { 432 Iterator it = _attributes.iterator(); 433 while (it.hasNext()) { 434 TreeHtmlAttributeInfo jsi = (TreeHtmlAttributeInfo) it.next(); 435 _treeElement.addAttribute(jsi); 436 } 437 } 438 } 439 } 440 | Popular Tags |