Commits

Anonymous committed a5c8228

Initial import from SourceForge

Comments (0)

Files changed (11)

src/etc/example/osworkflow.xml

+<osworkflow>
+    <persistence class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore"/>
+
+    <factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
+        <property key="resource" value="workflows.xml" />
+    </factory>
+</osworkflow>

src/webapp/manager/default.jsp

+<%@ page import="com.opensymphony.module.user.UserManager,
+				 java.util.Collection,
+				 java.util.Iterator,
+				 com.opensymphony.module.user.provider.CredentialsProvider,
+				 com.opensymphony.module.user.provider.AccessProvider,
+				 com.opensymphony.module.user.provider.UserProvider"%>
+ <h2>Directory</h2>
+<ul>
+<li><a href="users.jsp">Users</a>
+<li><a href="groups.jsp">Groups</a>
+</ul>
+
+<hr>
+
+<h2>Providers</h2>
+<%
+	UserManager um = UserManager.getInstance();
+%>
+
+<h4>CredentialsProviders</h4>
+
+<ul>
+<%
+	Collection credentialProviders = um.getCredentialsProviders();
+	for (Iterator iterator = credentialProviders.iterator(); iterator.hasNext();)
+	{
+		CredentialsProvider provider = (CredentialsProvider) iterator.next();
+%>
+        <li><%= provider.getClass() %></li>
+<%
+	}
+%>
+</ul>
+
+<h4>AccessProviders</h4>
+
+<ul>
+<%
+	Collection accessProviders = um.getAccessProviders();
+	for (Iterator iterator = accessProviders.iterator(); iterator.hasNext();)
+	{
+		UserProvider provider = (UserProvider) iterator.next();
+%>
+        <li><%= provider.getClass() %></li>
+<%
+	}
+%>
+</ul>
+
+<h4>ProfileProviders</h4>
+
+<ul>
+<%
+	Collection profileProviders = um.getProfileProviders();
+	for (Iterator iterator = profileProviders.iterator(); iterator.hasNext();)
+	{
+		UserProvider provider = (UserProvider) iterator.next();
+%>
+        <li><%= provider.getClass() %></li>
+<%
+	}
+%>
+</ul>
+
+

src/webapp/manager/editusergroups.jsp

+<%@ page import="com.opensymphony.module.user.UserManager,
+				 com.opensymphony.module.user.User,
+				 java.util.Collection,
+				 java.net.URLEncoder,
+				 com.opensymphony.module.user.Group,
+                 java.util.Iterator"%>
+
+
+<%
+	UserManager um = UserManager.getInstance();
+	User user = um.getUser(request.getParameter("name"));
+
+	if (request.getParameter("add") != null)
+	{
+		String[] addGroupNames = request.getParameterValues("outgroups");
+		for (int i = 0; i < addGroupNames.length; i++)
+		{
+			String addGroupName = addGroupNames[i];
+			Group addGroup = um.getGroup(addGroupName);
+			user.addToGroup(addGroup);
+		}
+	}
+	else if (request.getParameter("remove") != null)
+	{
+		String[] removeGroupNames = request.getParameterValues("ingroups");
+		for (int i = 0; i < removeGroupNames.length; i++)
+		{
+			String removeGroupName = removeGroupNames[i];
+			Group removeGroup = um.getGroup(removeGroupName);
+			user.removeFromGroup(removeGroup);
+		}
+	}
+%>
+
+<h1>Edit Groups : <%= user.getName() %></h1>
+<hr>
+
+<form action="editusergroups.jsp" method="get">
+
+	<table cellpadding=0 cellspacing=0 border=0 bgcolor=666666 width=80% align="center"><tr><td>
+	<table cellpadding=4 cellspacing=1 border=0 width=100% bgcolor=666666>
+	<tr>
+		<td bgcolor=f0f0f0 valign="top" align="center" nowrap width="45%"><b>Other Groups</b></td>
+		<td bgcolor=f0f0f0 width="10%">&nbsp;</td>
+		<td bgcolor=f0f0f0 valign="top" align="center" nowrap width="45%"><b>Member Of</b></td>
+	</tr>
+	<tr>
+		<td bgcolor=ffffff valign="top" align="center">
+			<% Collection allgroups = um.getGroups(); %>
+			<select name="outgroups"
+				size="7"
+				multiple>
+                    <% for (Iterator iterator = allgroups.iterator(); iterator.hasNext();) {
+                        Group outgroup = (Group) iterator.next();
+                    %>
+
+						<% if (user.getGroups() == null || !user.getGroups().contains(outgroup.getName())) { %>
+						<option value="<%= outgroup.getName() %>"><%= outgroup.getName() %></option>
+						<% } %>
+					<% } %>
+			</select>
+		</td>
+		<td bgcolor=ffffff align="center">
+            <input type="submit" name="add" value="&gt;&gt;">
+			<br>
+			<input type="submit" name="remove" value="&lt;&lt;">
+		</td>
+		<td bgcolor=ffffff valign="top" align="center">
+			<select name="ingroups"
+				size="7"
+				multiple
+				class="maincontent">
+					<% if (user.getGroups() != null) { %>
+                        <% for (Iterator iterator = user.getGroups().iterator(); iterator.hasNext();) {
+                            String ingroup = (String) iterator.next();
+                        %>
+							<option value="<%= ingroup %>"><%= ingroup %></option>
+						<% } %>
+					<% } %>
+			</select>
+		</td>
+	</tr>
+	<tr>
+		<td bgcolor=ffffff valign=top colspan=3 align=center>
+			<input type="hidden" name="executed" value="true">
+			<input type="hidden" name="name" value="<%= user.getName() %>">
+			<input type="button" value="Done" onclick="location.href='viewuser.jsp?name=<%= URLEncoder.encode(user.getName()) %>'">
+		</td>
+	</tr>
+	</table>
+	</td></tr></table>
+
+</form>
+
+<%@ include file="nav.jsp" %>

