&& (command.getModifier().equals("history"))) {
// user is requesting an old item record from the audit log
goToList = false;
String[] vals = command.getOther().get(0).split("\\|");
AuditLogManager alm = new AuditLogManager();
int itemId = -1;
try {
itemId = Integer.parseInt(vals[2]);
if (!workflowManager.canEdit(user, command.getProject(),
command.getCommand(), itemId)) {
errors.add("You don't have permission to edit "
+ "the requested item.");
goToList = true;
} else {
AuditLog record = alm.getRecord(Integer.parseInt(vals[0]),
ContentType.valueOf(Integer.parseInt(vals[1])),
(itemId = Integer.parseInt(vals[2])), Timestamp
.valueOf(vals[3]));
String data = record.getDataExport();
item = new Item();
item.fromString(data);
}
} catch (NullPointerException e) {
goToList = true;
errors.add("Invalid history request format.");
} catch (NumberFormatException e) {
goToList = true;
errors.add("Invalid history request format.");
} catch (NoSuchAuditLogRecordException e) {
errors.add("The history record requested couldn't be located.");
} catch (DataTypeMismatchException e) {
Logger.error("Data type mismatch occurred pulling "
+ command.getOther().get(0) + " from the audit log", e);
errors
.add("A system error was encountered (DataTypeMismatch). "
+ "Please contact a system administrator.");
}
if (!goToList) {
if (item == null) {
try {
item = itemManager.getItem(command, itemId, false);
} catch (NoSuchItemException e) {
goToList = true;
errors.add("No such item (" + itemId + ") found.");
}
}
}
request.setAttribute("isDirty", "t");
}
// one last permissions check if we're on our way to the edit page
if ((item != null)
&& (!command.isViewCommand())
&& (errors.size() == 0)
&& (fieldMessages.size() == 0)
&& (!goToList)
&& (!workflowManager.canEdit(user, command.getProject(),
command.getCommand(), item.getItemId()))) {
errors.add("You don't have permission to "
+ "work on the requested content.");
goToList = true;
}
if (errors.size() > 0) {
request.setAttribute("errorMessage", generateErrorMessage(errors));
}
if (fieldMessages.size() > 0) {
request.setAttribute("fieldMessages", fieldMessages);
}
if (goToList) {
// the request dispatcher's forward method strips anchors, so we
// set page target here and let the ContentList.jsp handle it
// in the body tag's onload event.
if (item != null) {
if (request.getParameter("parentId") != null) {
request.setAttribute("jumpToTarget", "#node"
+ request.getParameter("parentId"));
} else {
request.setAttribute("jumpToTarget", "#node"
+ item.getItemId());
}
}
if ((command.getModifier() == null)
|| (!command.getModifier().equals("search"))) {
ArrayList<VBOTreeNodeWrapper> tree = TreeManager.getInstance()
.getTreeNodeWrappers(
command.getProject(),
openNodes,
command.isViewCommand() ? true : false,
-1,
(User) request.getSession()
.getAttribute("user"));
request.setAttribute("tree", tree);
}
// if this is from a search, flag it as such for the ContentList.jsp
// page
if (request.getParameter("fs") != null) {
command.setModifier("search");
ArrayList<String> other = new ArrayList<String>();
other.add("results");
command.setOther(other);
} else if ((updated)
&& (request.getSession().getAttribute("savedCommand") != null)) {
command = (Command) request.getSession().getAttribute(
"savedCommand");
try {
request.getRequestDispatcher(
response.encodeURL("/do" + command.buildURL()))
.forward(request, response);
return;
} catch (ServletException e) {
Logger.error("Couldn't forward request ContentList.jsp", e);
} catch (IOException e) {
Logger.error("Couldn't forward request ContentList.jsp", e);
}
}
try {
request.getRequestDispatcher(
response.encodeURL(contentListPage)).forward(request,
response);
} catch (ServletException e) {
Logger.error("Couldn't forward request to " + contentListPage,
e);
} catch (IOException e) {
Logger.error("Couldn't forward request to " + contentListPage,
e);
}
} else {
ArrayList<GUIElement> guiElements = item.getGUIElements();
String addToRepeatables = request.getParameter("addToRepeatables");
if ((addToRepeatables != null)
&& (addToRepeatables.trim().length() > 0)) {
for (GUIElement guiElem : guiElements) {
if (guiElem.getName().equals(addToRepeatables)) {
guiElem.setRepeatableElementsToAdd(3);
request.setAttribute("isDirty", "t");
break;
}
}
}
request.setAttribute("elements", guiElements);
request.setAttribute("item", item);
ArrayList<AuditLog> historyRecords = (new AuditLogManager())
.getUpdateRecords(
((HashMap<String, Project>) getServletContext()
.getAttribute("projectMap")).get(
command.getProject()).getProjectId(),
ContentType.ITEM, item.getItemId());