| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| WOConditional |
|
| 1.9;1.9 |
| 1 | /* |
|
| 2 | Wotonomy: OpenStep design patterns for pure Java applications. |
|
| 3 | Copyright (C) 2000 Blacksmith, Inc. |
|
| 4 | ||
| 5 | This library is free software; you can redistribute it and/or |
|
| 6 | modify it under the terms of the GNU Lesser General Public |
|
| 7 | License as published by the Free Software Foundation; either |
|
| 8 | version 2.1 of the License, or (at your option) any later version. |
|
| 9 | ||
| 10 | This library is distributed in the hope that it will be useful, |
|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 13 | Lesser General Public License for more details. |
|
| 14 | ||
| 15 | You should have received a copy of the GNU Lesser General Public |
|
| 16 | License along with this library; if not, see http://www.gnu.org |
|
| 17 | */ |
|
| 18 | ||
| 19 | package net.wotonomy.web; |
|
| 20 | ||
| 21 | import net.wotonomy.foundation.NSDictionary; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * WOConditional renders whatever is inside its opening and closing tags |
|
| 25 | * only if a condition is met. |
|
| 26 | * Bindings are: |
|
| 27 | * <ul> |
|
| 28 | * <li>condition: a boolean property that indicates whether the contents of the element |
|
| 29 | * should be displayed, invoked, or passed the request form values.</li> |
|
| 30 | * <li>negate: if this is true, then the behavior of the element is reversed, showing its |
|
| 31 | * contents only if the condition is NOT met.</li> |
|
| 32 | * </ul> |
|
| 33 | * |
|
| 34 | * @author ezamudio@nasoft.com |
|
| 35 | * @author $Author: cgruber $ |
|
| 36 | * @version $Revision: 893 $ |
|
| 37 | */ |
|
| 38 | public class WOConditional extends WODynamicElement { |
|
| 39 | ||
| 40 | public boolean condition; |
|
| 41 | public boolean negate; |
|
| 42 | ||
| 43 | protected WOConditional() { |
|
| 44 | 0 | super(); |
| 45 | 0 | } |
| 46 | ||
| 47 | public WOConditional(String aName, NSDictionary aMap, WOElement template) { |
|
| 48 | 0 | super(aName, aMap, template); |
| 49 | 0 | } |
| 50 | ||
| 51 | public void setCondition(boolean value) { |
|
| 52 | 0 | condition = value; |
| 53 | 0 | } |
| 54 | public boolean condition() { |
|
| 55 | 0 | return condition; |
| 56 | } |
|
| 57 | ||
| 58 | public void setNegate(boolean value) { |
|
| 59 | 0 | negate = value; |
| 60 | 0 | } |
| 61 | public boolean negate() { |
|
| 62 | 0 | return negate; |
| 63 | } |
|
| 64 | ||
| 65 | protected void pullValuesFromParent(WOComponent c) { |
|
| 66 | 0 | condition = booleanForProperty("condition", c); |
| 67 | 0 | negate = booleanForProperty("negate", c); |
| 68 | 0 | } |
| 69 | ||
| 70 | public void takeValuesFromRequest(WORequest aRequest, WOContext aContext) { |
|
| 71 | 0 | if (rootElement == null) |
| 72 | 0 | return; |
| 73 | 0 | pullValuesFromParent(aContext.component()); |
| 74 | 0 | if ((condition && !negate) || (!condition && negate)) { |
| 75 | 0 | rootElement.takeValuesFromRequest(aRequest, aContext); |
| 76 | } |
|
| 77 | 0 | } |
| 78 | ||
| 79 | public WOActionResults invokeAction(WORequest aRequest, WOContext aContext) { |
|
| 80 | 0 | if (rootElement == null) |
| 81 | 0 | return null; |
| 82 | 0 | pullValuesFromParent(aContext.component()); |
| 83 | 0 | WOActionResults el = null; |
| 84 | 0 | if ((condition && !negate) || (!condition && negate)) { |
| 85 | 0 | el = rootElement.invokeAction(aRequest, aContext); |
| 86 | } |
|
| 87 | 0 | return el; |
| 88 | } |
|
| 89 | ||
| 90 | public void appendToResponse(WOResponse aResponse, WOContext aContext) { |
|
| 91 | 0 | if (rootElement == null) |
| 92 | 0 | return; |
| 93 | 0 | pullValuesFromParent(aContext.component()); |
| 94 | 0 | if ((condition && !negate) || (!condition && negate)) { |
| 95 | 0 | rootElement.appendToResponse(aResponse, aContext); |
| 96 | } |
|
| 97 | 0 | } |
| 98 | ||
| 99 | } |