01: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.restrictions.alm;
07:
08: import org.jasig.portal.PortalException;
09: import org.jasig.portal.layout.node.ILayoutNode;
10: import org.jasig.portal.utils.CommonUtils;
11:
12: /**
13: * BooleanRestriction checks the restriction on the boolean property for a given ILayoutNode object.
14: * <p>
15: * Company: Instructional Media & Magic
16: *
17: * Prior to uPortal 2.5, this class existed in the package org.jasig.portal.layout.restrictions.
18: * It was moved to its present package to reflect that it is part of Aggregated Layouts.
19: *
20: * @author <a href="mailto:mvi@immagic.com">Michael Ivanov</a>
21: * @version $Revision: 35731 $
22: */
23: public abstract class BooleanRestriction extends ALRestriction {
24:
25: private boolean boolValue1 = false, boolValue2 = false;
26:
27: public BooleanRestriction(String name, String nodePath) {
28: super (name, nodePath);
29: }
30:
31: public BooleanRestriction(String name) {
32: super (name);
33: }
34:
35: public BooleanRestriction() {
36: super ();
37: }
38:
39: private boolean strToBool(String boolStr) {
40: return ("Y".equalsIgnoreCase(boolStr)) ? true : false;
41: }
42:
43: /**
44: * Parses the restriction expression of the current node
45: * @exception PortalException
46: */
47: protected void parseRestrictionExpression() throws PortalException {
48: try {
49: String restrictionExp = getRestrictionExpression();
50: int commaIndex = restrictionExp.indexOf(',');
51: if (commaIndex < 0) {
52: boolValue1 = boolValue2 = strToBool(restrictionExp);
53: } else {
54: boolValue1 = strToBool(restrictionExp.substring(0,
55: commaIndex));
56: boolValue2 = strToBool(restrictionExp
57: .substring(commaIndex + 1));
58: }
59: } catch (Exception e) {
60: throw new PortalException(e);
61: }
62: }
63:
64: /**
65: * Gets the boolean property value for the specified node
66: */
67: protected abstract boolean getBooleanPropertyValue(ILayoutNode node);
68:
69: protected boolean checkRestriction(boolean boolProperty)
70: throws PortalException {
71: if (boolProperty == boolValue1 || boolProperty == boolValue2)
72: return true;
73: return false;
74: }
75:
76: /**
77: * Checks the restriction for the specified node
78: * @param node a <code>ILayoutNode</code> user layout node to be checked
79: * @exception PortalException
80: */
81: public boolean checkRestriction(ILayoutNode node)
82: throws PortalException {
83: boolean boolProperty = getBooleanPropertyValue(node);
84: return checkRestriction(boolProperty);
85: }
86:
87: /**
88: * Checks the restriction for the specified property
89: * @param propertyValue a <code>String</code> property value
90: * @exception PortalException
91: */
92: public boolean checkRestriction(String propertyValue)
93: throws PortalException {
94: boolean boolProperty = CommonUtils.strToBool(propertyValue);
95: return checkRestriction(boolProperty);
96: }
97:
98: }
|