001: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.layout.restrictions;
007:
008: import org.jasig.portal.PortalException;
009: import org.jasig.portal.layout.node.ILayoutNode;
010:
011: /**
012: * UserLayoutRestriction summary sentence goes here.
013: *
014: * @author Michael Ivanov
015: * @version $Revision: 36684 $
016: */
017:
018: public abstract class UserLayoutRestriction implements
019: IUserLayoutRestriction {
020:
021: private String name;
022: private String restrictionExpression;
023: protected String nodePath;
024:
025: public UserLayoutRestriction() {
026: this ("", LOCAL_RESTRICTION_PATH);
027: }
028:
029: public UserLayoutRestriction(String name) {
030: this (name, LOCAL_RESTRICTION_PATH);
031: }
032:
033: public UserLayoutRestriction(String name, String nodePath) {
034: this .name = name;
035: this .nodePath = nodePath;
036: }
037:
038: /**
039: * Sets the name of the current restriction
040: * @param name <code>String</code> name
041: */
042: public void setName(String name) {
043: this .name = name;
044: }
045:
046: /**
047: * Returns the name of the current restriction
048: * @return name <code>String</code> name
049: */
050: public String getName() {
051: return name;
052: }
053:
054: /**
055: * Sets the restriction path
056: * @param nodePath a <code>String</code> path
057: */
058: public void setRestrictionPath(String nodePath) {
059: this .nodePath = nodePath;
060: }
061:
062: /**
063: * Parses the restriction expression of the current node
064: * @exception PortalException
065: */
066: protected abstract void parseRestrictionExpression()
067: throws PortalException;
068:
069: /**
070: * Checks the restriction for the given property value
071: * @param propertyValue a <code>String</code> property value to be checked
072: * @exception PortalException
073: */
074: public abstract boolean checkRestriction(String propertyValue)
075: throws PortalException;
076:
077: /**
078: * Checks the restriction on a given node
079: * @param node a <code>ILayoutNode</code> node
080: * @return a boolean value
081: * @exception PortalException
082: */
083: public boolean checkRestriction(ILayoutNode node)
084: throws PortalException {
085: return true;
086: }
087:
088: /**
089: * Gets the restriction name
090: * @return a <code>String</code> restriction name
091: */
092: public String getUniqueKey() {
093: return getUniqueKey(getName(), nodePath);
094: }
095:
096: /**
097: * Gets the restriction name based on a restriction name and a node path
098: * @param restrictionName a restriction name
099: * @param nodePath a <code>String</code> node path
100: * @return a <code>String</code> restriction name
101: */
102: public static String getUniqueKey(String restrictionName,
103: String nodePath) {
104: if (nodePath != null && nodePath.length() > 0)
105: nodePath = LOCAL_RESTRICTION_PATH;
106: return restrictionName + ":" + nodePath;
107: }
108:
109: /**
110: * Gets the local restriction name based on a restriction type
111: * @param restrictionName a restriction name
112: * @return a <code>String</code> restriction name
113: */
114: public static String getUniqueKey(String restrictionName) {
115: return getUniqueKey(restrictionName, LOCAL_RESTRICTION_PATH);
116: }
117:
118: /**
119: * Sets the restriction expression
120: * @param restrictionExpression a <code>String</code> expression
121: */
122: public void setRestrictionExpression(String restrictionExpression) {
123: if (!restrictionExpression.equals(this .restrictionExpression)) {
124: this .restrictionExpression = restrictionExpression;
125: try {
126: parseRestrictionExpression();
127: } catch (PortalException pe) {
128: pe.printStackTrace();
129: System.out.println("restriction expression: "
130: + restrictionExpression);
131: System.out.println("setRestrictionExpression: " + pe);
132: }
133: }
134: }
135:
136: /**
137: * Gets the restriction expression
138: * @return a <code>String</code> expression
139: */
140: public String getRestrictionExpression() {
141: return restrictionExpression;
142: }
143:
144: /**
145: * Gets the tree path for the current restriction
146: * @return a <code>String</code> tree path
147: */
148: public String getRestrictionPath() {
149: return nodePath;
150: }
151:
152: }
|