// user need cancel
if (request.getParameter("cancel") != null) {
try {
Mapping.begin();
Publication publication = Publication.getInstance(id);
// LockManager locks =
// (LockManager) servlet.getServletContext().getAttribute(
// "locks");
// locks.unlock(publication);
Mapping.rollback();
} catch (Exception e) {
Mapping.rollback();
throw new ServletException(e);
}
// Forward to the next page
return (mapping.findForward("cancel"));
}
// fill data | first time
if (request.getParameter("itsOk") == null) {
try {
Mapping.begin();
Publication publication = Publication.getInstance(id);
String editForm = FormGenerator.getForm(publication);
// LockManager locks =
// (LockManager) servlet.getServletContext().getAttribute(
// "locks");
//
// if( locks.isLocked(publication) ) {
// throw new Exception("La publication "+publication.getId()+" est bloqu�e par un autre utilisateur." );
// }
//
// locks.lock(
// publication,
// User.getInstance(
// request.getSession().getAttribute("userLogin") + ""));
Mapping.rollback();
request.setAttribute("publication", publication);
request.setAttribute("editForm", editForm);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
sform.setDate(formatter.format(publication.getDate()));
} catch (Exception e) {
Mapping.rollback();
throw new ServletException(e);
}
// Forward to the view page
return (mapping.findForward("view"));
}
// fill data | errors
if (errors.size() > 0) {
try {
Mapping.begin();
Publication publication = Publication.getInstance(id);
Hashtable data = new Hashtable();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement().toString();
data.put(name, request.getParameter(name));
}
String editForm =
FormGenerator.getForm(publication.getType(), data);
Mapping.rollback();
request.setAttribute("publication", publication);
request.setAttribute("editForm", editForm);
request.setAttribute(ERROR_KEY, errors);
} catch (Exception e) {
Mapping.rollback();
throw new ServletException(e);
}
// Forward to the view page
return (mapping.findForward("view"));
}
// all it's ok : update publication
try {
Mapping.begin();
Publication publication = Publication.getInstance(id);
Hashtable data = new Hashtable();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement().toString();
String value = request.getParameter(name);
if (!value.trim().equals("")) {
data.put(name, request.getParameter(name));
}
}
publication.setData(data, true);
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
publication.setDate(formatter.parse(sform.getDate()));
// LockManager locks =
// (LockManager) servlet.getServletContext().getAttribute("locks");
// locks.unlock(publication);