Source Code Cross Referenced for EditFormController.java in  » Groupware » LibreSource » org » libresource » web » controllers » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » LibreSource » org.libresource.web.controllers.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * LibreSource Community
003:         * Copyright (C) 2004-2007 Artenum SARL / INRIA
004:         * http://www.libresource.org - contact@artenum.com
005:         *
006:         * This software is not a free software; you can modify it under the
007:         * LibreSource Enterprise user license but you can't redistribute it.
008:         * See licenses details in LSE-user-license.txt 
009:         *
010:         * Initial authors :
011:         *
012:         * Guillaume Bort / INRIA
013:         * Francois Charoy / Universite Nancy 2
014:         * Julien Forest / Artenum
015:         * Claude Godart / Universite Henry Poincare
016:         * Florent Jouille / INRIA
017:         * Sebastien Jourdain / INRIA / Artenum
018:         * Yves Lerumeur / Artenum
019:         * Pascal Molli / Universite Henry Poincare
020:         * Gerald Oster / INRIA
021:         * Mariarosa Penzi / Artenum
022:         * Gerard Sookahet / Artenum
023:         * Raphael Tani / INRIA
024:         *
025:         * Contributors :
026:         *
027:         * Stephane Bagnier / Artenum
028:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
029:         */package org.libresource.web.controllers.form;
030:
031:        import org.libresource.Libresource;
032:
033:        import org.libresource.form.FormConstants;
034:        import org.libresource.form.FormField;
035:        import org.libresource.form.ejb.model.FormResourceValue;
036:        import org.libresource.form.interfaces.LibresourceFormService;
037:
038:        import org.libresource.kernel.KernelConstants;
039:        import org.libresource.kernel.LibresourceSecurityException;
040:        import org.libresource.kernel.interfaces.KernelService;
041:
042:        import org.libresource.web.Controller;
043:        import org.libresource.wiki.WikiConstants;
044:
045:        import java.net.URI;
046:
047:        import java.util.ArrayList;
048:        import java.util.Iterator;
049:        import java.util.Vector;
050:
051:        import javax.servlet.http.HttpServletRequest;
052:        import javax.servlet.http.HttpServletResponse;
053:
054:        public class EditFormController implements  Controller {
055:            private LibresourceFormService libresourceFormService;
056:
057:            public Object process(URI uri, HttpServletRequest request,
058:                    HttpServletResponse response) throws Exception {
059:                libresourceFormService = (LibresourceFormService) Libresource
060:                        .getService(FormConstants.SERVICE);
061:
062:                FormResourceValue form = libresourceFormService.getForm(uri);
063:                request.setAttribute("selectPage", Boolean.valueOf(form
064:                        .getResourceTypeToCreate().equals(
065:                                WikiConstants.RESOURCE)));
066:
067:                if (request.getParameter("cancel") != null) {
068:                    request.setAttribute("form", form);
069:                    request.setAttribute("description", form.getDescription());
070:
071:                    return uri;
072:                }
073:
074:                if (request.getParameter("name") == null) {
075:                    // TO prevent a deny later
076:                    KernelService kernelService = (KernelService) Libresource
077:                            .getService(KernelConstants.SERVICE);
078:
079:                    if (!kernelService.checkSecurity(uri,
080:                            KernelConstants.SECURITY_UPDATE)) {
081:                        throw new LibresourceSecurityException(uri,
082:                                KernelConstants.SECURITY_UPDATE);
083:                    }
084:
085:                    request.setAttribute("form", form);
086:
087:                    return "/pages/modules/form/editForm.jsp";
088:                }
089:
090:                // What kind of action
091:                if (request.getParameter("save") != null) {
092:                    if (saveData(uri, request, response)) {
093:                        form = libresourceFormService.getForm(uri);
094:                        request.setAttribute("form", form);
095:                        request.setAttribute("description", form
096:                                .getDescription());
097:                    } else {
098:                        form = libresourceFormService.getForm(uri);
099:                        form.setFormFields(getFields(request, response));
100:                        request.setAttribute("form", form);
101:                        request.setAttribute("description", form
102:                                .getDescription());
103:                        request
104:                                .setAttribute("error",
105:                                        "Error: Field Id and field Label can't be empty. Field Id must be unique.");
106:
107:                        return "/pages/modules/form/editForm.jsp";
108:                    }
109:                }
110:
111:                if (request.getParameter("addField") != null) {
112:                    if (saveData(uri, request, response)) {
113:                        libresourceFormService.addFormField(uri, new FormField(
114:                                ""));
115:
116:                        form = libresourceFormService.getForm(uri);
117:                        request.setAttribute("form", form);
118:
119:                        return "/pages/modules/form/editForm.jsp";
120:                    } else {
121:                        form = libresourceFormService.getForm(uri);
122:                        form.setFormFields(getFields(request, response));
123:                        request.setAttribute("form", form);
124:                        request.setAttribute("description", form
125:                                .getDescription());
126:                        request
127:                                .setAttribute("error",
128:                                        "Error: Field Id and field Label can't be empty. Field Id must be unique.");
129:
130:                        return "/pages/modules/form/editForm.jsp";
131:                    }
132:                }
133:
134:                // Check field moves/delete
135:                int nbFields = (form.getFormFields() == null) ? 0 : form
136:                        .getFormFields().size();
137:
138:                for (int i = 0; i < nbFields; i++) {
139:                    if (request.getParameter("up_field_" + i) != null) {
140:                        if (saveData(uri, request, response)) {
141:                            form = libresourceFormService.getForm(uri);
142:                            libresourceFormService.moveFormFieldUp(uri,
143:                                    ((FormField) form.getFormFields().get(i))
144:                                            .getFieldId());
145:                            form = libresourceFormService.getForm(uri);
146:                            request.setAttribute("form", form);
147:
148:                            return "/pages/modules/form/editForm.jsp";
149:                        } else {
150:                            form = libresourceFormService.getForm(uri);
151:                            form.setFormFields(getFields(request, response));
152:                            request.setAttribute("form", form);
153:                            request.setAttribute("description", form
154:                                    .getDescription());
155:                            request
156:                                    .setAttribute("error",
157:                                            "Error: Field Id and field Label can't be empty. Field Id must be unique.");
158:
159:                            return "/pages/modules/form/editForm.jsp";
160:                        }
161:                    }
162:
163:                    if (request.getParameter("down_field_" + i) != null) {
164:                        if (saveData(uri, request, response)) {
165:                            form = libresourceFormService.getForm(uri);
166:                            libresourceFormService.moveFormFieldDown(uri,
167:                                    ((FormField) form.getFormFields().get(i))
168:                                            .getFieldId());
169:                            form = libresourceFormService.getForm(uri);
170:                            request.setAttribute("form", form);
171:
172:                            return "/pages/modules/form/editForm.jsp";
173:                        } else {
174:                            form = libresourceFormService.getForm(uri);
175:                            form.setFormFields(getFields(request, response));
176:                            request.setAttribute("form", form);
177:                            request.setAttribute("description", form
178:                                    .getDescription());
179:                            request
180:                                    .setAttribute("error",
181:                                            "Error: Field Id and field Label can't be empty. Field Id must be unique.");
182:
183:                            return "/pages/modules/form/editForm.jsp";
184:                        }
185:                    }
186:
187:                    if (request.getParameter("addField_" + i) != null) {
188:                        if (saveData(uri, request, response)) {
189:                            libresourceFormService.addFormField(uri, i + 1,
190:                                    new FormField(""));
191:
192:                            form = libresourceFormService.getForm(uri);
193:                            request.setAttribute("form", form);
194:
195:                            return "/pages/modules/form/editForm.jsp";
196:                        } else {
197:                            form = libresourceFormService.getForm(uri);
198:                            form.setFormFields(getFields(request, response));
199:                            request.setAttribute("form", form);
200:                            request.setAttribute("description", form
201:                                    .getDescription());
202:                            request
203:                                    .setAttribute("error",
204:                                            "Error: Field Id and field Label can't be empty. Field Id must be unique.");
205:
206:                            return "/pages/modules/form/editForm.jsp";
207:                        }
208:                    }
209:
210:                    if (request.getParameter("delete_field_" + i) != null) {
211:                        saveData(uri, request, response);
212:                        form = libresourceFormService.getForm(uri);
213:                        libresourceFormService.removeFormField(uri,
214:                                ((FormField) form.getFormFields().get(i))
215:                                        .getFieldId());
216:                        form = libresourceFormService.getForm(uri);
217:                        request.setAttribute("form", form);
218:
219:                        return "/pages/modules/form/editForm.jsp";
220:                    }
221:                }
222:
223:                return uri;
224:            }
225:
226:            private boolean saveData(URI uri, HttpServletRequest request,
227:                    HttpServletResponse response) throws Exception {
228:                libresourceFormService.editForm(uri, request
229:                        .getParameter("name"), request
230:                        .getParameter("description"), request
231:                        .getParameter("destination"), request
232:                        .getParameter("typeCreation"), request
233:                        .getParameter("redirect"));
234:
235:                // Get forms fields
236:                Vector formFields = getFields(request, response);
237:
238:                // Check fields ID
239:                ArrayList fieldsIds = new ArrayList();
240:                Iterator fieldIterator = formFields.iterator();
241:                FormField currentField = null;
242:                boolean ok = true;
243:
244:                while (fieldIterator.hasNext()) {
245:                    currentField = (FormField) fieldIterator.next();
246:
247:                    if (fieldsIds.contains(currentField.getFieldId())
248:                            || (currentField.getFieldId().trim().length() == 0)
249:                            || (currentField.getFieldLabel().trim().length() == 0)) {
250:                        // Error
251:                        ok = false;
252:                    } else {
253:                        fieldsIds.add(currentField.getFieldId());
254:                    }
255:                }
256:
257:                if (ok) {
258:                    libresourceFormService.setFormFields(uri, formFields);
259:                }
260:
261:                request.setAttribute("selectPage", Boolean.valueOf(request
262:                        .getParameter("typeCreation").equals(
263:                                WikiConstants.RESOURCE)));
264:
265:                return ok;
266:            }
267:
268:            private Vector getFields(HttpServletRequest request,
269:                    HttpServletResponse response) throws Exception {
270:                // Get forms fields
271:                int formIndex = 0;
272:                Vector formFields = new Vector();
273:                FormField currentField = null;
274:
275:                while (request.getParameter("fieldID_" + formIndex) != null) {
276:                    currentField = new FormField(
277:                            request.getParameter("fieldID_" + formIndex),
278:                            request.getParameter("fieldLABEL_" + formIndex),
279:                            request.getParameter("fieldREQUIRED_" + formIndex) != null,
280:                            Integer.parseInt(request.getParameter("fieldTYPE_"
281:                                    + formIndex)));
282:                    currentField.setOptions(request
283:                            .getParameter("fieldOPTIONS_" + formIndex));
284:                    formFields.add(currentField);
285:                    formIndex++;
286:
287:                    // Check fields ID
288:                }
289:
290:                return formFields;
291:            }
292:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.