1 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 195 public class DisplayAction extends MaskAction { 196 private Library library; 197 private Settings settings; 198 199 208 public DisplayAction(Library library, Settings settings, 209 MaskFactory maskFactory, MaskAuthenticator authenticator) { 210 super(maskFactory, authenticator); 211 this.library = library; 212 this.settings = settings; 213 } 214 215 221 public void chooseItemType(final ItemForm itemForm) { 222 LibraryItemDO item = itemForm.getItem(); 223 224 itemForm.setDeleteKey("display.alert.delete"); 226 Integer itemType = item.getType(); 227 assert (itemType != null); 228 229 if (itemType.equals(LibraryItemConstants.ITEM_MEETING)) { 230 itemForm.setThemeName("meeting"); 231 itemForm.setSummaryThemeName("meetingSummary"); 232 itemForm.setDeleteKey("display.alert.delete.isMeeting"); 233 itemForm.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.setDisplayIncludePage("/library/displayMeeting.jsp"); 246 itemForm.setThemeName("document"); 247 itemForm.setSummaryThemeName("documentSummary"); 248 itemForm.setDisplayIncludePage("/library/displayDocument.jsp"); 249 } 250 } 251 275 public String execute(final ActionMapping mapping, 276 final ActionErrors errors, 277 final ActionForm form, 278 final HttpServletRequest request, 279 final HttpServletResponse response, 280 final HttpSession session) throws SystemException { 281 ItemForm itemForm = (ItemForm) form; 282 LibraryItemDO item = itemForm.getItem(); 283 Integer requestId = StringHandling.integerValue(request.getParameter( 284 "id")); 285 Integer requestMeetingId = StringHandling.integerValue(request.getParameter( 286 "meetingId")); 287 MessageResources resources = getResources(request); 288 MessageResources libraryResources = getResources(request, "library"); 289 Locale locale = (Locale ) session.getAttribute(Globals.LOCALE_KEY); 290 291 JspFactory factory = JspFactory.getDefaultFactory(); 293 PageContext pageContext = factory.getPageContext(getServlet(), request, 294 response, "", true, 512, true); 295 296 SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession"); 298 if (requestId != null) { 299 itemForm.setItem(item = library.findItemByPrimaryKey(securitySession, 300 requestId)); 301 itemForm.setPreview(null); 302 itemForm.setEdit(null); 303 304 312 } 313 314 386 387 if (!StringHandling.isNullOrEmpty(itemForm.getEdit())) { 389 return "librarySubmitAction"; 390 } 391 392 chooseItemType(itemForm); 393 setPageNumber("/library/display.action", request, response, itemForm); 394 395 HashMap printParameters = new HashMap (); 397 TagUtils tagUtils = TagUtils.getInstance(); 398 399 printParameters.put("id", item.getId().toString()); 400 printParameters.put("print", "true"); 401 402 String pageLink1 = ""; 403 String pageLink2 = ""; 404 405 try { 406 pageLink1 = tagUtils.computeURL(pageContext, null, null, 407 "/library/display.action", null, null, printParameters, 408 null, true); 409 } catch (MalformedURLException e) { 412 throw new SystemException(e); 413 } 414 415 StringBuffer newLinks = new StringBuffer (); 416 if (request.getParameter("print") == null) { 417 newLinks.append(itemForm.getPageLinks()); 418 newLinks.append("<a HREF='"); 419 newLinks.append(pageLink1); 420 newLinks.append("' target='_blank'><img class='printer' SRC='"); 421 newLinks.append(RewriteHandling.getContextPath(request)); 422 newLinks.append("/library/images/printer.gif' border='0' alt='"); 423 newLinks.append(libraryResources.getMessage(locale, 424 "displayItem.label.print")); 425 newLinks.append("' title='"); 426 newLinks.append(libraryResources.getMessage(locale, 427 "displayItem.label.print")); 428 newLinks.append("' width='32' height='32'/></a>"); 429 444 } 445 itemForm.setPageLinks(newLinks.toString()); 446 447 return null; 448 } 449 450 473 public String onDelete(final ActionMapping mapping, 474 final ActionErrors errors, 475 final ActionForm form, 476 final HttpServletRequest request, 477 final HttpServletResponse response, 478 final HttpSession session, final String defaultForward) throws SystemException { 479 LibraryItemDO item = ((ItemForm) form).getItem(); 480 SecuritySession securitySession = (SecuritySession) session.getAttribute("securitySession"); 481 482 library.removeItem(securitySession, item); 484 491 492 return "libraryIndex"; 493 } 494 495 508 protected void setDocumentPageNumber(final PageContext pageContext, 509 final String linkPage, 510 final HttpServletRequest request, 511 final ItemForm itemForm) 512 throws SystemException { 513 int pageInt = itemForm.getDisplayPage(); 514 LibraryItemDO item = itemForm.getItem(); 515 MessageResources libraryResources = getResources(request, "library"); 516 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 517 StringBuffer links = new StringBuffer (); 518 519 if (item.getPages().size() > 1) { 520 HashMap pageLinkParameters = new HashMap (); 521 int numberOfPages = item.getPages().size(); 522 523 for (int i = 0; i < numberOfPages; ++i) { 524 if (i == pageInt) { 526 links.append(" "); 527 links.append(i + 1); 528 } else { 529 pageLinkParameters.put("page", new Integer (i + 1).toString()); 530 531 String pageLink; 532 533 try { 534 pageLink = TagUtils.getInstance().computeURL(pageContext, null, 535 null, linkPage, null, null, pageLinkParameters, null, true); 536 } catch (MalformedURLException e) { 537 throw new SystemException(e); 538 } 539 540 links.append(" <a HREF='"); 541 links.append(pageLink); 542 links.append("'>"); 543 links.append(i + 1); 544 links.append("</a>"); 545 } 546 } 547 } 548 549 itemForm.setPageLinks(links.toString()); 550 } 551 552 565 protected void setFaqPageNumber(final PageContext pageContext, 566 final String linkPage, 567 final HttpServletRequest request, 568 final ItemForm itemForm) 569 throws SystemException { 570 int pageInt = itemForm.getDisplayPage(); 571 LibraryItemDO item = itemForm.getItem(); 572 MessageResources libraryResources = getResources(request, "library"); 573 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 574 575 String link; 578 HashMap linkParameters = new HashMap (); 579 StringBuffer links = new StringBuffer (); 580 581 if (pageInt == 0) { 583 links = new StringBuffer (libraryResources.getMessage(locale, 584 "displayItem.label.contents")); 585 } else { 586 linkParameters.put("page", "0"); 587 588 try { 589 link = TagUtils.getInstance().computeURL(pageContext, null, null, 590 linkPage, null, null, linkParameters, null, true); 591 } catch (MalformedURLException e) { 592 throw new SystemException(e); 593 } 594 595 links = new StringBuffer ("<a HREF='"); 596 links.append(link); 597 links.append("'>"); 598 links.append(libraryResources.getMessage(locale, 599 "displayItem.label.contents")); 600 links.append("</a>"); 601 } 602 603 int categoryLinkNumber = 0; 605 606 for (Iterator i = item.getFAQCategories().iterator(); i.hasNext();) { 607 FAQCategoryDO category = (FAQCategoryDO) i.next(); 608 609 if (++categoryLinkNumber == itemForm.getDisplayPage()) { 611 links.append(" "); 612 links.append(categoryLinkNumber); 613 } else { 614 linkParameters.put("page", 615 new Integer (categoryLinkNumber).toString()); 616 617 try { 618 link = TagUtils.getInstance().computeURL(pageContext, null, null, 619 linkPage, null, null, linkParameters, null, true); 620 } catch (MalformedURLException e) { 621 throw new SystemException(e); 622 } 623 624 links.append(" <a HREF='"); 625 links.append(link); 626 links.append("' title='"); 627 links.append(category.getName()); 628 links.append("'>"); 629 links.append(categoryLinkNumber); 630 links.append("</a>"); 631 } 632 } 633 634 itemForm.setPageLinks(links.toString()); 635 } 636 637 650 protected void setMeetingPageNumber(final PageContext pageContext, 651 final String linkPage, 652 final HttpServletRequest request, 653 final ItemForm itemForm) 654 throws SystemException { 655 int pageInt = itemForm.getDisplayPage(); 656 LibraryItemDO item = itemForm.getItem(); 657 658 MessageResources libraryResources = getResources(request, "library"); 659 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 660 661 String agendaLink; 664 HashMap agendaLinkParameters = new HashMap (); 665 StringBuffer links = new StringBuffer (); 666 667 if (pageInt == 0) { 669 links = new StringBuffer (libraryResources.getMessage(locale, 670 "displayItem.label.agenda")); 671 } else { 672 agendaLinkParameters.put("page", "0"); 673 674 try { 675 agendaLink = TagUtils.getInstance().computeURL(pageContext, null, 676 null, linkPage, null, null, agendaLinkParameters, null, 677 true); 678 } catch (MalformedURLException e) { 679 throw new SystemException(e); 680 } 681 682 links = new StringBuffer ("<a HREF='"); 683 links.append(agendaLink); 684 links.append("'>"); 685 links.append(libraryResources.getMessage(locale, 686 "displayItem.label.agenda")); 687 links.append("</a>"); 688 } 689 690 int categoryLinkNumber = 0; 692 693 725 726 itemForm.setPageLinks(links.toString()); 727 } 728 729 743 public final void setPageNumber(final String linkPage, 744 final HttpServletRequest request, 745 final HttpServletResponse response, 746 final ItemForm itemForm) 747 throws SystemException { 748 LibraryItemDO item = itemForm.getItem(); 749 JspFactory factory = JspFactory.getDefaultFactory(); 750 PageContext pageContext = factory.getPageContext(getServlet(), request, 751 response, "", true, 512, true); 752 753 itemForm.setLinkPage(linkPage); 754 755 int lastPage; 758 759 int offset; 762 763 Integer itemType = item.getType(); 765 assert (itemType != null); 766 774 if (itemType.equals(LibraryItemConstants.ITEM_FAQ)) { 775 lastPage = item.getFAQCategories().size(); 776 offset = 0; 777 778 } else { 780 lastPage = item.getPages().size() - 1; 781 offset = 1; 782 } 783 784 int pageInt = -1; 785 786 if (request.getParameter("page") != null) { 787 try { 788 pageInt = new Integer (request.getParameter("page")).intValue() - 789 offset; 790 } catch (NumberFormatException e) { } 792 } else { 793 pageInt = itemForm.getDisplayPage(); 794 } 795 796 if (pageInt > lastPage) { 797 pageInt = lastPage; 798 } 799 800 if (pageInt < 0) { 802 pageInt = 0; 803 } 804 805 itemForm.setDisplayPage(pageInt); 806 807 if (itemType.equals(LibraryItemConstants.ITEM_MEETING)) { 809 setMeetingPageNumber(pageContext, linkPage, request, itemForm); 810 811 } else if (itemType.equals(LibraryItemConstants.ITEM_FAQ)) { 813 setFaqPageNumber(pageContext, linkPage, request, itemForm); 814 815 } else { 817 setDocumentPageNumber(pageContext, linkPage, request, itemForm); 818 } 819 820 HashMap displayDocumentParameters = new HashMap (); 822 StringBuffer previousPageLink = new StringBuffer (); 823 StringBuffer nextPageLink = new StringBuffer (); 824 MessageResources libraryResources = getResources(request, "library"); 825 Locale locale = (Locale ) request.getSession().getAttribute(Globals.LOCALE_KEY); 826 827 if (pageInt > 0) { 829 displayDocumentParameters.put("page", 831 new Integer ((pageInt + offset) - 1).toString()); 832 previousPageLink.append("<a HREF='"); 833 834 try { 835 previousPageLink.append(TagUtils.getInstance().computeURL(pageContext, 836 null, null, linkPage, null, null, 837 displayDocumentParameters, null, true)); 838 } catch (MalformedURLException e) { 839 throw new SystemException(e); 840 } 841 842 previousPageLink.append("'>"); 843 previousPageLink.append(libraryResources.getMessage(locale, 844 "displayDocument.link.previousPage")); 845 previousPageLink.append("</a>"); 846 } 847 848 itemForm.setPreviousPageLink(previousPageLink.toString()); 849 850 if (pageInt < lastPage) { 852 displayDocumentParameters.put("page", 853 new Integer (pageInt + offset + 1).toString()); 854 nextPageLink.append("<a HREF='"); 855 856 try { 857 nextPageLink.append(TagUtils.getInstance().computeURL( 858 pageContext, null, null, linkPage, null, 859 null, displayDocumentParameters, null, true)); 860 } catch (MalformedURLException e) { 861 throw new SystemException(e); 862 } 863 864 nextPageLink.append("'>"); 865 nextPageLink.append(libraryResources.getMessage(locale, 866 "displayDocument.link.nextPage")); 867 nextPageLink.append("</a>"); 868 } 869 870 itemForm.setNextPageLink(nextPageLink.toString()); 871 } 872 } 873 | Popular Tags |