src/webapp/manager/groups.jsp

+<%@ page import="com.opensymphony.module.user.UserManager,
+				 java.util.Collection,
+				 java.util.Iterator,
+				 com.opensymphony.module.user.User,
+				 java.net.URLEncoder,
+				 com.opensymphony.module.user.Group"%>
+
+<%
+	UserManager um = UserManager.getInstance();
+
+	if (request.getParameter("addGroup") != null)
+	{
+		Group newgroup = um.createGroup(request.getParameter("name"));
+	}
+	else if (request.getParameter("delGroup") != null)
+	{
+		Group removegroup = um.getGroup(request.getParameter("delGroup"));
+		removegroup.remove();
+	}
+%>
+
+<h1>Groups</h1>
+<hr>
+<ol>
+<%
+	Collection groups = um.getGroups();
+	for (Iterator iterator = groups.iterator(); iterator.hasNext();)
+	{
+		Group group = (Group) iterator.next();
+		%>
+		<li><%= group.getName() %> [<a href="viewgroup.jsp?name=<%= URLEncoder.encode(group.getName()) %>">View</a> | <a href="groups.jsp?delGroup=<%= URLEncoder.encode(group.getName()) %>">Del</a>]</li>
+		<%
+	}
+%>
+</ol>
+
+<hr>
+
+<form action="groups.jsp">
+<b>Add Group</b><br>
+Name: <input type="text" name="name"><br>
+<input type="submit" name="addGroup" value="Add group">
+</form>
+
+<%@ include file="nav.jsp" %>

src/webapp/manager/includes/propertysetMethods.jsp

+<%@ page import="com.opensymphony.module.propertyset.PropertySet"%>
+<%!
+private String getTypeName(int type)
+{
+    switch (type)
+    {
+        case 1:
+            return "Boolean";
+        case 2:
+            return "Integer";
+        case 3:
+            return "Long";
+        case 4:
+            return "Double";
+        case 5:
+            return "String";
+        case 6:
+            return "Text";
+        case 7:
+            return "Date";
+        case 8:
+            return "Object";
+        case 9:
+            return "XML";
+        case 10:
+            return "Data";
+        case 11:
+            return "Properties";
+        default:
+            return "Unknown";
+    }
+}
+
+public String getPropertyValue(PropertySet ps, String key) throws Exception
+{
+    int type = ps.getType(key);
+
+    switch(type)
+    {
+        case PropertySet.STRING:
+            return ps.getString(key);
+        case PropertySet.BOOLEAN:
+            return ps.getBoolean(key) + "";
+        case PropertySet.INT:
+			return ps.getInt(key) + "";
+        case PropertySet.LONG:
+			return ps.getLong(key) + "";
+        case PropertySet.DATE:
+            return ps.getDate(key) + "";
+		case PropertySet.TEXT:
+			return ps.getText(key) + "";
+        default:
+            return "Cannot display property value";
+    }
+}
+
+public void setPropertyValue(PropertySet ps, String key, int type, String newVal) throws Exception
+{
+    try
+    {
+        switch (type)
+        {
+            case PropertySet.STRING:
+                ps.setString(key, newVal); break;
+			case PropertySet.TEXT:
+                ps.setText(key, newVal); break;
+            case PropertySet.BOOLEAN:
+                ps.setBoolean(key, Boolean.valueOf(newVal).booleanValue()); break;
+            case PropertySet.INT:
+                ps.setInt(key, Integer.valueOf(newVal).intValue()); break;
+			case PropertySet.LONG:
+                ps.setLong(key, Long.valueOf(newVal).intValue()); break;
+			case PropertySet.DOUBLE:
+                ps.setDouble(key, Double.valueOf(newVal).intValue()); break;
+            case PropertySet.DATE:
+                ps.setDate(key, java.text.DateFormat.getDateInstance().parse(newVal)); break;
+            default:
+                throw new Exception("Type not recognised");
+        }
+    } catch (Exception e)
+    {
+        throw e;
+    }
+}
+%>

