01: /**
02: * LibreSource Community
03: * Copyright (C) 2004-2007 Artenum SARL / INRIA
04: * http://www.libresource.org - contact@artenum.com
05: *
06: * This software is not a free software; you can modify it under the
07: * LibreSource Enterprise user license but you can't redistribute it.
08: * See licenses details in LSE-user-license.txt
09: *
10: * Initial authors :
11: *
12: * Guillaume Bort / INRIA
13: * Francois Charoy / Universite Nancy 2
14: * Julien Forest / Artenum
15: * Claude Godart / Universite Henry Poincare
16: * Florent Jouille / INRIA
17: * Sebastien Jourdain / INRIA / Artenum
18: * Yves Lerumeur / Artenum
19: * Pascal Molli / Universite Henry Poincare
20: * Gerald Oster / INRIA
21: * Mariarosa Penzi / Artenum
22: * Gerard Sookahet / Artenum
23: * Raphael Tani / INRIA
24: *
25: * Contributors :
26: *
27: * Stephane Bagnier / Artenum
28: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29: */package org.libresource.web.controllers.form;
30:
31: import org.libresource.Libresource;
32:
33: import org.libresource.form.Form;
34: import org.libresource.form.FormConstants;
35: import org.libresource.form.FormField;
36: import org.libresource.form.FormFieldRequiredException;
37:
38: import org.libresource.kernel.KernelConstants;
39: import org.libresource.kernel.interfaces.KernelService;
40:
41: import org.libresource.web.Controller;
42:
43: import java.net.URI;
44:
45: import javax.servlet.http.HttpServletRequest;
46: import javax.servlet.http.HttpServletResponse;
47:
48: public class EditFormInPlaceController implements Controller {
49: private KernelService kernelService;
50:
51: public Object process(URI uri, HttpServletRequest request,
52: HttpServletResponse response) throws Exception {
53: // Generic op
54: if (kernelService == null) {
55: kernelService = (KernelService) Libresource
56: .getService(KernelConstants.SERVICE);
57: }
58:
59: // ok => save the new values
60: if (request.getParameter("ok") != null) {
61: // retreive data model
62: Form form = ((Form) kernelService.getPropertyObject(uri,
63: FormConstants.NODE_PROPERTY_FORM));
64:
65: // retreive meta-data
66: for (FormField currentField : form.getFormFields()) {
67: try {
68: currentField.updateValueFromRequest(request);
69: } catch (FormFieldRequiredException e) {
70: }
71: }
72:
73: // save data
74: kernelService.setProperty(uri,
75: FormConstants.NODE_PROPERTY_FORM, form);
76:
77: return uri;
78: }
79:
80: // Cancel / view the form
81: request.setAttribute("form", kernelService.getPropertyObject(
82: uri, FormConstants.NODE_PROPERTY_FORM));
83: request.setAttribute("description", "");
84: request.setAttribute("submitAction", "editFormInPlace");
85:
86: return "/pages/modules/form/viewForm.jsp";
87: }
88: }
|