001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: */package org.jamwiki.model;
017:
018: import java.util.Collection;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.Vector;
022: import org.jamwiki.utils.WikiLogger;
023:
024: /**
025: * Provides an object representing a mapping of a user or group to a set of
026: * roles. This class exists primarily as a helper when adding or modifying
027: * roles using a form interface.
028: */
029: public class RoleMap {
030:
031: private static final WikiLogger logger = WikiLogger
032: .getLogger(RoleMap.class.getName());
033: private Integer groupId = null;
034: private String groupName = null;
035: private Collection roleNames = null;
036: private Integer userId = null;
037: private String userLogin = null;
038:
039: /**
040: *
041: */
042: public RoleMap() {
043: }
044:
045: /**
046: *
047: */
048: public Integer getGroupId() {
049: return this .groupId;
050: }
051:
052: /**
053: *
054: */
055: public void setGroupId(Integer groupId) {
056: this .groupId = groupId;
057: }
058:
059: /**
060: *
061: */
062: public String getGroupName() {
063: return this .groupName;
064: }
065:
066: /**
067: *
068: */
069: public void setGroupName(String groupName) {
070: this .groupName = groupName;
071: }
072:
073: /**
074: *
075: */
076: public void addRole(String roleName) {
077: if (this .roleNames == null) {
078: this .roleNames = new Vector();
079: }
080: this .roleNames.add(roleName);
081: }
082:
083: /**
084: *
085: */
086: public Collection getRoleNames() {
087: return this .roleNames;
088: }
089:
090: /**
091: *
092: */
093: public void setRoleNames(Collection roleNames) {
094: this .roleNames = roleNames;
095: }
096:
097: /**
098: *
099: */
100: public Integer getUserId() {
101: return this .userId;
102: }
103:
104: /**
105: *
106: */
107: public void setUserId(Integer userId) {
108: this .userId = userId;
109: }
110:
111: /**
112: *
113: */
114: public String getUserLogin() {
115: return this .userLogin;
116: }
117:
118: /**
119: *
120: */
121: public void setUserLogin(String userLogin) {
122: this .userLogin = userLogin;
123: }
124:
125: /**
126: * This method is simply a utility method to be used with JSTL for
127: * determining if the current list of roles contains a specific role.
128: */
129: public HashMap getRoleNamesMap() {
130: HashMap results = new HashMap();
131: if (this .roleNames == null) {
132: return results;
133: }
134: Iterator roleNameIterator = this .roleNames.iterator();
135: while (roleNameIterator.hasNext()) {
136: String key = (String) roleNameIterator.next();
137: String value = this .getUserGroup() + "|" + key;
138: results.put(key, value);
139: }
140: return results;
141: }
142:
143: /**
144: * This is a utility method for building a concatenated version of the
145: * user and group id values for use with JSTL.
146: */
147: public String getUserGroup() {
148: String result = "";
149: if (this .userId != null) {
150: result += this .userId;
151: } else {
152: result += "0";
153: }
154: result += "|";
155: if (this .groupId != null) {
156: result += this .groupId;
157: } else {
158: result += "0";
159: }
160: return result;
161: }
162: }
|