String action = request.getParameter("action");
if (action == null) {
action = "view";
}
WFSRoot root = getRoot(request);
WFSSnapshot snapshot = null;
if (root instanceof WFSSnapshot) {
snapshot = (WFSSnapshot) root;
}
SnapshotResult result = null;
if (action.equalsIgnoreCase("update")) {
result = doUpdate(request, response, snapshot);
} else if (action.equalsIgnoreCase("edit")) {
result = doEdit(request, response, snapshot);
} else if (action.equalsIgnoreCase("remove")) {
result = doRemove(request, response, snapshot);
} else if (action.equalsIgnoreCase("snapshot")) {
result = doSnapshot(request, response);
} else if (action.equalsIgnoreCase("current")) {
result = doCurrent(request, response, root);
} else if (action.equalsIgnoreCase("restore")) {
result = doRestore(request, response, root);
}
if (result != null) {
// make the error visible
request.setAttribute("error", result.getError());
if (result.hasError()) {
logger.warning("Error processing action " + action + ": " +
result.getError());
}
// redirect to the requested page
if (result.hasRedirect()) {
RequestDispatcher rd = getServletContext().getRequestDispatcher(result.getRedirect());
rd.forward(request, response);
return;
}
}
// if we get here, we are going to display the main page
// store the wfs roots in a variable
List<WFSRoot> wfsRoots = m.getWFSRoots();
wfsRoots.add(0, EMPTY_WORLD);
request.setAttribute("roots", wfsRoots);
// store the wfs snapshots in a variable. Sort the snapshots by date
List<WFSSnapshot> snapshots = m.getWFSSnapshots();
Collections.sort(snapshots, new Comparator<WFSSnapshot>() {
public int compare(WFSSnapshot o1, WFSSnapshot o2) {
if (o1.getTimestamp() == null) {
return (o2.getTimestamp() == null)?0:1;
} else if (o2.getTimestamp() == null) {
return -1;
}
return -1 * o1.getTimestamp().compareTo(o2.getTimestamp());
}
});
request.setAttribute("snapshots", snapshots);
// find the current snapshot
WFSRoot currentRoot = getCurrentRoot(wfsRoots, snapshots);
request.setAttribute("currentroot", currentRoot);
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/snapshots.jsp");
rd.forward(request, response);