public class GraphicalViewEditHandler implements UrlHandler {
@Override
public View handleRequest(HttpServletRequest request, HttpServletResponse response, Map<String, Object> model)
throws Exception {
GraphicalView view;
User user = Common.getUser(request);
// Fresh hit. Get the id.
String viewIdStr = request.getParameter("viewId");
if (viewIdStr != null) {
// An existing view.
view = new GraphicalViewDao().getView(Integer.parseInt(viewIdStr));
if (view == null)
// Doesn't exist. Redirect back to the views page.
return new RedirectView("/views.shtm");
GraphicalViewsCommon.ensureViewEditPermission(user, view);
if ("true".equals(request.getParameter("copy"))) {
// Make a copy
GraphicalView copy = new GraphicalView();
copy.setId(Common.NEW_ID);
copy.setUserId(user.getId());
copy.setXid(new GraphicalViewDao().generateUniqueXid());
copy.setName(StringUtils.abbreviate(TranslatableMessage.translate(
ControllerUtils.getTranslations(request), "common.copyPrefix", view.getName()), 100));
copy.setBackgroundFilename(GraphicalViewsCommon.copyImage(view.getBackgroundFilename()));
for (ViewComponent vc : view.getViewComponents())
copy.addViewComponent(vc);
view = copy;
}
}
else {
// A new view.
view = new GraphicalView();
view.setId(Common.NEW_ID);
view.setUserId(user.getId());
view.setXid(new GraphicalViewDao().generateUniqueXid());
}
GraphicalViewsCommon.setUserEditView(user, view);
view.validateViewComponents(false);