01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool/src/java/org/theospi/portfolio/security/model/impl/PermissionsCustomEditor.java $
03: * $Id:PermissionsCustomEditor.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.security.model.impl;
21:
22: import java.beans.PropertyEditorSupport;
23: import java.util.ArrayList;
24: import java.util.Collection;
25: import java.util.Iterator;
26: import java.util.List;
27:
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.sakaiproject.metaobj.shared.mgt.AgentManager;
31: import org.sakaiproject.metaobj.shared.model.Agent;
32: import org.sakaiproject.metaobj.utils.mvc.intf.TypedPropertyEditor;
33: import org.theospi.portfolio.security.model.Permission;
34:
35: public class PermissionsCustomEditor extends PropertyEditorSupport
36: implements TypedPropertyEditor {
37: protected final transient Log logger = LogFactory
38: .getLog(getClass());
39:
40: private AgentManager agentManager = null;
41:
42: public void setAsText(String text) throws IllegalArgumentException {
43: if (text == null || text.length() == 0) {
44: setValue(new ArrayList());
45: } else {
46: String[] items = text.split(",");
47: List permissions = new ArrayList();
48: for (int i = 0; i < items.length; i++) {
49: if (items[i].length() == 0) {
50: continue;
51: }
52: String[] values = items[i].split("~");
53: String role = values[0];
54: String function = values[1];
55: Agent agent = getAgentManager().getWorksiteRole(role);
56: permissions.add(new Permission(agent, function));
57: }
58: setValue(permissions);
59: }
60: }
61:
62: public String getAsText() {
63: if (getValue() == null) {
64: return null;
65: }
66:
67: StringBuffer buffer = new StringBuffer();
68: for (Iterator i = ((Collection) getValue()).iterator(); i
69: .hasNext();) {
70: buffer.append(i.next().toString());
71: if (i.hasNext()) {
72: buffer.append(",");
73: }
74: }
75: return buffer.toString();
76: }
77:
78: public Class getType() {
79: return List.class;
80: }
81:
82: public AgentManager getAgentManager() {
83: return agentManager;
84: }
85:
86: public void setAgentManager(AgentManager agentManager) {
87: this.agentManager = agentManager;
88: }
89:
90: }
|