1 41 42 43 package org.jahia.admin.homepages; 44 45 import java.io.IOException ; 46 import java.util.Enumeration ; 47 import java.util.Hashtable ; 48 import java.util.Locale ; 49 import java.util.Vector ; 50 51 import javax.servlet.ServletContext ; 52 import javax.servlet.ServletException ; 53 import javax.servlet.http.HttpServletRequest ; 54 import javax.servlet.http.HttpServletResponse ; 55 import javax.servlet.http.HttpSession ; 56 57 import org.jahia.bin.JahiaAdministration; 58 import org.jahia.data.JahiaData; 59 import org.jahia.engines.selectpage.SelectPage_Engine; 60 import org.jahia.exceptions.JahiaException; 61 import org.jahia.params.ParamBean; 62 import org.jahia.registries.ServicesRegistry; 63 import org.jahia.resourcebundle.JahiaResourceBundle; 64 import org.jahia.services.homepages.HomepageTypes; 65 import org.jahia.services.homepages.JahiaHomepage; 66 import org.jahia.services.homepages.JahiaHomepageCopy; 67 import org.jahia.services.homepages.JahiaHomepageLink; 68 import org.jahia.services.homepages.JahiaHomepageNew; 69 import org.jahia.services.homepages.JahiaHomepagesService; 70 import org.jahia.services.pages.ContentPage; 71 import org.jahia.services.pages.JahiaPage; 72 import org.jahia.services.pages.JahiaPageBaseService; 73 import org.jahia.services.pages.JahiaPageDefinition; 74 import org.jahia.services.sites.JahiaSite; 75 import org.jahia.services.sites.JahiaSiteTools; 76 import org.jahia.services.sites.JahiaSitesService; 77 import org.jahia.services.usermanager.JahiaUser; 78 79 80 89 public class ManageHomepages { 90 91 private static org.apache.log4j.Logger logger = 92 org.apache.log4j.Logger.getLogger (ManageHomepages.class); 93 94 private static final String JSP_PATH = JahiaAdministration.JSP_PATH; 95 private static final String HTTP_FILES = "/jsp/jahia/engines"; 96 private static final String JSP = "/jsp/jahia/administration/homepages/main.jsp?includejsp="; 97 98 private static ServletContext context; 99 100 private ServicesRegistry sReg; 101 private JahiaSitesService siteServ; 102 private JahiaHomepagesService hpServ; 103 104 private JahiaSite site; 105 private JahiaUser user; 106 private Hashtable values = new Hashtable (); 107 private ParamBean jParams = null; 108 109 private String operation = ""; 111 public static final String CHOOSEPAGE_LAUNCHER_LINK_SOURCEPAGE 112 = "org.jahia.admin.ManageHomepages.link_sourcepage"; 113 public static final String CHOOSEPAGE_LAUNCHER_NEW_DESTPAGE 114 = "org.jahia.admin.ManageHomepages.new_destpage"; 115 public static final String CHOOSEPAGE_LAUNCHER_COPY_DESTPAGE 116 = "org.jahia.admin.ManageHomepages.copy_destpage"; 117 public static final String CHOOSEPAGE_LAUNCHER_COPY_SOURCEPAGE 118 = "org.jahia.admin.ManageHomepages.copy_sourcepage"; 119 120 129 public ManageHomepages (HttpServletRequest request, 130 HttpServletResponse response, 131 HttpSession session, 132 ServletContext context) 133 throws Throwable { 134 ManageHomepages.context = context; 135 136 sReg = ServicesRegistry.getInstance (); 137 JahiaData jData = (JahiaData)request.getAttribute ("org.jahia.data.JahiaData"); 138 this.jParams = jData.params (); 139 140 if (sReg == null) { 141 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.serviceRegistyNotAvailable.label", 142 jParams, jParams.getLocale ()); 143 displayError (request, response, dspMsg); 144 return; 145 } 146 147 siteServ = sReg.getJahiaSitesService (); 148 hpServ = sReg.getJahiaHomepagesService (); 149 150 if (siteServ == null || hpServ == null) { 151 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestServiceNotAvailable.label", 152 jParams, jParams.getLocale ()); 153 displayError (request, response, dspMsg); 154 return; 155 } 156 157 userRequestDispatcher (request, response, session); 158 } 159 160 161 169 private void userRequestDispatcher (HttpServletRequest request, 170 HttpServletResponse response, 171 HttpSession session) 172 throws IOException , ServletException { 173 174 user = (JahiaUser)session.getAttribute (ParamBean.SESSION_USER); 176 site = (JahiaSite)session.getAttribute (ParamBean.SESSION_SITE); 177 178 if (site == null || user == null || sReg == null) { 179 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestInfoNotAvailable.label", 180 jParams, jParams.getLocale ()); 181 displayError (request, response, dspMsg); 182 return; 183 } 184 185 try { 186 187 if (JahiaSiteTools.getAdminGroup (site).isMember (user)) { 188 189 operation = request.getParameter ("sub"); 190 191 if (operation.equals ("display")) { 192 displayMain (request, response, session); 193 } else if (operation.equals ("add")) { 194 displayAdd (request, response, session); 195 } else if (operation.equals ("detail")) { 196 displayDetail (request, response, session); 197 } else if (operation.equals ("options")) { 198 displayOptions (request, response, session); 199 } 200 201 } else { 202 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.noAdminAcessSite.label", 204 jParams, jParams.getLocale ()); 205 displayError (request, response, dspMsg); 206 } 207 208 } catch (Throwable t) { 209 t.printStackTrace (); 210 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.processingRequestError.label", 211 jParams, jParams.getLocale ()); 212 displayError (request, response, dspMsg); 213 } 214 } 215 216 227 private void doRedirect (HttpServletRequest request, 228 HttpServletResponse response, 229 String target) 230 throws IOException , ServletException { 231 try { 232 request.setAttribute ("currentSite", site); 233 request.setAttribute ("user", user); 234 235 if (request.getAttribute ("operation") == null) { 237 request.setAttribute ("operation", operation); 238 } 239 240 if (request.getAttribute ("warningMsg") == null) { 242 request.setAttribute ("warningMsg", ""); 243 } 244 245 if (request.getAttribute ("msg") == null) { 247 request.setAttribute ("msg", 248 JahiaResourceBundle.getAdminResource("org.jahia.admin.copyright", 249 jParams, jParams.getLocale())); 250 } 251 252 if (request.getAttribute ("focus") == null) { 253 request.setAttribute ("focus", "-none-"); 254 } 255 256 if (request.getAttribute ("title") == null) { 258 request.setAttribute ("title", "Manage Home pages"); 259 } 260 261 request.setAttribute ("values", values); 263 264 request.setAttribute ("url", request.getContextPath () + HTTP_FILES); 266 267 String userAgent = request.getHeader ("user-agent"); 269 270 Integer navigator = (userAgent.indexOf ("IE")) 271 != -1 ? new Integer (0) : new Integer (1); 272 request.setAttribute ("navigator", navigator); 273 274 boolean isLynx = false; 275 276 if (userAgent.indexOf ("Lynx") != -1) { 277 isLynx = true; 278 } 279 request.setAttribute ("isLynx", new Boolean (isLynx)); 280 281 HttpSession session = request.getSession (); 283 Locale currentLocale = (Locale )session.getAttribute (ParamBean.SESSION_LOCALE); 284 if (currentLocale == null) { 285 currentLocale = jParams.getLocale (); 286 } 287 288 String contentTypeStr = "text/html;charset="; 289 contentTypeStr = contentTypeStr + "ISO8859-1"; 290 request.setAttribute ("content-type", contentTypeStr); 291 292 context.getRequestDispatcher (target).forward (request, response); 294 295 } catch (IOException ie) { 296 logger.error ("IOException while redirecting to " + target, ie); 297 298 } catch (ServletException se) { 299 logger.error("Servlet exception while redirecting to " + target, se); 300 Throwable t = se.getRootCause(); 301 while (t != null) { 302 logger.error("Root cause", t); 303 if (t instanceof ServletException ) { 304 t = ((ServletException )t).getRootCause(); 305 } else { 306 t = null; 307 } 308 } 309 } 310 } 311 312 320 private void displayMain (HttpServletRequest request, 321 HttpServletResponse response, 322 HttpSession session) 323 throws IOException , ServletException , JahiaException { 324 session.setAttribute ("homepageBean", null); 326 327 Enumeration enumeration = hpServ.getHomepages (site); 328 329 request.setAttribute ("homepages", enumeration); 330 331 request.setAttribute ("subAction", "list"); 333 request.setAttribute ("go", "change"); 335 336 doRedirect (request, response, JSP + "list"); 337 } 338 339 347 private void displayError (HttpServletRequest request, 348 HttpServletResponse response, 349 String msg) 350 throws IOException , ServletException { 351 request.setAttribute ("warningMsg", msg); 352 doRedirect (request, response, JSP + "error"); 353 } 354 355 356 360 361 369 private void displayAdd (HttpServletRequest request, 370 HttpServletResponse response, 371 HttpSession session) 372 throws IOException , ServletException , JahiaException { 373 logger.info("Started"); 374 375 JahiaHomepage hp = null; 376 377 String go = request.getParameter ("go"); 378 if (go == null) { 379 go = ""; 380 session.setAttribute ("homepageBean", null); 382 } 383 384 request.setAttribute ("subAction", "add"); 386 if (go.equals ("")) 388 go = "change"; 389 request.setAttribute ("go", go); 390 391 hp = (JahiaHomepage)session.getAttribute ("homepageBean"); 392 if (hp == null) { 393 hp = hpServ.createHomepage ("", 394 "", 395 site.getSiteKey (), 396 HomepageTypes.HOMEPAGE_LINK, 397 new Hashtable (), 398 0); 399 session.setAttribute ("homepageBean", hp); 400 401 } else { 402 403 String name = ""; 405 int type = HomepageTypes.HOMEPAGE_LINK; 406 String descr = ""; 407 408 409 String value = request.getParameter ("name"); 411 if (value != null) 412 name = value; 413 414 value = request.getParameter ("type"); 415 if (value != null) 416 type = Integer.parseInt (value); 417 418 value = request.getParameter ("descr"); 419 if (value != null) 420 descr = value; 421 422 if (hp.getType () != type) { 423 hp = hpServ.createHomepage (name, 425 descr, 426 site.getSiteKey (), 427 type, 428 new Hashtable (), 429 0); 430 session.setAttribute ("homepageBean", hp); 431 432 } 433 434 hp.setName (name); 436 hp.setDescr (descr); 437 438 if (go.equals ("save")) { 439 440 boolean error = false; 441 442 if (name == null || name.trim ().equals ("")) { 443 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.nameRequired.label", 444 jParams, jParams.getLocale ()); 445 request.setAttribute ("warningMsg", dspMsg); 446 error = true; 447 } 448 449 if (!error) { 450 if (hp.getType () == HomepageTypes.HOMEPAGE_LINK) { 452 error = !saveLink (request, response, session); 453 } else if (hp.getType () == HomepageTypes.HOMEPAGE_COPY) { 454 error = !saveCopy (request, response, session); 455 } else if (hp.getType () == HomepageTypes.HOMEPAGE_NEW) { 456 error = !saveNew (request, response, session); 457 } 458 } 459 460 if (!error) { 461 session.setAttribute ("homepageBean", null); 463 displayMain (request, response, session); 464 return; 465 } 466 } 467 } 468 469 if (hp.getType () == HomepageTypes.HOMEPAGE_LINK) { 470 prepareAddLink (request, response, session); 471 } else if (hp.getType () == HomepageTypes.HOMEPAGE_COPY) { 472 prepareAddCopy (request, response, session); 473 } else if (hp.getType () == HomepageTypes.HOMEPAGE_NEW) { 474 prepareAddNew (request, response, session); 475 } 476 doRedirect (request, response, JSP + "add"); 478 479 } 480 481 489 private void prepareAddLink (HttpServletRequest request, 490 HttpServletResponse response, 491 HttpSession session) 492 throws IOException , ServletException , JahiaException { 493 494 prepareAdd (request, response, session); 495 496 JahiaHomepageLink hp = (JahiaHomepageLink)session.getAttribute ("homepageBean"); 497 if (hp == null) { 498 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestedHomepageNotFound.label", 499 jParams, jParams.getLocale ()); 500 displayError (request, response, dspMsg); 501 return; 502 } 503 504 506 String value = request.getParameter ("pageid"); 507 int pageID = -1; 508 if (value != null) { 509 pageID = Integer.parseInt (value); 510 hp.setPageID (pageID); 511 } else { 512 pageID = SelectPage_Engine.getInstance ().getSelectedPageID (session); 513 if (pageID != -1) { 514 hp.setPageID (pageID); 515 } 516 } 517 session.setAttribute (ParamBean.SESSION_JAHIA_ENGINEMAP, null); 519 request.setAttribute ("linkInitialSourcePage", new Integer (hp.getPageID ())); 521 522 if (operation.equals ("add")) { 523 request.setAttribute ("includeSpecificSection", "addlink"); 524 } else if (operation.equals ("detail")) 525 request.setAttribute ("includeSpecificSection", "detaillink"); 526 } 527 528 536 private void prepareAddCopy (HttpServletRequest request, 537 HttpServletResponse response, 538 HttpSession session) 539 throws IOException , ServletException , JahiaException { 540 541 prepareAdd (request, response, session); 542 543 JahiaHomepageCopy hp = (JahiaHomepageCopy)session.getAttribute ("homepageBean"); 544 if (hp == null) { 545 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestedHomepageNotFound.label", 546 jParams, jParams.getLocale ()); 547 displayError (request, response, dspMsg); 548 return; 549 } 550 551 553 String value = request.getParameter ("pageid"); 554 int pageID = -1; 555 int destPageID = -1; 556 int depth = 1; 557 int depthType = 2; 558 559 if (value != null) { 560 pageID = Integer.parseInt (value); 561 hp.setPageID (pageID); 562 } 563 564 value = request.getParameter ("destpageid"); 565 if (value != null) { 566 destPageID = Integer.parseInt (value); 567 hp.setParentPageID (destPageID); 568 } 569 570 value = request.getParameter ("depth"); 571 if (value != null) { 572 try { 573 depth = Integer.parseInt (value); 574 } catch (Throwable t) { 575 } 576 if (depth >= 0) 577 hp.setCopyDepth (depth); 578 579 } 580 581 value = request.getParameter ("depthtype"); 582 if (value != null) { 583 depthType = Integer.parseInt (value); 584 } 585 586 587 request.setAttribute ("depthType", new Integer (depthType)); 588 if (operation.equals ("add")) { 589 request.setAttribute ("includeSpecificSection", "addcopy"); 590 } else if (operation.equals ("detail")) 591 request.setAttribute ("includeSpecificSection", "detailcopy"); 592 593 } 594 595 603 private void prepareAddNew (HttpServletRequest request, 604 HttpServletResponse response, 605 HttpSession session) 606 throws IOException , ServletException , JahiaException { 607 608 prepareAdd (request, response, session); 609 610 JahiaHomepageNew hp = (JahiaHomepageNew)session.getAttribute ("homepageBean"); 611 if (hp == null) { 612 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestedHomepageNotFound.label", 613 jParams, jParams.getLocale ()); 614 displayError (request, response, dspMsg); 615 return; 616 } 617 618 Enumeration templates = ServicesRegistry.getInstance () 620 .getJahiaPageTemplateService ().getPageTemplates (site.getID (), true); 621 622 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance (); 623 624 626 String value = request.getParameter ("destpageid"); 627 int pageID = -1; 628 if (value != null) { 629 pageID = Integer.parseInt (value); 630 hp.setParentPageID (pageID); 631 } 632 633 value = request.getParameter ("template"); 634 int templateID = -1; 635 if (value != null) { 636 templateID = Integer.parseInt (value); 637 hp.setTemplateID (templateID); 638 } 639 640 request.setAttribute ("templates", templates); 641 if (operation.equals ("add")) { 642 request.setAttribute ("includeSpecificSection", "addnew"); 643 } else if (operation.equals ("detail")) 644 request.setAttribute ("includeSpecificSection", "detailnew"); 645 646 647 } 648 649 657 private void prepareAdd (HttpServletRequest request, 658 HttpServletResponse response, 659 HttpSession session) 660 throws IOException , ServletException , JahiaException { 661 662 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance (); 664 Vector allPagesIDVector = pageService.getPageIDsInSite (site.getID (), 665 org.jahia.services.pages.PageInfoInterface.TYPE_DIRECT); 666 667 Vector pages = new Vector (); 669 Enumeration allPagesIDEnumeration = allPagesIDVector.elements (); 670 while (allPagesIDEnumeration.hasMoreElements ()) { 671 Integer pageID = (Integer )allPagesIDEnumeration.nextElement (); 672 ContentPage contentPage = pageService 673 .lookupContentPage (pageID.intValue (), jParams.getEntryLoadRequest (), false); 674 pages.add (contentPage); 675 } 676 677 request.setAttribute ("pages", pages); 679 680 } 681 682 690 private boolean saveLink (HttpServletRequest request, 691 HttpServletResponse response, 692 HttpSession session) 693 throws IOException , ServletException , JahiaException { 694 695 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance (); 696 697 ContentPage selectedPage = null; 699 700 String value = request.getParameter ("pageid"); 701 int pageID = -1; 702 if (value != null) { 703 pageID = Integer.parseInt (value); 704 705 try { 706 if (pageID != -1) 707 selectedPage = pageService 708 .lookupContentPage (pageID, jParams.getEntryLoadRequest (), false); 709 } catch (Throwable t) { 710 } 711 } 712 713 if (selectedPage == null) { 714 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.pageNotAvailable.label", 715 jParams, jParams.getLocale ()); 716 request.setAttribute ("warningMsg", dspMsg); 717 return false; 718 } 719 720 JahiaHomepageLink hp = (JahiaHomepageLink)session.getAttribute ("homepageBean"); 721 if (hp == null) { 722 throw new JahiaException (this.getClass().getName() + ".saveLink", 723 "Homepage bean not found in session", 724 JahiaException.ERROR_SEVERITY, 725 JahiaException.ERROR_SEVERITY); 726 } 727 728 hp.setPageID (pageID); 729 hpServ.saveHomepage (hp, site.getAclID ()); 730 731 return true; 732 } 733 734 742 private boolean saveCopy (HttpServletRequest request, 743 HttpServletResponse response, 744 HttpSession session) 745 throws IOException , ServletException , JahiaException { 746 747 prepareAdd (request, response, session); 748 749 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance (); 750 751 ContentPage selectedContentPage = null; 753 ContentPage destContentPage = null; 754 755 String value = request.getParameter ("pageid"); 756 int pageID = -1; 757 int depth = 1; 758 int depthType = 2; 759 760 if (value != null) { 761 pageID = Integer.parseInt (value); 762 763 try { 764 if (pageID != -1) 765 selectedContentPage = pageService 766 .lookupContentPage (pageID, jParams.getEntryLoadRequest (), false); 767 } catch (Throwable t) { 768 } 769 } 770 771 if (selectedContentPage == null) { 772 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.sourcePageNotAvailable.label", 773 jParams, jParams.getLocale ()); 774 request.setAttribute ("warningMsg", dspMsg); 775 return false; 776 } 777 778 value = request.getParameter ("destpageid"); 779 if (value != null) { 780 pageID = Integer.parseInt (value); 781 782 try { 783 if (pageID != -1) 784 destContentPage = pageService 785 .lookupContentPage (pageID, jParams.getEntryLoadRequest (), false); 786 } catch (Throwable t) { 787 t.printStackTrace (); 788 } 789 } 790 791 if (destContentPage == null) { 792 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.destinationPageNotAvailable.label", 793 jParams, jParams.getLocale ()); 794 request.setAttribute ("warningMsg", dspMsg); 795 return false; 796 } 797 798 if (destContentPage.getID () == selectedContentPage.getID ()) { 799 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.destinationSameAsSourcePage.label", 800 jParams, jParams.getLocale ()); 801 request.setAttribute ("warningMsg", dspMsg); 802 return false; 803 } 804 805 value = request.getParameter ("depthtype"); 806 if (value != null) { 807 depthType = Integer.parseInt (value); 808 } 809 810 if (depthType == 2) { 811 depth = 0; 812 } else { 813 value = request.getParameter ("depth"); 814 if (value != null) { 815 depth = Integer.parseInt (value); 816 } 817 } 818 if (depth < 0) { 819 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.invalidDepth.label", 820 jParams, jParams.getLocale ()); 821 request.setAttribute ("warningMsg", dspMsg); 822 return false; 823 } 824 825 JahiaHomepageCopy hp = (JahiaHomepageCopy)session.getAttribute ("homepageBean"); 826 if (hp == null) { 827 throw new JahiaException (this.getClass().getName() + ".saveCopy", 828 "Homepage bean not found in session", 829 JahiaException.ERROR_SEVERITY, 830 JahiaException.ERROR_SEVERITY); 831 } 832 833 hp.setPageID (selectedContentPage.getID ()); 834 hp.setParentPageID (destContentPage.getID ()); 835 hp.setCopyDepth (depth); 836 838 if (true) { String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.pageDefinitionNotImplemented.label", 841 jParams, jParams.getLocale ()); 842 request.setAttribute ("warningMsg", dspMsg); 843 return false; 844 } 845 846 return true; 847 } 848 849 857 private boolean saveNew (HttpServletRequest request, 858 HttpServletResponse response, 859 HttpSession session) 860 throws IOException , ServletException , JahiaException { 861 862 JahiaPageBaseService pageService = JahiaPageBaseService.getInstance (); 863 864 JahiaPage selectedPage = null; 866 867 String value = request.getParameter ("destpageid"); 868 int pageID = -1; 869 if (value != null) { 870 pageID = Integer.parseInt (value); 871 872 try { 873 if (pageID != -1) 874 selectedPage = pageService 875 .lookupPageWhitoutTemplates (pageID); 876 } catch (Throwable t) { 877 t.printStackTrace (); 878 } 879 } 880 881 if (selectedPage == null) { 882 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.pageNotAvailable.label", 883 jParams, jParams.getLocale ()); 884 request.setAttribute ("warningMsg", dspMsg); 885 return false; 886 } 887 888 value = request.getParameter ("template"); 889 int templateID = -1; 890 if (value != null) { 891 templateID = Integer.parseInt (value); 892 } 893 894 JahiaPageDefinition pageDef = null; 895 try { 896 pageDef = ServicesRegistry.getInstance () 897 .getJahiaPageTemplateService ().lookupPageTemplate (templateID); 898 } catch (Throwable t) { 899 t.printStackTrace (); 900 } 901 902 if (pageDef == null) { 903 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.choiseAnotherTemplate.label", 904 jParams, jParams.getLocale ()); 905 request.setAttribute ("warningMsg", dspMsg); 906 return false; 907 } 908 909 JahiaHomepageNew hp = (JahiaHomepageNew)session.getAttribute ("homepageBean"); 910 if (hp == null) { 911 throw new JahiaException (this.getClass().getName() + ".saveCopy", 912 "Homepage bean not found in session", 913 JahiaException.ERROR_SEVERITY, 914 JahiaException.ERROR_SEVERITY); 915 } 916 917 hp.setParentPageID (pageID); 918 hp.setTemplateID (templateID); 919 921 if (true) { String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.pageDefinitionNotImplemented.label", 924 jParams, jParams.getLocale ()); 925 request.setAttribute ("warningMsg", dspMsg); 926 return false; 927 } 928 929 return true; 930 931 } 932 933 934 942 private void displayDetail (HttpServletRequest request, 943 HttpServletResponse response, 944 HttpSession session) 945 throws IOException , ServletException , JahiaException 946 { 947 logger.info ("Started"); 948 949 JahiaHomepage hp = null; 950 951 String value = request.getParameter ("hpid"); 952 if (value != null) { 953 954 JahiaHomepage oriHp = hpServ.getHomepage (Integer.parseInt (value)); 955 if (oriHp == null) { 956 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestHomepageCannotFound.label", 957 jParams, jParams.getLocale ()); 958 displayError (request, response, dspMsg + " [" + value + "]"); 959 return; 960 } 961 hp = (JahiaHomepage)oriHp.clone (); 962 session.setAttribute ("homepageBean", hp); 963 } 964 965 hp = (JahiaHomepage)session.getAttribute ("homepageBean"); 966 if (hp == null) { 967 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.requestHomepageCannotFound.label", 968 jParams, jParams.getLocale ()); 969 displayError (request, response, dspMsg + " [" + value + "]"); 970 return; 971 } 972 973 String go = request.getParameter ("go"); 974 if (go == null) 975 go = ""; 976 977 request.setAttribute ("subAction", "detail"); 979 if (go.equals ("")) 981 go = "change"; 982 request.setAttribute ("go", go); 983 984 985 if (go.equals ("delete")) { 986 String confirm = request.getParameter ("confirmdelete"); 987 if (confirm == null) { 988 request.setAttribute ("includeSpecificSection", "delete"); 989 doRedirect (request, response, JSP + "delete"); 990 return; 991 } 992 993 if (processDelete (hp)) { 994 displayMain (request, response, session); 995 return; 996 } else { 997 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.deletingHomepageError.label", 998 jParams, jParams.getLocale ()); 999 displayError (request, response, dspMsg); 1000 } 1001 } 1002 1003 if (go.equals ("save") || go.equals ("change")) { 1004 1005 value = request.getParameter ("name"); 1007 if (value != null) 1008 hp.setName (value); 1009 1010 value = request.getParameter ("descr"); 1011 if (value != null) 1012 hp.setDescr (value); 1013 } 1014 1015 if (go.equals ("save")) { 1016 1017 boolean error = false; 1018 1019 if (hp.getName () == null || hp.getName ().trim ().equals ("")) { 1020 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.nameRequired.label", 1021 jParams, jParams.getLocale ()); 1022 request.setAttribute ("warningMsg", dspMsg); 1023 error = true; 1024 } 1025 1026 if (!error) { 1027 if (hp.getType () == HomepageTypes.HOMEPAGE_LINK) { 1029 error = !saveLink (request, response, session); 1030 } else if (hp.getType () == HomepageTypes.HOMEPAGE_COPY) { 1031 error = !saveCopy (request, response, session); 1032 } else if (hp.getType () == HomepageTypes.HOMEPAGE_NEW) { 1033 error = !saveNew (request, response, session); 1034 } 1035 } 1036 1037 if (!error) { 1038 session.setAttribute ("homepageBean", null); 1040 displayMain (request, response, session); 1041 return; 1042 } 1043 } 1044 if (hp.getType () == HomepageTypes.HOMEPAGE_LINK) { 1045 prepareAddLink (request, response, session); 1046 } else if (hp.getType () == HomepageTypes.HOMEPAGE_COPY) { 1047 prepareAddCopy (request, response, session); 1048 } else if (hp.getType () == HomepageTypes.HOMEPAGE_NEW) { 1049 prepareAddNew (request, response, session); 1050 } 1051 doRedirect (request, response, JSP + "detail"); 1053 1054 } 1055 1056 1064 private void displayOptions (HttpServletRequest request, 1065 HttpServletResponse response, 1066 HttpSession session) 1067 throws IOException , ServletException , JahiaException { 1068 1069 logger.info ("Started"); 1070 1071 JahiaHomepage hp = null; 1072 1073 String value = null; 1074 int userDefaultHomepageID = site.getUserDefaultHomepageDef (); 1075 int groupDefaultHomepageID = site.getGroupDefaultHomepageDef (); 1076 1077 String go = request.getParameter ("go"); 1078 if (go == null) 1079 go = ""; 1080 1081 request.setAttribute ("subAction", "options"); 1083 if (go.equals ("")) 1085 go = "change"; 1086 request.setAttribute ("go", go); 1087 1088 if (go.equals ("save") || go.equals ("change")) { 1089 1090 value = request.getParameter ("userdefaulthomepage"); 1092 if (value != null) 1093 userDefaultHomepageID = Integer.parseInt (value); 1094 1095 value = request.getParameter ("groupdefaulthomepage"); 1096 if (value != null) 1097 groupDefaultHomepageID = Integer.parseInt (value); 1098 1099 } 1100 1101 if (go.equals ("save")) { 1102 1103 site.setUserDefaultHomepageDef (userDefaultHomepageID); 1104 site.setGroupDefaultHomepageDef (groupDefaultHomepageID); 1105 1106 String dspMsg = JahiaResourceBundle.getAdminResource ("org.jahia.admin.warningMsg.changSaved.label", 1107 jParams, jParams.getLocale ()); 1108 request.setAttribute ("warningMsg", dspMsg); 1109 } 1113 1114 Enumeration enumeration = hpServ.getHomepages (site); 1115 request.setAttribute ("homepages1", enumeration); 1116 enumeration = hpServ.getHomepages (site); 1117 request.setAttribute ("homepages2", enumeration); 1118 1119 hp = hpServ.getHomepage (userDefaultHomepageID); 1120 if (hp == null) 1121 hp = hpServ.createHomepage ("", "", "", HomepageTypes.HOMEPAGE_LINK, null, -1); 1122 1123 request.setAttribute ("userDefaultHomepage", hp); 1124 1125 hp = hpServ.getHomepage (groupDefaultHomepageID); 1126 if (hp == null) 1127 hp = hpServ.createHomepage ("", "", "", HomepageTypes.HOMEPAGE_LINK, null, -1); 1128 1129 request.setAttribute ("groupDefaultHomepage", hp); 1130 1131 doRedirect (request, response, JSP + "options"); 1133 1134 1135 } 1136 1137 1142 private boolean processDelete (JahiaHomepage hp) 1143 throws JahiaException 1144 { 1145 if (hp == null) 1146 return false; 1147 1148 hpServ.deleteHomepage (hp.getID ()); 1149 return true; 1150 } 1151 1152} 1153 | Popular Tags |