HttpServletResponse response) {
User user = (User) request.getSession().getAttribute("user");
ArrayList<String> errors = new ArrayList<String>();
HashMap<String, String> fieldMessages = new HashMap<String, String>();
Command command = (Command) request.getAttribute("command");
WorkflowManager workflowManager = new WorkflowManager();
// handle the "view vs. admin"-specific changes
String openNodesAttributeName = command.isViewCommand() ? "openViewNodes"
: "openTreeNodes";
String contentListPage = "/"
+ command.getDisplayProject()
+ (command.isViewCommand() ? "/Content.jsp"
: "/admin/ContentList.jsp");
String vboViewPage = "/"
+ command.getDisplayProject()
+ (command.isViewCommand() ? "/VBODisplay.jsp"
: "/admin/Community.jsp");
if (command.isViewCommand()) {
request.setAttribute("vboType", "Community");
}
// then do the regular page processing
ArrayList<Integer> openNodes = (ArrayList<Integer>) request
.getSession().getAttribute(openNodesAttributeName);
if (openNodes == null) {
openNodes = new ArrayList<Integer>();
}
boolean goToList = true;
String cancel;
if ((command.getModifier() != null)
&& (command.getModifier().equals("items"))) {
// get the listing of items that belong to this community
getItemWrappersForNode(command, (User) request.getSession()
.getAttribute("user"), request);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("search"))) {
// prep for search functions
setSearchObject(command, new CommunityManager(), request, errors);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("open"))) {
// open nodes in the content tree
openNodes(command, request, openNodesAttributeName, openNodes);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("close"))) {
// close nodes in the content tree
closeNodes(command, request, openNodesAttributeName, openNodes);
} else if (((cancel = request.getParameter("cancelChanges")) != null)
&& (cancel.equals("yes"))) {
// user has elected to cancel changes made to a form
request.setAttribute("successMessages",
"Your changes have been cancelled.");
int idToCancel = Integer.parseInt(request
.getParameter("communityId"));
ContentLockManager.unlockContentByTypeAndID(ContentType.COMMUNITY
.getValue(), idToCancel);
goToList = true;
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("add"))) {
goToList = handleCommunityAddRequest(request, command, errors,
user, openNodes, openNodesAttributeName);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("update"))
&& (!command.isViewCommand())) {
goToList = handleCommunityUpdateRequest(request, command, errors,
user, openNodes, fieldMessages);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("view"))
&& (command.isViewCommand())) {
goToList = handleCommunityViewRequest(request, command);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("delete"))) {
goToList = handleCommunityDeleteRequest(request, command, errors,
user);
} else if ((command.getModifier() != null)
&& (command.getModifier().equals("history"))) {
goToList = handleHistoryRequest(request, command, errors, user);
}
Community community = request.getAttribute("community") == null ? null
: (Community) request.getAttribute("community");
// one last permissions check if we're on our way to the edit page
if ((community != null)
&& (!command.isViewCommand())
&& (errors.size() == 0)
&& (fieldMessages.size() == 0)
&& (!goToList)
&& (!workflowManager.canEdit(user, command.getProject(),
command.getCommand(), community.getCommunityId()))) {
errors.add("You don't have permission to "
+ "work on the requested content.");
goToList = true;
}