src/webapp/manager/nav.jsp

+<hr>
+<a href="default.jsp">Home</a> |
+<a href="users.jsp">Users</a> |
+<a href="groups.jsp">Groups</a>

src/webapp/manager/users.jsp

+<%@ page import="com.opensymphony.module.user.UserManager,
+				 java.util.Collection,
+				 java.util.Iterator,
+				 com.opensymphony.module.user.User,
+				 java.net.URLEncoder"%>
+
+<%
+	UserManager um = UserManager.getInstance();
+
+	if (request.getParameter("adduser") != null)
+	{
+		User newuser = um.createUser(request.getParameter("name"));
+		newuser.setPassword(request.getParameter("password"));
+		newuser.setEmail(request.getParameter("email"));
+	}
+	else if (request.getParameter("deluser") != null)
+	{
+		User removeuser = um.getUser(request.getParameter("deluser"));
+		removeuser.remove();
+	}
+%>
+
+<h1>Users</h1>
+<hr>
+
+<ol>
+<%
+	Collection users = um.getUsers();
+	for (Iterator iterator = users.iterator(); iterator.hasNext();)
+	{
+		User user = (User) iterator.next();
+		%>
+		<li><%= user.getName() %> (<%= user.getEmail() %>) [<a href="viewuser.jsp?name=<%= URLEncoder.encode(user.getName()) %>">View</a> | <a href="users.jsp?deluser=<%= URLEncoder.encode(user.getName()) %>">Del</a>]</li>
+		<%
+	}
+%>
+</ol>
+
+<hr>
+
+<form action="users.jsp">
+<b>Add User</b><br>
+Name: <input type="text" name="name"><br>
+Password: <input type="password" name="password"><br>
+Email: <input type="text" name="email"><br>
+<input type="submit" name="adduser" value="Add User">
+</form>
+
+<%@ include file="nav.jsp" %>

src/webapp/manager/viewgroup.jsp

