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.alm;
007:
008: import java.util.List;
009: import java.util.StringTokenizer;
010: import java.util.Vector;
011:
012: import org.jasig.portal.PortalException;
013: import org.jasig.portal.groups.IEntityGroup;
014: import org.jasig.portal.groups.IGroupService;
015: import org.jasig.portal.groups.IGroupServiceFactory;
016: import org.jasig.portal.groups.ReferenceGroupServiceFactory;
017: import org.jasig.portal.layout.alm.ALNode;
018: import org.jasig.portal.layout.alm.IALNodeDescription;
019: import org.jasig.portal.layout.node.ILayoutNode;
020:
021: /**
022: * GroupRestriction checks the group restriction for a given ALNode object.
023: *
024: * Prior to uPortal 2.5, this class existed in the package org.jasig.portal.layout.restrictions.
025: * It was moved to its present package to reflect that it is part of Aggregated Layouts.
026: *
027: * @author <a href="mailto:mvi@immagic.com">Michael Ivanov</a>
028: * @version $Revision: 35731 $
029: */
030: public class GroupRestriction extends ALRestriction {
031:
032: // This group key can be come from different sources, for instance, from IEntityGroup object
033: private IEntityGroup groups[];
034: private static IGroupService groupService;
035: private static IGroupServiceFactory groupServiceFactory;
036:
037: static {
038: try {
039: if (groupServiceFactory == null)
040: groupServiceFactory = new ReferenceGroupServiceFactory();
041: if (groupService == null)
042: groupService = groupServiceFactory.newGroupService();
043: } catch (Exception e) {
044: throw new RuntimeException(e);
045: }
046: }
047:
048: public GroupRestriction(String name, String nodePath)
049: throws PortalException {
050: super (name, nodePath);
051: }
052:
053: public GroupRestriction(String name) throws PortalException {
054: super (name);
055: }
056:
057: public GroupRestriction() throws PortalException {
058: super ();
059: }
060:
061: /**
062: * Parses the restriction expression of the current node
063: * @exception PortalException
064: */
065: protected void parseRestrictionExpression() throws PortalException {
066: try {
067: String restrictionExp = getRestrictionExpression();
068: List groupsList = new Vector();
069: StringTokenizer st = new StringTokenizer(restrictionExp,
070: ",");
071: while (st.hasMoreTokens()) {
072: String token = st.nextToken();
073: groupsList.add(groupService.findGroup(token));
074: }
075: groups = (IEntityGroup[]) groupsList.toArray();
076:
077: } catch (Exception e) {
078: throw new PortalException(e);
079: }
080:
081: }
082:
083: /**
084: * Checks the restriction for the specified property value
085: * @param propertyValue a <code>String</code> property value to be checked
086: * @exception PortalException
087: */
088: public boolean checkRestriction(String propertyValue)
089: throws PortalException {
090: IEntityGroup group = groupService.findGroup(propertyValue);
091: for (int i = 0; i < groups.length; i++)
092: if (groups[i].contains(group))
093: return true;
094: return false;
095: }
096:
097: /**
098: * Checks the restriction for the current node
099: * @exception PortalException
100: */
101: public boolean checkRestriction(ILayoutNode node)
102: throws PortalException {
103: if (!(node instanceof ALNode))
104: throw new PortalException("The node must be ALNode type!");
105: IEntityGroup group = groupService
106: .findGroup(((IALNodeDescription) node
107: .getNodeDescription()).getGroup());
108: for (int i = 0; i < groups.length; i++)
109: if (groups[i].contains(group))
110: return true;
111: return false;
112: }
113:
114: }
|