01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.engine;
18:
19: import java.util.ArrayList;
20: import java.util.Arrays;
21: import java.util.Iterator;
22: import java.util.List;
23: import java.util.Vector;
24:
25: import org.jdom.Document;
26: import org.jdom.Element;
27:
28: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
29: import edu.iu.uis.eden.routeheader.DocumentContent;
30: import edu.iu.uis.eden.routetemplate.AbstractRoleAttribute;
31: import edu.iu.uis.eden.routetemplate.ResolvedQualifiedRole;
32: import edu.iu.uis.eden.routetemplate.Role;
33: import edu.iu.uis.eden.util.XmlHelper;
34: import edu.iu.uis.eden.workgroup.GroupNameId;
35:
36: public class ChartOrgDispatchAttribute extends AbstractRoleAttribute {
37:
38: public static final String DISPATCH_ROLE = "DISPATCH";
39: private String workgroupName;
40:
41: public ChartOrgDispatchAttribute() {
42: }
43:
44: public ChartOrgDispatchAttribute(String workgroupName) {
45: this .workgroupName = workgroupName;
46: }
47:
48: public List getRoleNames() {
49: return Arrays.asList(new Role[] { new Role(getClass(),
50: DISPATCH_ROLE, DISPATCH_ROLE) });
51: }
52:
53: public List getQualifiedRoleNames(String roleName,
54: DocumentContent documentContent)
55: throws EdenUserNotFoundException {
56: return parseWorkgroups(documentContent);
57: }
58:
59: public ResolvedQualifiedRole resolveQualifiedRole(
60: RouteContext routeContext, String roleName,
61: String qualifiedRole) throws EdenUserNotFoundException {
62: List recipients = new ArrayList();
63: recipients.add(new GroupNameId(qualifiedRole));
64: return new ResolvedQualifiedRole(roleName, recipients);
65: }
66:
67: public String getDocContent() {
68: return "<" + DISPATCH_ROLE + ">" + workgroupName + "</"
69: + DISPATCH_ROLE + ">";
70: }
71:
72: private List parseWorkgroups(DocumentContent documentContent) {
73: Document document = XmlHelper.buildJDocument(documentContent
74: .getDocument());
75: Vector dispatchElements = XmlHelper.findElements(document
76: .getRootElement(), DISPATCH_ROLE);
77: List workgroupNames = new ArrayList();
78: for (Iterator iterator = dispatchElements.iterator(); iterator
79: .hasNext();) {
80: Element element = (Element) iterator.next();
81: workgroupNames.add(element.getText());
82: }
83: return workgroupNames;
84: }
85:
86: }
|