+<%@ page import="com.opensymphony.module.user.UserManager,
+				 java.util.Collection,
+				 com.opensymphony.module.user.Group,
+				 java.util.Iterator,
+				 com.opensymphony.module.user.User,
+				 java.net.URLEncoder,
+				 com.opensymphony.module.propertyset.PropertySet"%>
+<%
+	UserManager um = UserManager.getInstance();
+	Group group = um.getGroup(request.getParameter("name"));
+
+	PropertySet ps = null;
+
+	if (request.getParameter("propertyAdd") != null) {
+		ps = group.getPropertySet();
+        setPropertyValue(ps, request.getParameter("propertyKey"), Integer.parseInt(request.getParameter("propertyType")), request.getParameter("propertyValue"));
+	}
+  else if (request.getParameter("propertyDel") != null)
+	{
+		ps = group.getPropertySet();
+		ps.remove(request.getParameter("propertyDel"));
+	}
+%>
+
+<h1>View Group : <%= group.getName() %></h1>
+<hr>
+
+<h4>Details</h4>
+Name: <%= group.getName() %><br>
+Class: <%= group.getClass() %><br>
+
+<h4>Providers</h4>
+CredentialsProvider: <%= (group.getCredentialsProvider() != null ? group.getCredentialsProvider().getClass().toString() : "None") %><br>
+AccessProvider: <%= (group.getAccessProvider() != null ? group.getAccessProvider().getClass().toString() : "None" )%><br>
+ProfileProvider: <%= (group.getProfileProvider() != null ? group.getProfileProvider().getClass().toString() : "None")%><br>
+
+<h4>Users</h4>
+
+<%
+	Collection users = group.getUsers();
+%>
+<%= users.size() %> users<br>
+
+<ol>
+<%
+	for (Iterator iterator = users.iterator(); iterator.hasNext();)
+	{
+		String userName = (String) iterator.next();
+%>
+		<li><a href="viewuser.jsp?name=<%= URLEncoder.encode(userName) %>"><%= userName%></a></li>
+<%
+	}
+%>
+</ol>
+
+<h4>Properties</h4>
+<%
+	ps = group.getPropertySet();
+	if (ps != null)
+	{
+		Collection keys = ps.getKeys();
+		for (Iterator iterator = keys.iterator(); iterator.hasNext();)
+		{
+			String key = (String) iterator.next();
+%>
+		<%= key %> : <%= getPropertyValue(ps, key) %> (<%= getTypeName(ps.getType(key)) %>) [<a href="viewgroup.jsp?name=<%= URLEncoder.encode(group.getName()) %>&propertyDel=<%= URLEncoder.encode(key) %>">Del</a>]<br>
+<%
+		}
+%>
+
+<form action="viewgroup.jsp" method="post">
+<input type="hidden" name="name" value="<%= group.getName() %>">
+<h4>Add Property</h4>
+Key: <input name="propertyKey" type="text"><br>
+Type:
+<select name="propertyType">
+	<% for (int i = 1; i <= 7; i++) { %>
+		<option value="<%= i %>"><%= getTypeName(i) %></option>
+	<% } %>
+</select><br>
+Value: <input name="propertyValue" type="text"><br>
+<input type="submit" name="propertyAdd" value="Add Property">
+</form>
+
+<%
+	}
+	else
+	{
+%>
+		No PropertySet for this group
+<%
+	}
+%>
+
+
+<%@ include file="nav.jsp" %>
+
+<%@ include file="includes/propertysetMethods.jsp" %>
+

src/webapp/manager/viewuser.jsp

+<%@ page import="com.opensymphony.module.user.UserManager,
+				 com.opensymphony.module.user.User,
+				 com.opensymphony.module.propertyset.PropertySet,
+				 java.util.Collection,
+				 java.util.Iterator,
+				 java.net.URLEncoder,
+				 com.opensymphony.module.user.Group"%>
+<%
+	UserManager um = UserManager.getInstance();
+	User user = um.getUser(request.getParameter("name"));
+	PropertySet ps = null;
+
+	if (request.getParameter("propertyAdd") != null) {
+		ps = user.getPropertySet();
+        setPropertyValue(ps, request.getParameter("propertyKey"), Integer.parseInt(request.getParameter("propertyType")), request.getParameter("propertyValue"));
+	}
+	else if (request.getParameter("propertyDel") != null)
+	{
+		ps = user.getPropertySet();
+		ps.remove(request.getParameter("propertyDel"));
+	}
+%>
+
+<h1>User: <%= user.getName() %></h1>
+<hr>
+
+<h4>Details</h4>
+Name: <%= user.getName() %><br>
+Class: <%= user.getClass() %><br>
+Full Name: <%= user.getFullName() %><br>
+Email: <%= user.getEmail() %><br>
+
+<h4>Providers</h4>
+CredentialsProvider: <%= (user.getCredentialsProvider() != null ? user.getCredentialsProvider().getClass().toString() : "None") %><br>
+AccessProvider: <%= (user.getAccessProvider() != null ? user.getAccessProvider().getClass().toString() : "None" )%><br>
+ProfileProvider: <%= (user.getProfileProvider() != null ? user.getProfileProvider().getClass().toString() : "None")%><br>
+
+<h4>Groups</h4>
+<%
+	Collection groups = user.getGroups();
+%>
+<%= groups.size() %> groups<br>
+
+<ol>
+<%
+	for (Iterator iterator = groups.iterator(); iterator.hasNext();)
+	{
+		String groupName = (String) iterator.next();
+%>
+		<li><a href="viewgroup.jsp?name=<%= URLEncoder.encode(groupName) %>"><%= groupName %></a></li>
+<%
+	}
+%>
+</ol>
+<a href="editusergroups.jsp?name=<%= URLEncoder.encode(user.getName()) %>">Add / Edit Groups</a>
+
+<h4>Properties</h4>
+<%
+	ps = user.getPropertySet();
+
+	Collection keys = ps.getKeys();
+	for (Iterator iterator = keys.iterator(); iterator.hasNext();)
+	{
+		String key = (String) iterator.next();
+%>
+	<%= key %> : <%= getPropertyValue(ps, key) %> (<%= getTypeName(ps.getType(key)) %>) [<a href="viewuser.jsp?name=<%= URLEncoder.encode(user.getName()) %>&propertyDel=<%= URLEncoder.encode(key) %>">Del</a>]<br>
+<%
+	}
+%>
+<form action="viewuser.jsp" method="post">
+<input type="hidden" name="name" value="<%= user.getName() %>">
+<h4>Add Property</h4>
+Key: <input name="propertyKey" type="text"><br>
+Type:
+<select name="propertyType">
+	<% for (int i = 1; i <= 7; i++) { %>
+		<option value="<%= i %>"><%= getTypeName(i) %></option>
+	<% } %>
+</select><br>
+Value: <input name="propertyValue" type="text"><br>
+<input type="submit" name="propertyAdd" value="Add Property">
+</form>
+<%@ include file="nav.jsp" %>
+
+<%@ include file="includes/propertysetMethods.jsp" %>

