Source Code Cross Referenced for DisplayAction.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: DisplayAction.java,v $
031:         * Revision 1.8  2005/04/30 13:04:13  colinmacleod
032:         * Fixes reverting id type from String to Integer.
033:         *
034:         * Revision 1.7  2005/04/29 02:48:16  colinmacleod
035:         * Data bugfixes.
036:         * Changed primary key back to Integer.
037:         *
038:         * Revision 1.6  2005/04/28 18:47:07  colinmacleod
039:         * Fixed XHMTL, styles and resin compatibility.
040:         * Added support for URL rewriting.
041:         *
042:         * Revision 1.5  2005/04/26 15:07:07  colinmacleod
043:         * Consolidated print JSP into display pages (eliminating need for separate print pages).
044:         * Renamed Faq to FAQ.
045:         *
046:         * Revision 1.4  2005/04/22 09:53:33  colinmacleod
047:         * Removed table surrounding the page
048:         * links.
049:         *
050:         * Revision 1.3  2005/04/10 20:31:58  colinmacleod
051:         * Added new themes.
052:         * Changed id type to String.
053:         * Changed i tag to em and b tag to strong.
054:         * Improved PicoContainerFactory with NanoContainer scripts.
055:         *
056:         * Revision 1.2  2005/04/09 17:19:46  colinmacleod
057:         * Changed copyright text to GPL v2 explicitly.
058:         *
059:         * Revision 1.1.1.1  2005/03/10 17:52:01  colinmacleod
060:         * Restructured ivata op around Hibernate/PicoContainer.
061:         * Renamed ivata groupware.
062:         *
063:         * Revision 1.10  2004/12/31 18:27:44  colinmacleod
064:         * Added MaskFactory to constructor of MaskAction.
065:         *
066:         * Revision 1.9  2004/12/23 21:01:29  colinmacleod
067:         * Updated Struts to v1.2.4.
068:         * Changed base classes to use ivata masks.
069:         *
070:         * Revision 1.8  2004/11/12 18:19:15  colinmacleod
071:         * Change action and form classes to extend MaskAction, MaskForm respectively.
072:         *
073:         * Revision 1.7  2004/11/12 15:57:16  colinmacleod
074:         * Removed dependencies on SSLEXT.
075:         * Moved Persistence classes to ivata masks.
076:         *
077:         * Revision 1.6  2004/11/03 15:31:51  colinmacleod
078:         * Change method interfaces to remove log.
079:         *
080:         * Revision 1.5  2004/08/01 11:45:19  colinmacleod
081:         * Restructured search engine into separate subproject.
082:         *
083:         * Revision 1.4  2004/07/13 19:47:29  colinmacleod
084:         * Moved project to POJOs from EJBs.
085:         * Applied PicoContainer to services layer (replacing session EJBs).
086:         * Applied Hibernate to persistence layer (replacing entity EJBs).
087:         *
088:         * Revision 1.3  2004/03/21 21:16:29  colinmacleod
089:         * Shortened name to ivata op.
090:         *
091:         * Revision 1.2  2004/02/01 22:07:31  colinmacleod
092:         * Added full names to author tags
093:         *
094:         * Revision 1.1.1.1  2004/01/27 20:58:41  colinmacleod
095:         * Moved ivata openportal to SourceForge..
096:         *
097:         * Revision 1.5  2004/01/20 15:12:13  jano
098:         * fixing problems with new sslext
099:         *
100:         * Revision 1.4  2004/01/19 21:13:14  colin
101:         * Removed minutes for ivata groupware v0.9
102:         *
103:         * Revision 1.3  2003/10/28 13:16:14  jano
104:         * commiting library,
105:         * still fixing compile and building openGroupware project
106:         *
107:         * Revision 1.2  2003/10/15 14:16:53  colin
108:         * fixing for XDoclet
109:         *
110:         * Revision 1.14  2003/09/05 07:19:42  peter
111:         * changes in drive methods
112:         * Revision 1.13  2003/08/20 08:35:08  peter
113:         * directory issues fixed
114:         *
115:         * Revision 1.12  2003/08/18 11:38:55  peter
116:         * findByPath replaced by findByParentIdName
117:         *
118:         * Revision 1.11  2003/07/08 13:24:25  jano
119:         * we have library items in CVS
120:         *
121:         * Revision 1.10  2003/06/30 13:07:26  jano
122:         * we want new link in LinksOfpage
123:         *
124:         * Revision 1.9  2003/06/20 13:22:15  jano
125:         * we want deleteFile button in list of attached files
126:         *
127:         * Revision 1.8  2003/06/03 05:08:00  peter
128:         * changes due to posibility to change filelist from display mode
129:         *
130:         * Revision 1.7  2003/05/20 08:29:40  jano
131:         * maintaing attaching files to libray item
132:         *
133:         * Revision 1.6  2003/05/07 14:01:59  jano
134:         * we want findFilesByPath
135:         *
136:         * Revision 1.5  2003/03/27 15:40:46  jano
137:         * read pageInt from form befor seting to lastPage or 0
138:         *
139:         * Revision 1.4  2003/03/04 16:01:52  colin
140:         * fixed page for print.jsp
141:         *
142:         * Revision 1.3  2003/02/28 10:52:22  colin
143:         * when edit is pressed, now forwards to SubmitAction (was submit.jsp)
144:         *
145:         * Revision 1.2  2003/02/28 07:30:22  colin
146:         * implemented editing/displaying of faqs & notes
147:         *
148:         * Revision 1.1  2003/02/24 19:09:24  colin
149:         * moved to business
150:         * -----------------------------------------------------------------------------
151:         */
152:        package com.ivata.groupware.business.library.struts;
153:
154:        import java.net.MalformedURLException;
155:        import java.util.HashMap;
156:        import java.util.Iterator;
157:        import java.util.Locale;
158:
159:        import javax.servlet.http.HttpServletRequest;
160:        import javax.servlet.http.HttpServletResponse;
161:        import javax.servlet.http.HttpSession;
162:        import javax.servlet.jsp.JspFactory;
163:        import javax.servlet.jsp.PageContext;
164:
165:        import org.apache.struts.Globals;
166:        import org.apache.struts.action.ActionErrors;
167:        import org.apache.struts.action.ActionForm;
168:        import org.apache.struts.action.ActionMapping;
169:        import org.apache.struts.taglib.TagUtils;
170:        import org.apache.struts.util.MessageResources;
171:
172:        import com.ivata.groupware.admin.security.server.SecuritySession;
173:        import com.ivata.groupware.admin.setting.Settings;
174:        import com.ivata.groupware.business.library.Library;
175:        import com.ivata.groupware.business.library.faq.category.FAQCategoryDO;
176:        import com.ivata.groupware.business.library.item.LibraryItemConstants;
177:        import com.ivata.groupware.business.library.item.LibraryItemDO;
178:        import com.ivata.mask.MaskFactory;
179:        import com.ivata.mask.util.StringHandling;
180:        import com.ivata.mask.util.SystemException;
181:        import com.ivata.mask.web.RewriteHandling;
182:        import com.ivata.mask.web.struts.MaskAction;
183:        import com.ivata.mask.web.struts.MaskAuthenticator;
184:
185:        /**
186:         * <p><code>Action</code> invoked whenever a library item is
187:         * displayed.</p>
188:         *
189:         * @since 2003-02-18
190:         * @author Colin MacLeod
191:         * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
192:         * @version $Revision: 1.8 $
193:         */
194:        public class DisplayAction extends MaskAction {
195:            private Library library;
196:            private Settings settings;
197:
198:            /**
199:             * TODO
200:             * @param library
201:             * @param settings
202:             * @param maskFactory This factory is needed to access the masks and groups
203:             * of masks.
204:             * @param authenticator used to confirm whether or not the
205:             * user should be allowed to continue, in the <code>execute</code> method.
206:             */
207:            public DisplayAction(Library library, Settings settings,
208:                    MaskFactory maskFactory, MaskAuthenticator authenticator) {
209:                super (maskFactory, authenticator);
210:                this .library = library;
211:                this .settings = settings;
212:            }
213:
214:            /**
215:             * <p>Set information to display the item type correcly.</p>
216:             *
217:             * @param itemForm the fom which should be set up fo the given
218:             * type.
219:             */
220:            public void chooseItemType(final ItemForm itemForm) {
221:                LibraryItemDO item = itemForm.getItem();
222:
223:                // find out which page we're on (starting with 0)
224:                itemForm.setDeleteKey("display.alert.delete");
225:                Integer itemType = item.getType();
226:                assert (itemType != null);
227:
228:                if (itemType.equals(LibraryItemConstants.ITEM_MEETING)) {
229:                    itemForm.setThemeName("meeting");
230:                    itemForm.setSummaryThemeName("meetingSummary");
231:                    itemForm.setDeleteKey("display.alert.delete.isMeeting");
232:                    itemForm
233:                            .setDisplayIncludePage("/library/displayMeeting.jsp");
234:                } else if (itemType.equals(LibraryItemConstants.ITEM_NOTE)) {
235:                    itemForm.setThemeName("note");
236:                    itemForm.setSummaryThemeName("note");
237:                    itemForm.setDisplayIncludePage(null);
238:                    itemForm.setDisplayIncludePage(null);
239:                } else if (itemType.equals(LibraryItemConstants.ITEM_FAQ)) {
240:                    itemForm.setDisplayIncludePage("/library/displayFAQ.jsp");
241:                    itemForm.setThemeName("fAQ");
242:                    itemForm.setSummaryThemeName("fAQ");
243:                    itemForm.setDisplayIncludePage("/library/displayFAQ.jsp");
244:                } else {
245:                    itemForm
246:                            .setDisplayIncludePage("/library/displayMeeting.jsp");
247:                    itemForm.setThemeName("document");
248:                    itemForm.setSummaryThemeName("documentSummary");
249:                    itemForm
250:                            .setDisplayIncludePage("/library/displayDocument.jsp");
251:                }
252:            }
253:
254:            /**
255:             * <p>Overridden to proved flow for <code>onEdit</code> and
256:             * <code>onPreview</code>.</p>
257:             *
258:             * @param mapping current action mapping from <em>Struts</em> config.
259:             * @param log valid logging object to write messages to.
260:             * @param errors valid errors object to append errors to. If there are
261:             * any errors, the action will return to the input.
262:             * @param form optional ActionForm bean for this request (if any)
263:             * @param request non-HTTP request we are processing
264:             * @param response The non-HTTP response we are creating
265:             * @param session  returned from the <code>request</code> parameter.
266:             * @param userName current user name from session. .
267:             * @param settings valid, non-null settings from session.
268:             * @exception SystemException if there is any problem which
269:             * prevents processing. It will result in the webapp being forwarded
270:             * to
271:             * the standard error page.
272:             * @return this method returns the string used to identify the correct
273:             * <em>Struts</em> <code>ActionForward</code> which should follow this
274:             * page, or <code>null</code> if it should return to the input.
275:             *
276:             *
277:             */
278:            public String execute(final ActionMapping mapping,
279:                    final ActionErrors errors, final ActionForm form,
280:                    final HttpServletRequest request,
281:                    final HttpServletResponse response,
282:                    final HttpSession session) throws SystemException {
283:                ItemForm itemForm = (ItemForm) form;
284:                LibraryItemDO item = itemForm.getItem();
285:                Integer requestId = StringHandling.integerValue(request
286:                        .getParameter("id"));
287:                Integer requestMeetingId = StringHandling.integerValue(request
288:                        .getParameter("meetingId"));
289:                MessageResources resources = getResources(request);
290:                MessageResources libraryResources = getResources(request,
291:                        "library");
292:                Locale locale = (Locale) session
293:                        .getAttribute(Globals.LOCALE_KEY);
294:
295:                // used in computeURL
296:                JspFactory factory = JspFactory.getDefaultFactory();
297:                PageContext pageContext = factory.getPageContext(getServlet(),
298:                        request, response, "", true, 512, true);
299:
300:                // if there is an id in the request, that means find a new item
301:                SecuritySession securitySession = (SecuritySession) session
302:                        .getAttribute("securitySession");
303:                if (requestId != null) {
304:                    itemForm.setItem(item = library.findItemByPrimaryKey(
305:                            securitySession, requestId));
306:                    itemForm.setPreview(null);
307:                    itemForm.setEdit(null);
308:
309:                    // otherwise, if there is a meeting id in the request, find the item
310:                    // by the meeting id
311:                    /*            } else if (requestMeetingId != null) {
312:                     itemForm.setItem(item = library.findItemByMeetingId(
313:                     requestMeetingId));
314:                     itemForm.setPreview(null);
315:                     itemForm.setEdit(null);
316:                     */
317:                }
318:
319:                /*TODO
320:                 DirectoryDO attachmentDirectoryDO = drive.findDirectoryByParentIdName(DirectoryConstants.LIBRARY_DIRECTORY,
321:                 itemForm.getItem().getId().toString(), userName);
322:
323:                 // the list of already attached files
324:                 itemForm.setFileList((java.util.Vector) drive.findFilesByPath(
325:                 "/library/" + item.getId().toString(), userName));
326:
327:                 //list of new uploads
328:                 Vector uploadList = (java.util.Vector) drive.getUploads("drive",
329:                 userName);
330:
331:                 itemForm.setUploadingFileList(uploadList);
332:
333:                 // is user selected any file to remove and he did click on deleteFile button
334:                 if (!StringHandling.isNullOrEmpty(itemForm.getDeleteFileButton())) {
335:                 //remove attached files
336:                 for (Iterator i = itemForm.getFileList().iterator();
337:                 i.hasNext();) {
338:                 DriveFileDO tmpFile = (DriveFileDO) i.next();
339:
340:                 if (itemForm.getSelectedAttachedFilesIds(
341:                 tmpFile.getId().toString()) != null) {
342:                 drive.removeFile(tmpFile.getId(), userName);
343:                 }
344:                 }
345:
346:                 itemForm.setDeleteFileButton("");
347:                 }
348:
349:                 // attach is a flag set by javaScript, when something attachment
350:                 // related happened
351:                 if (!StringHandling.isNullOrEmpty(request.getParameter("attach"))) {
352:                 // if there are some uploads, commit them
353:                 if (!uploadList.isEmpty()) {
354:                 Vector uploadedFileNames = new Vector();
355:
356:                 for (Iterator i = uploadList.iterator(); i.hasNext();) {
357:                 FileDO fileDO = (FileDO) i.next();
358:                 DriveFileDO driveFileDO = new DriveFileDO();
359:
360:                 driveFileDO.setFileName(fileDO.getFileName());
361:                 driveFileDO.setDirectoryId(attachmentDirectoryDO.getId());
362:                 driveFileDO.setHeadRevision(new FileRevisionDO());
363:                 driveFileDO.getHeadRevision().setComment(fileDO.getComment());
364:                 driveFileDO.setCreatedBy(userName);
365:                 driveFileDO.setMimeType(fileDO.getMimeType());
366:                 driveFileDO.setSize(fileDO.getSize());
367:                 uploadedFileNames.add(fileDO.getFileName());
368:
369:                 try {
370:                 drive.commitFile(driveFileDO, userName, null);
371:                 } catch (RemoteException e) {
372:                 throw new SystemException(e);
373:                 }
374:                 }
375:
376:                 // remove uploaded files
377:                 try {
378:                 itemForm.setUploadingFileList(new Vector(
379:                 drive.removeUploads(uploadedFileNames, "drive",
380:                 userName)));
381:                 } catch (RemoteException e) {
382:                 throw new SystemException(e);
383:                 }
384:                 }
385:
386:                 // no wonder that we request back the current attachment list....
387:                 itemForm.setFileList((java.util.Vector) drive.findFilesByPath(
388:                 "/library/" + item.getId().toString(), userName));
389:                 }
390:                 */
391:
392:                // if edit was pressed, forward to the submit
393:                if (!StringHandling.isNullOrEmpty(itemForm.getEdit())) {
394:                    return "librarySubmitAction";
395:                }
396:
397:                chooseItemType(itemForm);
398:                setPageNumber("/library/display.action", request, response,
399:                        itemForm);
400:
401:                // add a printer to the page links, if we're not in submit
402:                HashMap printParameters = new HashMap();
403:                TagUtils tagUtils = TagUtils.getInstance();
404:
405:                printParameters.put("id", item.getId().toString());
406:                printParameters.put("print", "true");
407:
408:                String pageLink1 = "";
409:                String pageLink2 = "";
410:
411:                try {
412:                    pageLink1 = tagUtils.computeURL(pageContext, null, null,
413:                            "/library/display.action", null, null,
414:                            printParameters, null, true);
415:                    // TODO             pageLink2 = RequestUtils.computeURL(pageContext, null, null,
416:                    //                    "/library/downLoad.jsp", null, printParameters, null, true);
417:                } catch (MalformedURLException e) {
418:                    throw new SystemException(e);
419:                }
420:
421:                StringBuffer newLinks = new StringBuffer();
422:                if (request.getParameter("print") == null) {
423:                    newLinks.append(itemForm.getPageLinks());
424:                    newLinks.append("<a href='");
425:                    newLinks.append(pageLink1);
426:                    newLinks
427:                            .append("' target='_blank'><img class='printer' src='");
428:                    newLinks.append(RewriteHandling.getContextPath(request));
429:                    newLinks
430:                            .append("/library/images/printer.gif' border='0' alt='");
431:                    newLinks.append(libraryResources.getMessage(locale,
432:                            "displayItem.label.print"));
433:                    newLinks.append("' title='");
434:                    newLinks.append(libraryResources.getMessage(locale,
435:                            "displayItem.label.print"));
436:                    newLinks.append("' width='32' height='32'/></a>");
437:                    /* TODO
438:                     newLinks.append(
439:                     "<td><nobr><img src='/images/empty.gif' width='20' height='1'/><a href='");
440:                     newLinks.append(pageLink2);
441:                     newLinks.append("' target='_blank'><img src='");
442:                     newLinks.append(RewriteHandling.getContextPath(request));
443:                     newLinks.append("/library/images/downloadHTML.gif' border='0' alt='");
444:                     newLinks.append(libraryResources.getMessage(locale,
445:                     "displayItem.label.download"));
446:                     newLinks.append("' title='");
447:                     newLinks.append(libraryResources.getMessage(locale,
448:                     "displayItem.label.download"));
449:                     newLinks.append(
450:                     "' width='32' height='32'/></a></nobr></td>");
451:                     */
452:                }
453:                itemForm.setPageLinks(newLinks.toString());
454:
455:                return null;
456:            }
457:
458:            /**
459:             * <p>This method is called if the delete (confirm, not warn) button
460:             * is pressed.</p>
461:             * @param mapping current action mapping from <em>Struts</em> config.
462:             * @param errors valid errors object to append errors to. If there are
463:             * any errors, the action will return to the input.
464:             * @param form optional ActionForm bean for this request (if any)
465:             * @param request non-HTTP request we are processing
466:             * @param response The non-HTTP response we are creating
467:             * @param session  returned from the <code>request</code> parameter.
468:             * @param log valid logging object to write messages to.
469:             * @param userName valid, non-null user name from session.
470:             * @param settings valid, non-null settings from session.
471:             *
472:             * @exception SystemException if there is any problem which
473:             * prevents processing. It will result in the webapp being forwarded
474:             * to
475:             * the standard error page.
476:             * @return this method returns the string used to identify the correct
477:             * <em>Struts</em> <code>ActionForward</code> which should follow this
478:             * page, or <code>null</code> if it should return to the input.
479:             *
480:             */
481:            public String onDelete(final ActionMapping mapping,
482:                    final ActionErrors errors, final ActionForm form,
483:                    final HttpServletRequest request,
484:                    final HttpServletResponse response,
485:                    final HttpSession session, final String defaultForward)
486:                    throws SystemException {
487:                LibraryItemDO item = ((ItemForm) form).getItem();
488:                SecuritySession securitySession = (SecuritySession) session
489:                        .getAttribute("securitySession");
490:
491:                // remove library item
492:                library.removeItem(securitySession, item);
493:                /*TODO
494:                 // remove files
495:                 for (Iterator i = ((ItemForm) form).getFileList().iterator();
496:                 i.hasNext();) {
497:                 drive.removeFile(((DriveFileDO) i.next()).getId(), userName);
498:                 }
499:                 */
500:
501:                return "libraryIndex";
502:            }
503:
504:            /**
505:             * <p>Implementation of
506:             * <code>setPageNumber</code> for document types.</p>
507:             *
508:             * @pageContext used to create links.
509:             * @param linkPage the page to link the page numbers to.
510:             * @param request current request to check for a 'page' parameter
511:             * and to create links.
512:             * @param itemForm form to set page number <code>displayPage</code>.
513:             * @throws SystemException if there is any exception creating
514:             * the <code>URL</code>s.
515:             * @see setPageNumber
516:             */
517:            protected void setDocumentPageNumber(final PageContext pageContext,
518:                    final String linkPage, final HttpServletRequest request,
519:                    final ItemForm itemForm) throws SystemException {
520:                int pageInt = itemForm.getDisplayPage();
521:                LibraryItemDO item = itemForm.getItem();
522:                MessageResources libraryResources = getResources(request,
523:                        "library");
524:                Locale locale = (Locale) request.getSession().getAttribute(
525:                        Globals.LOCALE_KEY);
526:                StringBuffer links = new StringBuffer();
527:
528:                if (item.getPages().size() > 1) {
529:                    HashMap pageLinkParameters = new HashMap();
530:                    int numberOfPages = item.getPages().size();
531:
532:                    for (int i = 0; i < numberOfPages; ++i) {
533:                        // don't link to the current page; just show it
534:                        if (i == pageInt) {
535:                            links.append("&nbsp;");
536:                            links.append(i + 1);
537:                        } else {
538:                            pageLinkParameters.put("page", new Integer(i + 1)
539:                                    .toString());
540:
541:                            String pageLink;
542:
543:                            try {
544:                                pageLink = TagUtils.getInstance().computeURL(
545:                                        pageContext, null, null, linkPage,
546:                                        null, null, pageLinkParameters, null,
547:                                        true);
548:                            } catch (MalformedURLException e) {
549:                                throw new SystemException(e);
550:                            }
551:
552:                            links.append("&nbsp;<a href='");
553:                            links.append(pageLink);
554:                            links.append("'>");
555:                            links.append(i + 1);
556:                            links.append("</a>");
557:                        }
558:                    }
559:                }
560:
561:                itemForm.setPageLinks(links.toString());
562:            }
563:
564:            /**
565:             * <p>Implementation of
566:             * <code>setPageNumber</code> for FAQ types.</p>
567:             *
568:             * @pageContext used to create links.
569:             * @param linkPage the page to link the page numbers to.
570:             * @param request current request to check for a 'page' parameter
571:             * and to create links.
572:             * @param itemForm form to set page number <code>displayPage</code>.
573:             * @throws SystemException if there is any exception creating
574:             * the <code>URL</code>s.
575:             * @see setPageNumber
576:             */
577:            protected void setFaqPageNumber(final PageContext pageContext,
578:                    final String linkPage, final HttpServletRequest request,
579:                    final ItemForm itemForm) throws SystemException {
580:                int pageInt = itemForm.getDisplayPage();
581:                LibraryItemDO item = itemForm.getItem();
582:                MessageResources libraryResources = getResources(request,
583:                        "library");
584:                Locale locale = (Locale) request.getSession().getAttribute(
585:                        Globals.LOCALE_KEY);
586:
587:                // always show the contents
588:                // in this case, don't show a link as the contents is already displayed
589:                String link;
590:                HashMap linkParameters = new HashMap();
591:                StringBuffer links = new StringBuffer();
592:
593:                // first put out the agenda
594:                if (pageInt == 0) {
595:                    links = new StringBuffer(libraryResources.getMessage(
596:                            locale, "displayItem.label.contents"));
597:                } else {
598:                    linkParameters.put("page", "0");
599:
600:                    try {
601:                        link = TagUtils.getInstance().computeURL(pageContext,
602:                                null, null, linkPage, null, null,
603:                                linkParameters, null, true);
604:                    } catch (MalformedURLException e) {
605:                        throw new SystemException(e);
606:                    }
607:
608:                    links = new StringBuffer("<a href='");
609:                    links.append(link);
610:                    links.append("'>");
611:                    links.append(libraryResources.getMessage(locale,
612:                            "displayItem.label.contents"));
613:                    links.append("</a>");
614:                }
615:
616:                // now show each category numbered from 1
617:                int categoryLinkNumber = 0;
618:
619:                for (Iterator i = item.getFAQCategories().iterator(); i
620:                        .hasNext();) {
621:                    FAQCategoryDO category = (FAQCategoryDO) i.next();
622:
623:                    // don't link to the current page; just show it
624:                    if (++categoryLinkNumber == itemForm.getDisplayPage()) {
625:                        links.append("&nbsp;");
626:                        links.append(categoryLinkNumber);
627:                    } else {
628:                        linkParameters.put("page", new Integer(
629:                                categoryLinkNumber).toString());
630:
631:                        try {
632:                            link = TagUtils.getInstance().computeURL(
633:                                    pageContext, null, null, linkPage, null,
634:                                    null, linkParameters, null, true);
635:                        } catch (MalformedURLException e) {
636:                            throw new SystemException(e);
637:                        }
638:
639:                        links.append("&nbsp;<a href='");
640:                        links.append(link);
641:                        links.append("' title='");
642:                        links.append(category.getName());
643:                        links.append("'>");
644:                        links.append(categoryLinkNumber);
645:                        links.append("</a>");
646:                    }
647:                }
648:
649:                itemForm.setPageLinks(links.toString());
650:            }
651:
652:            /**
653:             * <p>Implementation of
654:             * <code>setPageNumber</code> for meeting types.</p>
655:             *
656:             * @pageContext used to create links.
657:             * @param linkPage the page to link the page numbers to.
658:             * @param request current request to check for a 'page' parameter
659:             * and to create links.
660:             * @param itemForm form to set page number <code>displayPage</code>.
661:             * @throws SystemException if there is any exception creating
662:             * the <code>URL</code>s.
663:             * @see setPageNumber
664:             */
665:            protected void setMeetingPageNumber(final PageContext pageContext,
666:                    final String linkPage, final HttpServletRequest request,
667:                    final ItemForm itemForm) throws SystemException {
668:                int pageInt = itemForm.getDisplayPage();
669:                LibraryItemDO item = itemForm.getItem();
670:
671:                MessageResources libraryResources = getResources(request,
672:                        "library");
673:                Locale locale = (Locale) request.getSession().getAttribute(
674:                        Globals.LOCALE_KEY);
675:
676:                // always show the agenda
677:                // in this case, don't show a link as the agenda is already displayed
678:                String agendaLink;
679:                HashMap agendaLinkParameters = new HashMap();
680:                StringBuffer links = new StringBuffer();
681:
682:                // first put out the agenda
683:                if (pageInt == 0) {
684:                    links = new StringBuffer(libraryResources.getMessage(
685:                            locale, "displayItem.label.agenda"));
686:                } else {
687:                    agendaLinkParameters.put("page", "0");
688:
689:                    try {
690:                        agendaLink = TagUtils.getInstance().computeURL(
691:                                pageContext, null, null, linkPage, null, null,
692:                                agendaLinkParameters, null, true);
693:                    } catch (MalformedURLException e) {
694:                        throw new SystemException(e);
695:                    }
696:
697:                    links = new StringBuffer("<a href='");
698:                    links.append(agendaLink);
699:                    links.append("'>");
700:                    links.append(libraryResources.getMessage(locale,
701:                            "displayItem.label.agenda"));
702:                    links.append("</a>");
703:                }
704:
705:                // now show each category numbered from 1
706:                int categoryLinkNumber = 0;
707:
708:                /**
709:                 * TODO: we should subclass/fire events to get around this
710:                MeetingDO meeting = item.getMeeting();
711:                for (Iterator i = meeting.getCategories().iterator(); i.hasNext();) {
712:                    String category = (String) i.next();
713:
714:                    // don't link to the current page; just show it
715:                    if (++categoryLinkNumber == itemForm.getDisplayPage()) {
716:                        links.append("&nbsp;");
717:                        links.append(categoryLinkNumber);
718:                    } else {
719:                        agendaLinkParameters.put("page",
720:                            new Integer(categoryLinkNumber).toString());
721:
722:                        try {
723:                            agendaLink = RequestUtils.computeURL(pageContext, null,
724:                                    null, linkPage, agendaLinkParameters, null, false,
725:                                    true);
726:                        } catch (MalformedURLException e) {
727:                            throw new SystemException(e);
728:                        }
729:
730:                        links.append("&nbsp;<a href='");
731:                        links.append(agendaLink);
732:                        links.append("' title='");
733:                        links.append(category);
734:                        links.append("'>");
735:                        links.append(categoryLinkNumber);
736:                        links.append("</a>");
737:                    }
738:                }
739:                 */
740:
741:                itemForm.setPageLinks(links.toString());
742:            }
743:
744:            /**
745:             * <p>Set the current page number from the request or form to the
746:             * <code>displayPage</code> attribute on the form.</p>
747:             *
748:             * <p>This method also sets the appropriate page links.</p>
749:             *
750:             * @param linkPage the page to link the page numbers to.
751:             * @param request current request to check for a 'page' parameter
752:             * and to create links.
753:             * @param response used to create links.
754:             * @param itemForm form to set page number <code>displayPage</code>.
755:             * @throws SystemException if there is any exception creating
756:             * the <code>URL</code>s.
757:             */
758:            public final void setPageNumber(final String linkPage,
759:                    final HttpServletRequest request,
760:                    final HttpServletResponse response, final ItemForm itemForm)
761:                    throws SystemException {
762:                LibraryItemDO item = itemForm.getItem();
763:                JspFactory factory = JspFactory.getDefaultFactory();
764:                PageContext pageContext = factory.getPageContext(getServlet(),
765:                        request, response, "", true, 512, true);
766:
767:                itemForm.setLinkPage(linkPage);
768:
769:                // offset is the difference between the counting routine and the request
770:                // parameter - we want page 1 to be 1, not 0 for documents
771:                int lastPage;
772:
773:                // offset is the difference between the counting routine and the request
774:                // parameter - we want page 1 to be 1, not 0 for documents
775:                int offset;
776:
777:                // find last page for meeeting
778:                Integer itemType = item.getType();
779:                assert (itemType != null);
780:                /**
781:                 * TODO: fix this via subclassing/fire events
782:                if (itemType.equals(LibraryItemConstants.ITEM_MEETING)) {
783:                    lastPage = item.getMeeting().getCategories().size();
784:                    offset = 0;
785:
786:                    // calculate last page for fequently asked questions
787:                } else         */
788:                if (itemType.equals(LibraryItemConstants.ITEM_FAQ)) {
789:                    lastPage = item.getFAQCategories().size();
790:                    offset = 0;
791:
792:                    // calculate last page for normal pages
793:                } else {
794:                    lastPage = item.getPages().size() - 1;
795:                    offset = 1;
796:                }
797:
798:                int pageInt = -1;
799:
800:                if (request.getParameter("page") != null) {
801:                    try {
802:                        pageInt = new Integer(request.getParameter("page"))
803:                                .intValue()
804:                                - offset;
805:                    } catch (NumberFormatException e) { // ignore all number conversion exceptions: the page will default to the first one
806:                    }
807:                } else {
808:                    pageInt = itemForm.getDisplayPage();
809:                }
810:
811:                if (pageInt > lastPage) {
812:                    pageInt = lastPage;
813:                }
814:
815:                // page indices can't normally be < 0
816:                if (pageInt < 0) {
817:                    pageInt = 0;
818:                }
819:
820:                itemForm.setDisplayPage(pageInt);
821:
822:                // calculate links for meetings
823:                if (itemType.equals(LibraryItemConstants.ITEM_MEETING)) {
824:                    setMeetingPageNumber(pageContext, linkPage, request,
825:                            itemForm);
826:
827:                    // calculate links for fequently asked questions
828:                } else if (itemType.equals(LibraryItemConstants.ITEM_FAQ)) {
829:                    setFaqPageNumber(pageContext, linkPage, request, itemForm);
830:
831:                    // calculate links for normal pages
832:                } else {
833:                    setDocumentPageNumber(pageContext, linkPage, request,
834:                            itemForm);
835:                }
836:
837:                // now the links for the next and previous page
838:                HashMap displayDocumentParameters = new HashMap();
839:                StringBuffer previousPageLink = new StringBuffer();
840:                StringBuffer nextPageLink = new StringBuffer();
841:                MessageResources libraryResources = getResources(request,
842:                        "library");
843:                Locale locale = (Locale) request.getSession().getAttribute(
844:                        Globals.LOCALE_KEY);
845:
846:                // no previous page for the first page!
847:                if (pageInt > 0) {
848:                    // 'human-readable' numbers start with 1
849:                    displayDocumentParameters.put("page", new Integer(
850:                            (pageInt + offset) - 1).toString());
851:                    previousPageLink.append("<a href='");
852:
853:                    try {
854:                        previousPageLink.append(TagUtils.getInstance()
855:                                .computeURL(pageContext, null, null, linkPage,
856:                                        null, null, displayDocumentParameters,
857:                                        null, true));
858:                    } catch (MalformedURLException e) {
859:                        throw new SystemException(e);
860:                    }
861:
862:                    previousPageLink.append("'>");
863:                    previousPageLink.append(libraryResources.getMessage(locale,
864:                            "displayDocument.link.previousPage"));
865:                    previousPageLink.append("</a>");
866:                }
867:
868:                itemForm.setPreviousPageLink(previousPageLink.toString());
869:
870:                // no next page for the last page!
871:                if (pageInt < lastPage) {
872:                    displayDocumentParameters.put("page", new Integer(pageInt
873:                            + offset + 1).toString());
874:                    nextPageLink.append("<a href='");
875:
876:                    try {
877:                        nextPageLink.append(TagUtils.getInstance().computeURL(
878:                                pageContext, null, null, linkPage, null, null,
879:                                displayDocumentParameters, null, true));
880:                    } catch (MalformedURLException e) {
881:                        throw new SystemException(e);
882:                    }
883:
884:                    nextPageLink.append("'>");
885:                    nextPageLink.append(libraryResources.getMessage(locale,
886:                            "displayDocument.link.nextPage"));
887:                    nextPageLink.append("</a>");
888:                }
889:
890:                itemForm.setNextPageLink(nextPageLink.toString());
891:            }
892:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.