Source Code Cross Referenced for CommentAction.java in  » Groupware » ivatagroupware » com » ivata » groupware » business » library » struts » 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 » ivatagroupware » com.ivata.groupware.business.library.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata groupware may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: CommentAction.java,v $
031:         * Revision 1.4  2005/04/29 02:48:16  colinmacleod
032:         * Data bugfixes.
033:         * Changed primary key back to Integer.
034:         *
035:         * Revision 1.3  2005/04/10 20:31:58  colinmacleod
036:         * Added new themes.
037:         * Changed id type to String.
038:         * Changed i tag to em and b tag to strong.
039:         * Improved PicoContainerFactory with NanoContainer scripts.
040:         *
041:         * Revision 1.2  2005/04/09 17:19:46  colinmacleod
042:         * Changed copyright text to GPL v2 explicitly.
043:         *
044:         * Revision 1.1.1.1  2005/03/10 17:52:02  colinmacleod
045:         * Restructured ivata op around Hibernate/PicoContainer.
046:         * Renamed ivata groupware.
047:         *
048:         * Revision 1.10  2004/12/31 18:27:43  colinmacleod
049:         * Added MaskFactory to constructor of MaskAction.
050:         *
051:         * Revision 1.9  2004/12/23 21:01:28  colinmacleod
052:         * Updated Struts to v1.2.4.
053:         * Changed base classes to use ivata masks.
054:         *
055:         * Revision 1.8  2004/11/12 18:19:15  colinmacleod
056:         * Change action and form classes to extend MaskAction, MaskForm respectively.
057:         *
058:         * Revision 1.7  2004/11/12 15:57:16  colinmacleod
059:         * Removed dependencies on SSLEXT.
060:         * Moved Persistence classes to ivata masks.
061:         *
062:         * Revision 1.6  2004/11/03 15:31:51  colinmacleod
063:         * Change method interfaces to remove log.
064:         *
065:         * Revision 1.5  2004/07/13 19:47:29  colinmacleod
066:         * Moved project to POJOs from EJBs.
067:         * Applied PicoContainer to services layer (replacing session EJBs).
068:         * Applied Hibernate to persistence layer (replacing entity EJBs).
069:         *
070:         * Revision 1.4  2004/03/21 21:16:29  colinmacleod
071:         * Shortened name to ivata op.
072:         *
073:         * Revision 1.3  2004/03/21 20:29:56  colinmacleod
074:         * Changed session variable called mailSession to securityServerSession.
075:         *
076:         * Revision 1.2  2004/02/01 22:07:31  colinmacleod
077:         * Added full names to author tags
078:         *
079:         * Revision 1.1.1.1  2004/01/27 20:58:40  colinmacleod
080:         * Moved ivata openportal to SourceForge..
081:         *
082:         * Revision 1.6  2004/01/12 14:01:03  jano
083:         * fixing bugs
084:         *
085:         * Revision 1.5  2003/12/16 15:08:46  jano
086:         * fixing library functionality
087:         *
088:         * Revision 1.4  2003/12/12 13:23:36  jano
089:         * fixing library functionality
090:         *
091:         * Revision 1.3  2003/10/28 13:16:14  jano
092:         * commiting library,
093:         * still fixing compile and building openGroupware project
094:         *
095:         * Revision 1.2  2003/10/15 14:16:53  colin
096:         * fixing for XDoclet
097:         *
098:         * Revision 1.9  2003/07/21 14:16:48  jano
099:         * we have new field - list
100:         * somethime we are commenting without itemForm in session
101:         * Revision 1.8  2003/06/30 07:12:29  peter
102:         * fixed flushing of commentTrees - all users want to see the news
103:         *
104:         * Revision 1.7  2003/06/30 05:23:07  peter
105:         * userName at the end of cache key, to match other cache namings
106:         *
107:         * Revision 1.6  2003/06/30 04:53:10  peter
108:         * comment tree is cached for each user separately now
109:         *
110:         * Revision 1.5  2003/06/09 12:06:13  peter
111:         * Implemented comment tree cache flushing on new/amended comment
112:         *
113:         * Revision 1.4  2003/03/04 17:26:32  colin
114:         * fixed bug in defaulting of subject (if parent is null)
115:         *
116:         * Revision 1.3  2003/02/28 13:44:12  colin
117:         * made comments work with Struts & popups
118:         *
119:         * Revision 1.2  2003/02/28 07:30:22  colin
120:         * implemented editing/displaying of faqs & notes
121:         *
122:         * Revision 1.1  2003/02/24 19:09:24  colin
123:         * moved to business
124:         * -----------------------------------------------------------------------------
125:         */
126:        package com.ivata.groupware.business.library.struts;
127:
128:        import javax.servlet.http.HttpServletRequest;
129:        import javax.servlet.http.HttpServletResponse;
130:        import javax.servlet.http.HttpSession;
131:
132:        import org.apache.struts.action.ActionErrors;
133:        import org.apache.struts.action.ActionForm;
134:        import org.apache.struts.action.ActionMapping;
135:
136:        import com.ivata.groupware.admin.security.server.SecuritySession;
137:        import com.ivata.groupware.admin.setting.Settings;
138:        import com.ivata.groupware.admin.setting.SettingsDataTypeException;
139:        import com.ivata.groupware.business.library.Library;
140:        import com.ivata.groupware.business.library.comment.CommentDO;
141:        import com.ivata.groupware.business.library.item.LibraryItemDO;
142:        import com.ivata.mask.MaskFactory;
143:        import com.ivata.mask.util.StringHandling;
144:        import com.ivata.mask.util.SystemException;
145:        import com.ivata.mask.web.struts.MaskAction;
146:        import com.ivata.mask.web.struts.MaskAuthenticator;
147:
148:        /**
149:         * <p>Invoked when the user edits, displays or enters a new library
150:         * comment.</p>
151:         *
152:         * @since 2003-02-18
153:         * @author Colin MacLeod
154:         * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
155:         * @version $Revision: 1.4 $
156:         *
157:         */
158:        public class CommentAction extends MaskAction {
159:            private Library library;
160:            private Settings settings;
161:
162:            /**
163:             *  TODO
164:             * @param library
165:             * @param settings
166:             * @param maskFactory This factory is needed to access the masks and groups
167:             * of masks.
168:             * @param authenticator used to confirm whether or not the
169:             * user should be allowed to continue, in the <code>execute</code> method.
170:             */
171:            public CommentAction(Library library, Settings settings,
172:                    MaskFactory maskFactory, MaskAuthenticator authenticator) {
173:                super (maskFactory, authenticator);
174:                this .library = library;
175:                this .settings = settings;
176:            }
177:
178:            /**
179:             * <p>Called when the clear button is pressed, or after an ok or
180:             * delete button, where the session should be restored to its default
181:             * state.</p>
182:             *
183:             * @param mapping The ActionMapping used to select this instance.
184:             * @param log valid logging object to write messages to.
185:             * @param errors valid errors object to append errors to. If there are
186:             * any errors, the action will return to the input.
187:             * @param form optional ActionForm bean for this request (if any)
188:             * @param request non-HTTP request we are processing
189:             * @param response The non-HTTP response we are creating
190:             * @param session  returned from the <code>request</code> parameter.
191:             * @param userName valid, non-null user name from session.
192:             * @param settings valid, non-null settings from session.
193:             * @exception SystemException if there is any problem which
194:             * prevents processing. It will result in the webapp being forwarded
195:             * to
196:             * the standard error page.
197:             */
198:            public void clear(final ActionMapping mapping,
199:                    final ActionErrors errors, final ActionForm form,
200:                    final HttpServletRequest request,
201:                    final HttpServletResponse response,
202:                    final HttpSession session) throws SystemException {
203:                // clear the comment form
204:                session.removeAttribute("libraryCommentForm");
205:            }
206:
207:            /**
208:             * <p>Overridden to TODO:.</p>
209:             *
210:             * @param mapping current action mapping from <em>Struts</em> config.
211:             * @param log valid logging object to write messages to.
212:             * @param errors valid errors object to append errors to. If there are
213:             * any errors, the action will return to the input.
214:             * @param form optional ActionForm bean for this request (if any)
215:             * @param request non-HTTP request we are processing
216:             * @param response The non-HTTP response we are creating
217:             * @param session  returned from the <code>request</code> parameter.
218:             * @param userName current user name from session. .
219:             * @param settings valid, non-null settings from session.
220:             * @exception SystemException if there is any problem which
221:             * prevents processing. It will result in the webapp being forwarded
222:             * to
223:             * the standard error page.
224:             * @return this method returns the string used to identify the correct
225:             * <em>Struts</em> <code>ActionForward</code> which should follow this
226:             * page, or <code>null</code> if it should return to the input.
227:             *
228:             *
229:             */
230:            public String execute(final ActionMapping mapping,
231:                    final ActionErrors errors, final ActionForm form,
232:                    final HttpServletRequest request,
233:                    final HttpServletResponse response,
234:                    final HttpSession session) throws SystemException {
235:                CommentForm commentForm = (CommentForm) form;
236:
237:                ItemForm itemForm = (ItemForm) session
238:                        .getAttribute("libraryItemForm");
239:
240:                if (StringHandling.isNullOrEmpty(commentForm.getList())) {
241:                    commentForm.setList("false");
242:                }
243:
244:                // if there is no item form, just get out
245:                // but only if we are not in list of openComments
246:                if (itemForm == null && commentForm.getList().equals("false")) {
247:                    return "utilClosePopUp";
248:                }
249:
250:                LibraryItemDO item = null;
251:
252:                if (commentForm.getList().equals("false")) {
253:                    item = itemForm.getItem();
254:                }
255:
256:                Integer requestParentId = StringHandling.integerValue(request
257:                        .getParameter("parentId"));
258:                Integer requestId = StringHandling.integerValue(request
259:                        .getParameter("id"));
260:                CommentDO comment = commentForm.getComment();
261:                CommentDO parent = null;
262:                if (comment != null) {
263:                    parent = comment.getParent();
264:                }
265:                SecuritySession securitySession = (SecuritySession) session
266:                        .getAttribute("securitySession");
267:                comment.setCreatedBy(securitySession.getUser());
268:
269:                // reply to an existing comment
270:                if (requestParentId != null) {
271:                    commentForm.setComment(comment = new CommentDO());
272:                    comment.setParent(parent = library.findCommentByPrimaryKey(
273:                            securitySession, requestParentId));
274:
275:                    // edit an existing comment
276:                } else if (requestId != null) {
277:                    commentForm
278:                            .setComment(comment = library
279:                                    .findCommentByPrimaryKey(securitySession,
280:                                            requestId));
281:                }
282:
283:                if (comment.getItem() == null) {
284:                    if (item != null) {
285:                        comment.setItem(item);
286:                    } else {
287:                        comment.setItem(parent.getItem());
288:                    }
289:                }
290:
291:                if (comment.getCreatedBy() == null) {
292:                    comment.setCreatedBy(securitySession.getUser());
293:                }
294:
295:                commentForm.setBundle("library");
296:                commentForm.setDeleteKey("submitComment.alert.delete");
297:
298:                // set default values here
299:                if (StringHandling.isNullOrEmpty(comment.getSubject())) {
300:                    try {
301:                        comment
302:                                .setSubject(settings.getStringSetting(
303:                                        securitySession,
304:                                        "emailSubjectReplyPrefix",
305:                                        securitySession.getUser())
306:                                        + (((parent == null) || StringHandling
307:                                                .isNullOrEmpty(parent
308:                                                        .getSubject())) ? ((item != null) ? item
309:                                                .getTitle()
310:                                                : comment.getItem().getTitle())
311:                                                : parent.getSubject()));
312:                    } catch (SettingsDataTypeException e) {
313:                        throw new SystemException(e);
314:                    }
315:                }
316:                return null;
317:            }
318:
319:            /**
320:             * <p>This method is called if the ok or apply buttons are
321:             * pressed.</p>
322:             *
323:             * @param mapping current action mapping from <em>Struts</em> config.
324:             * @param log valid logging object to write messages to.
325:             * @param errors valid errors object to append errors to. If there are
326:             * any errors, the action will return to the input.
327:             * @param form optional ActionForm bean for this request (if any)
328:             * @param request non-HTTP request we are processing
329:             * @param response The non-HTTP response we are creating
330:             * @param session  returned from the <code>request</code> parameter.
331:             * @param userName valid, non-null user name from session.
332:             * @param settings valid, non-null settings from session.
333:             * @param ok <code>true</code> if the ok button was pressed, otherwise
334:             * <code>false</code> if the apply button was pressed.
335:             * @exception SystemException if there is any problem which
336:             * prevents processing. It will result in the webapp being forwarded
337:             * to
338:             * the standard error page.
339:             * @return this method returns the string used to identify the correct
340:             * <em>Struts</em> <code>ActionForward</code> which should follow this
341:             * page, or <code>null</code> if it should return to the input.
342:             *
343:             */
344:            public String onConfirm(final ActionMapping mapping,
345:                    final ActionErrors errors, final ActionForm form,
346:                    final HttpServletRequest request,
347:                    final HttpServletResponse response,
348:                    final HttpSession session, final String defaultForward)
349:                    throws SystemException {
350:
351:                // new comment ?
352:                CommentDO comment = ((CommentForm) form).getComment();
353:                CommentDO parent = comment.getParent();
354:                SecuritySession securitySession = (SecuritySession) session
355:                        .getAttribute("securitySession");
356:                StringBuffer openerPage = new StringBuffer();
357:
358:                if (((CommentForm) form).getList().equals("true")) {
359:                    openerPage.append("/library/openComments.jsp");
360:                } else {
361:                    openerPage.append("/library/display.action?id=");
362:                    openerPage.append(comment.getItem().getId());
363:                }
364:
365:                if (comment.getId() == null) {
366:                    comment.setCreatedBy(securitySession.getUser());
367:
368:                    Integer parentId = (parent == null) ? null : parent.getId();
369:
370:                    comment = library.addComment(securitySession, comment);
371:                } else {
372:                    // amend an existing comment
373:                    library.amendComment(securitySession, comment);
374:                }
375:
376:                // flush the comment tree for this item from jsp cache
377:                //flushCache("itemCommentTree_" + comment.getItemId().toString(),PageContext.APPLICATION_SCOPE, request);
378:
379:                // if it was 'ok' we won't know the id till now
380:                if (!((CommentForm) form).getList().equals("true")) {
381:                    openerPage.append("#comment");
382:                    openerPage.append(comment.getId());
383:                }
384:
385:                request.setAttribute("openerPage", openerPage.toString());
386:
387:                return defaultForward;
388:            }
389:
390:            /**
391:             * <p>This method is called if the delete (confirm, not warn) button
392:             * is pressed.</p>
393:             * @param mapping current action mapping from <em>Struts</em> config.
394:             * @param errors valid errors object to append errors to. If there are
395:             * any errors, the action will return to the input.
396:             * @param form optional ActionForm bean for this request (if any)
397:             * @param request non-HTTP request we are processing
398:             * @param response The non-HTTP response we are creating
399:             * @param session  returned from the <code>request</code> parameter.
400:             * @param log valid logging object to write messages to.
401:             * @param userName valid, non-null user name from session.
402:             * @param settings valid, non-null settings from session.
403:             *
404:             * @exception SystemException if there is any problem which
405:             * prevents processing. It will result in the webapp being forwarded
406:             * to
407:             * the standard error page.
408:             * @return this method returns the string used to identify the correct
409:             * <em>Struts</em> <code>ActionForward</code> which should follow this
410:             * page, or <code>null</code> if it should return to the input.
411:             *
412:             */
413:            public String onDelete(final ActionMapping mapping,
414:                    final ActionErrors errors, final ActionForm form,
415:                    final HttpServletRequest request,
416:                    final HttpServletResponse response,
417:                    final HttpSession session, final String defaultForward)
418:                    throws SystemException {
419:                return null;
420:            }
421:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.