src/webapp/newworkflow.jsp

+<%@ page import="com.opensymphony.workflow.Workflow,
+                 com.opensymphony.workflow.basic.BasicWorkflow"%>
+
+<%
+    Workflow wf = new BasicWorkflow((String) session.getAttribute("username"));
+    long id = wf.initialize("example", 1, null);
+%>
+
+New workflow entry <a href="test.jsp?id=<%=id%>">#<%=id%></a> created and initialized!
+
+<%@ include file="nav.jsp" %>
+<%@ page import="com.opensymphony.module.user.User,
+                 com.opensymphony.workflow.Workflow,
+                 com.opensymphony.workflow.basic.BasicWorkflow,
+                 com.opensymphony.workflow.spi.Step,
+                 java.util.*,
+                 com.opensymphony.workflow.loader.WorkflowDescriptor,
+                 com.opensymphony.workflow.loader.ActionDescriptor"%>
+<%
+    Workflow wf = new BasicWorkflow((String) session.getAttribute("username"));
+
+    long id = Long.parseLong(request.getParameter("id"));
+
+    String doString = request.getParameter("do");
+    if (doString != null && !doString.equals("")) {
+        int action = Integer.parseInt(doString);
+        wf.doAction(id, action, Collections.EMPTY_MAP);
+    }
+
+
+    int[] actions = wf.getAvailableActions(id);
+    WorkflowDescriptor wd = wf.getWorkflowDescriptor("example");
+
+    for (int i = 0; i < actions.length; i++) {
+        String name = wd.getAction(actions[i]).getName();
+        %>
+        <li> <a href="test.jsp?id=<%=id%>&do=<%= actions[i] %>"><%= name %></a>
+        <%
+    }
+%>
+
+<hr>
+<b>Permissions</b>
+<p>
+
+<%
+    List perms = wf.getSecurityPermissions(id);
+    for (Iterator iterator = perms.iterator(); iterator.hasNext();) {
+        String perm = (String) iterator.next();
+%>
+    <li><%= perm %>
+<%
+    }
+%>
+<hr>
+
+
+<table border="1">
+<tr>
+    <th>Step</th>
+    <th>Action</th>
+    <th>Status</th>
+    <th>Owner</th>
+    <th>Start Date</th>
+    <th>Finish Date</th>
+    <th>Previous</th>
+</tr>
+
+
+<%
+    ArrayList steps = new ArrayList();
+    steps.addAll(wf.getCurrentSteps(id));
+    steps.addAll(wf.getHistorySteps(id));
+    for (Iterator iterator = steps.iterator(); iterator.hasNext();) {
+        Step step = (Step) iterator.next();
+        String owner = step.getOwner();
+        ActionDescriptor action = wd.getAction(step.getActionId());
+        %>
+        <tr>
+            <td><%= wd.getStep(step.getStepId()).getName()%> (<%= step.getId() %>)</td>
+            <td><%= action == null ? "NONE" : action.getName() %></td>
+            <td><%= step.getStatus() %></td>
+            <td><%= owner %></td>
+            <td><%= step.getStartDate() %></td>
+            <td><%= step.getFinishDate() %></td>
+            <td><%
+                long[] prevIds = step.getPreviousStepIds();
+                if (prevIds != null) {
+                    for (int i = 0; i < prevIds.length; i++) {
+                        long prevId = prevIds[i];
+                        out.print(prevId + ", ");
+                    }
+                } else {
+                    out.print("none");
+                }
+            %></td>
+        </tr>
+        <%
+    }
+%>
+
+</table>
+
+<%@ include file="nav.jsp" %>