1 13 23 package org.jahia.gui; 24 25 import java.util.HashMap ; 26 27 import org.jahia.content.ContentObject; 28 import org.jahia.data.containers.JahiaContainer; 29 import org.jahia.data.containers.JahiaContainerList; 30 import org.jahia.data.fields.JahiaField; 31 import org.jahia.engines.selectpage.SelectPage_Engine; 32 import org.jahia.exceptions.JahiaException; 33 import org.jahia.params.ParamBean; 34 import org.jahia.registries.ServicesRegistry; 35 import org.jahia.services.containers.ContentContainer; 36 import org.jahia.services.containers.ContentContainerList; 37 import org.jahia.services.fields.ContentField; 38 import org.jahia.services.lock.LockKey; 39 import org.jahia.services.lock.LockService; 40 import org.jahia.services.pages.ContentPage; 41 import org.jahia.services.pages.JahiaPage; 42 import org.jahia.services.pages.JahiaPageDefinition; 43 import javax.servlet.jsp.JspWriter ; 44 import java.io.IOException ; 45 import org.jahia.data.beans.ContainerListBean; 46 import org.jahia.data.beans.ContainerBean; 47 import org.jahia.data.beans.FieldBean; 48 import org.jahia.data.beans.PageBean; 49 import java.util.Map ; 50 import java.util.ResourceBundle ; 51 import java.util.Locale ; 52 import java.util.MissingResourceException ; 53 import java.util.Iterator ; 54 import org.jahia.data.beans.ActionURIBean; 55 import org.jahia.resourcebundle.JahiaResourceBundle; 56 import org.jahia.bin.Jahia; 57 58 public class HTMLToolBox { 59 60 private static final org.apache.log4j.Logger logger = 61 org.apache.log4j.Logger.getLogger(HTMLToolBox.class); 62 63 private static final int JS_WINDOW_WIDTH = 640; 64 private static final int JS_WINDOW_HEIGHT = 600; 65 66 private ParamBean jParams; 67 private GuiBean gui; 68 69 70 71 76 public HTMLToolBox( GuiBean guiBean, ParamBean params ) { 77 this.gui = guiBean; 78 this.jParams = params; 79 } 81 private static String previousSessionID = ""; 82 private static String previousCleanSessionID = ""; 83 95 public static String cleanSessionID(String sessionID) { 96 if (sessionID.equals(previousSessionID)) { 97 return previousCleanSessionID; 98 } 99 StringBuffer result = new StringBuffer (); 100 for (int i=0; i < sessionID.length(); i++) { 101 char curChar = sessionID.charAt(i); 102 if (Character.isLetterOrDigit(curChar)) { 103 result.append(curChar); 104 } 105 } 106 previousSessionID = sessionID; 107 previousCleanSessionID = result.toString(); 108 return result.toString(); 109 } 110 111 117 public String drawLoginLauncher() 118 throws JahiaException { 119 if (Jahia.usesSso()) { 121 return "window.location = '" + Jahia.getSsoValve().getRedirectUrl(jParams) + "'"; 122 } 123 String popupLoginURL = gui.drawPopupLoginUrl(); 125 return (popupLoginURL.equals("")) ? "" : 126 "OpenJahiaWindow('" + popupLoginURL + "','Login',260,300)"; 127 } 128 129 135 public String drawLoginLauncher( int destinationPageID) 136 throws JahiaException { 137 if (Jahia.usesSso()) { 139 return "window.location = '" + Jahia.getSsoValve().getRedirectUrl(jParams) + "'"; 140 } 141 String popupLoginURL = gui.drawPopupLoginUrl(destinationPageID); 143 return (popupLoginURL.equals("")) ? "" : 144 "OpenJahiaWindow('" + popupLoginURL + "','Login',260,300)"; 145 } 146 147 public String drawLoginButton() 148 throws JahiaException { 149 return drawButton( drawLoginLauncher(), "login" ); 150 } 151 152 public String drawLoginButton( int destinationPageID ) 153 throws JahiaException { 154 return drawButton( drawLoginLauncher( destinationPageID ), "login" ); 155 } 156 157 163 public String drawLogoutLauncher() 164 throws JahiaException { 165 return gui.drawLogoutUrl(); 166 } 167 168 174 public String drawLogoutLauncher( int destinationPageID ) 175 throws JahiaException { 176 return gui.drawLogoutUrl(); 177 } 178 179 public String drawLogoutButton() 180 throws JahiaException { 181 return drawLinkButton( gui.drawLogoutUrl(), "logout" ); 182 } 183 184 public String drawLogoutButton( int destinationPageID ) 185 throws JahiaException { 186 return drawLinkButton( gui.drawLogoutUrl(), "logout" ); 187 } 188 189 196 public String drawUpdateFieldLauncher(ContentField contentField) 197 throws JahiaException { 198 return drawUpdateFieldLauncher(contentField, false); 199 } 200 201 208 public String drawUpdateFieldLauncher( JahiaField theField ) 209 throws JahiaException { 210 if ( theField == null ){ 211 return ""; 212 } 213 ContentField contentField = theField.getContentField(); 214 return drawUpdateFieldLauncher(contentField, false); 215 } 216 217 224 public String drawUpdateFieldButton( JahiaField theField ) 225 throws JahiaException { 226 return drawButton( drawUpdateFieldLauncher(theField), "update" ); 227 } 228 229 private String drawUpdateFieldLauncher(ContentField contentField, boolean checkLock) 230 throws JahiaException { 231 StringBuffer name = new StringBuffer ("updateField_"); 232 if ( contentField != null ){ 233 name.append(contentField.getID()); 234 } 235 name.append(cleanSessionID(jParams.getSessionID())); 236 return drawLauncher( gui.drawUpdateFieldUrl(contentField) , name.toString() ); 237 } 238 239 245 public String drawAddContainerLauncher(JahiaContainerList jahiaContainerList) { 246 return drawAddContainerLauncher(jahiaContainerList, JS_WINDOW_WIDTH, JS_WINDOW_HEIGHT, false); 247 } 248 249 255 public String drawAddContainerLauncher(JahiaContainerList jahiaContainerList, int width, int height) { 256 return drawAddContainerLauncher(jahiaContainerList, width, height, false); 257 } 258 259 267 private String drawAddContainerLauncher(JahiaContainerList jahiaContainerList, int width, int height, boolean checkLock) { 268 String launcher = ""; 269 try { 270 StringBuffer name = new StringBuffer ("addContainer_"); 271 name.append(jahiaContainerList.getID()); 272 name.append(cleanSessionID(jParams.getSessionID())); 273 String addContainerURL = gui.drawAddContainerUrl(jahiaContainerList); 274 launcher = addContainerURL.equals("") ? "" : 275 "OpenJahiaScrollableWindow('" + addContainerURL + "','" + name.toString() + "'," + width + "," + height + ")"; 276 if (checkLock) { 278 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 279 LockKey lockKey = LockKey.composeLockKey(LockKey.ADD_CONTAINER_TYPE, jahiaContainerList.getID(), jahiaContainerList.getPageID()); 280 if (!lockRegistry.canRelease(lockKey, jParams.getUser(), jParams.getSessionID())) { 281 launcher = ""; 282 } 283 } 284 } catch (JahiaException je) { 286 logger.error("Cannot draw add container launcher", je); 287 launcher = ""; 288 } 289 return launcher; 290 } 291 292 299 public String drawUpdateContainerLauncher(ContentContainer contentContainer) 300 throws JahiaException { 301 return drawUpdateContainerLauncher(contentContainer, JS_WINDOW_WIDTH, JS_WINDOW_HEIGHT, false); 302 } 303 304 312 public String drawUpdateContainerLauncher(ContentContainer contentContainer, int width, int height) 313 throws JahiaException { 314 return drawUpdateContainerLauncher(contentContainer, width, height, false); 315 } 316 317 324 public String drawUpdateContainerLauncher( JahiaContainer theContainer ) 325 throws JahiaException { 326 if (theContainer != null) { 327 ContentContainer contentContainer = theContainer. 328 getContentContainer(); 329 return drawUpdateContainerLauncher(contentContainer, 330 JS_WINDOW_WIDTH, 331 JS_WINDOW_HEIGHT, false); 332 } else { 333 return ""; 334 } 335 } 336 337 346 public String drawUpdateContainerLauncher( JahiaContainer theContainer, int width, int height ) 347 throws JahiaException { 348 ContentContainer contentContainer = theContainer.getContentContainer(); 349 return drawUpdateContainerLauncher(contentContainer, width, height, false); 350 } 351 352 359 public String drawUpdateContainerButton( JahiaContainer theContainer ) 360 throws JahiaException { 361 return drawButton( drawUpdateContainerLauncher(theContainer), "update" ); 362 } 363 364 private String drawUpdateContainerLauncher(ContentContainer contentContainer, int width, int height, boolean checkLock) 365 throws JahiaException { 366 StringBuffer name = new StringBuffer ("updateContainer_"); 367 if ( contentContainer != null ) { 368 name.append(contentContainer.getID()); 369 } 370 name.append(cleanSessionID(jParams.getSessionID())); 371 String updateContainerURL = gui.drawUpdateContainerUrl(contentContainer); 372 String out = updateContainerURL.equals("") ? "" : 373 "OpenJahiaScrollableWindow('" + updateContainerURL + "','" + name.toString() + "'," + width + "," + height + ")"; 374 if (checkLock) { 376 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 377 LockKey lockKey = LockKey.composeLockKey(LockKey.UPDATE_CONTAINER_TYPE, contentContainer.getID(), contentContainer.getPageID()); 378 if (!lockRegistry.canRelease(lockKey, jParams.getUser(), jParams.getSessionID())) { 379 out = ""; 380 } 381 } 382 return out; 384 } 385 386 393 public String drawDeleteContainerLauncher(ContentContainer contentContainer) 394 throws JahiaException { 395 return drawDeleteContainerLauncher(contentContainer, false); 396 } 397 398 405 public String drawDeleteContainerLauncher( JahiaContainer theContainer ) 406 throws JahiaException { 407 if ( theContainer == null ){ 408 return ""; 409 } 410 ContentContainer contentContainer = theContainer.getContentContainer(); 411 return drawDeleteContainerLauncher(contentContainer, false); 412 } 413 414 421 public String drawDeleteContainerButton( JahiaContainer theContainer ) 422 throws JahiaException { 423 return drawButton( drawDeleteContainerLauncher(theContainer), "delete" ); 424 } 425 426 private String drawDeleteContainerLauncher(ContentContainer contentContainer, boolean checkLock) 427 throws JahiaException { 428 StringBuffer name = new StringBuffer ("deleteContainer_"); 429 if (contentContainer != null) { 430 name.append(contentContainer.getID()); 431 } 432 name.append(cleanSessionID(jParams.getSessionID())); 433 String deleteContainerURL = gui.drawDeleteContainerUrl(contentContainer); 434 String out = deleteContainerURL.equals("") ? "" : 435 "OpenJahiaScrollableWindow('" + deleteContainerURL + "','" + name.toString() + "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT +")"; 436 if (checkLock) { 438 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 439 LockKey lockKey = LockKey.composeLockKey(LockKey.DELETE_CONTAINER_TYPE, contentContainer.getID(), contentContainer.getPageID()); 440 if (!lockRegistry.canRelease(lockKey, jParams.getUser(), jParams.getSessionID())) { 441 out = ""; 442 } 443 } 444 return out; 446 } 447 448 454 public String drawContainerListPropertiesLauncher(ContentContainerList contentContainerList) 455 throws JahiaException { 456 return drawContainerListPropertiesLauncher(contentContainerList, false); 457 } 458 459 465 public synchronized String drawContainerListPropertiesLauncher( JahiaContainerList theContainerList ) 466 throws JahiaException { 467 if (theContainerList.getID() == 0) { 468 469 521 return ""; 522 } 523 ContentContainerList contentContainerList = ContentContainerList.getContainerList(theContainerList.getID()); 524 return drawContainerListPropertiesLauncher(contentContainerList, false); 525 } 526 527 533 public String drawContainerListPropertiesButton( JahiaContainerList theContainerList ) 534 throws JahiaException { 535 return drawButton( drawContainerListPropertiesLauncher( theContainerList ), "list properties" ); 536 } 537 538 private String drawContainerListPropertiesLauncher(ContentContainerList contentContainerList, boolean checkLock) 539 throws JahiaException { 540 StringBuffer name = new StringBuffer ("containerListProperties_"); 541 if ( contentContainerList != null ){ 542 name.append(contentContainerList.getID()); 543 } 544 name.append(cleanSessionID(jParams.getSessionID())); 545 String containerListPropertiesURL = gui.drawContainerListPropertiesUrl(contentContainerList); 546 String out = ""; 547 if (!"".equals(containerListPropertiesURL)) { 548 out = "OpenJahiaWindow('" + containerListPropertiesURL + "', '" + name.toString() + "', " + JS_WINDOW_WIDTH + ", " + JS_WINDOW_HEIGHT + ")"; 549 } 550 556 557 if (checkLock) { 559 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 560 LockKey lockKey = LockKey.composeLockKey(LockKey.UPDATE_CONTAINERLIST_TYPE, contentContainerList.getID(), contentContainerList.getPageID()); 561 if (!lockRegistry.canRelease(lockKey, jParams.getUser(), jParams.getSessionID())) { 562 out = ""; 563 } 564 } 565 return out; 567 } 568 569 public String drawWorkflowLauncher() 570 throws JahiaException { 571 572 StringBuffer name = new StringBuffer ("workflow_"); 573 if ( jParams.getPage() != null ){ 574 name.append(jParams.getPage().getID()); 575 } 576 name.append(cleanSessionID(jParams.getSessionID())); 577 String workflowURL = gui.drawWorkflowUrl(); 578 return ("".equals(workflowURL)) ? "" : "OpenJahiaScrollableWindow('" + workflowURL + "','" + name.toString() + "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT +")"; 579 } 580 581 584 public String drawWorkflowLauncher(int basePage) throws JahiaException { 585 StringBuffer name = new StringBuffer ("workflow_"); 586 587 name.append(basePage); 588 name.append(cleanSessionID(jParams.getSessionID())); 589 590 String workflowURL = gui.drawWorkflowUrl(); 591 return ("".equals(workflowURL)) ? "" : "OpenJahiaScrollableWindow('" + workflowURL + "','" + name.toString() 592 + "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT + ")"; 593 } 594 595 603 public String drawWorkflowLauncher(int basePage, String engineUrlParams) 604 throws JahiaException 605 { 606 String workflowURL = gui.drawWorkflowUrl(); 607 608 return workflowURL.length() == 0 ? "" : new StringBuffer (64).append( 609 "OpenJahiaScrollableWindow('").append(workflowURL) 610 .append(engineUrlParams).append("','").append("workflow_").append( 611 basePage).append(cleanSessionID(jParams.getSessionID())).append( 612 "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT + ")").toString(); 613 } 614 615 621 public String drawPagePropertiesLauncher() 622 throws JahiaException { 623 return drawPagePropertiesLauncher(false); 624 } 625 626 private String drawPagePropertiesLauncher(boolean checkLock) 627 throws JahiaException { 628 StringBuffer name = new StringBuffer ("pageProperties_"); 629 if ( jParams.getPage() != null ){ 630 name.append(jParams.getPage().getID()); 631 } 632 name.append(cleanSessionID(jParams.getSessionID())); 633 String out = gui.drawPagePropertiesUrl().equals("") ? "" : 634 "OpenJahiaScrollableWindow('" + gui.drawPagePropertiesUrl() + "','" + name.toString() + "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT +")"; 635 if (checkLock) { 637 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 638 LockKey lockKey = LockKey.composeLockKey(LockKey.UPDATE_PAGE_TYPE, jParams.getPageID(), jParams.getPageID()); 639 if (!lockRegistry.canRelease(lockKey, jParams.getUser(), jParams.getSessionID())) { 640 out = ""; 641 } 642 } 643 return out; 645 } 646 647 652 public String drawPagePropertiesButton() 653 throws JahiaException { 654 return drawButton( drawPagePropertiesLauncher(), "page properties" ); 655 } 656 657 public String drawUpdateTemplateLauncher( JahiaPageDefinition theTemplate ) 659 throws JahiaException { 660 StringBuffer name = new StringBuffer ("updateTemplate_"); 661 if ( theTemplate != null ){ 662 name.append(theTemplate.getID()); 663 } 664 name.append(cleanSessionID(jParams.getSessionID())); 665 return drawLauncher( gui.drawUpdateTemplateUrl(theTemplate) , name.toString() ); 666 } 667 668 683 public String drawSelectPageLauncher(String operation, int parentPageID, int pageID) throws JahiaException { 684 StringBuffer name = new StringBuffer ("selectPage_"); 685 if ( jParams.getPage() != null ){ 686 name.append(jParams.getPage().getID()); 687 } 688 HashMap params = new HashMap (); 689 params.put(SelectPage_Engine.OPERATION, operation); 690 params.put(SelectPage_Engine.PARENT_PAGE_ID, new Integer (parentPageID)); 691 params.put(SelectPage_Engine.PAGE_ID, new Integer (pageID)); 692 name.append(cleanSessionID(jParams.getSessionID())); 693 String selectPageURL = SelectPage_Engine.getInstance().renderLink(jParams, params); 694 return "".equals(selectPageURL) ? "" : "OpenJahiaScrollableWindow('" + selectPageURL + "','" + name.toString() 695 + "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT + ")"; 696 } 697 698 public String drawSearchLauncher() 700 throws JahiaException { 701 return gui.drawSearchUrl(); 703 } 704 705 public String drawAdministrationLauncher() 708 throws JahiaException { 709 return gui.drawAdministrationLauncher(); 710 } 711 712 public String drawMySettingsLauncher () 713 throws JahiaException { 714 return gui.drawMySettingsUrl (); 715 } 716 717 public String drawMySettingsLauncher(Object params) throws JahiaException 718 { 719 return gui.drawMySettingsUrl(params); 720 } 721 722 public String drawNewUserRegistrationLauncher () 723 throws JahiaException { 724 return gui.drawNewUserRegistrationUrl (); 725 } 726 727 public String drawNewUserRegistrationLauncher(Object params) 728 throws JahiaException 729 { 730 return gui.drawNewUserRegistrationUrl(params); 731 } 732 733 public String drawSiteMapLauncher() 735 throws JahiaException { 736 return gui.drawSiteMapUrl(); 738 } 739 740 public String drawAddContainerButton( JahiaContainerList theContainerList ) 742 throws JahiaException { return drawButton( drawAddContainerLauncher(theContainerList), "add" ); } 743 744 public String drawUpdateTemplateButton( JahiaPageDefinition theTemplate ) 746 throws JahiaException { return drawButton( drawUpdateTemplateLauncher(theTemplate), "template" ); } 747 748 749 public String drawSearchButton () 752 throws JahiaException { 753 String html = ""; 754 String theUrl=""; 755 theUrl += drawSearchLauncher(); 757 html += "<form method=\"POST\" action=\"" + theUrl + "\">\n"; 759 html += "<input type=\"text\" name=\"search\" size=15 value=\"\">\n"; 760 html += "<input type=submit value=\"Search\">"; 761 html += "</form>"; 763 764 return html; 766 } 767 768 769 public String drawSiteMapButton() 771 throws JahiaException { return drawButton( drawSiteMapLauncher(), "site map" ); } 772 773 780 public String drawReleaseLockObjectLauncher(ContentObject contentObject, LockKey lockKey) 781 throws JahiaException { 782 String launcher = ""; 784 if (!ParamBean.EDIT.equals(jParams.getOperationMode())) { 785 return null; 786 } 787 if (contentObject instanceof ContentContainerList) { 789 if (LockKey.ADD_CONTAINER_TYPE.equals(lockKey.getType())) { 790 ContentContainerList contentContainerList = (ContentContainerList) contentObject; 791 JahiaContainerList jahiaContainerList = contentContainerList.getJahiaContainerList(jParams, jParams.getEntryLoadRequest()); 792 launcher = drawAddContainerLauncher(jahiaContainerList, JS_WINDOW_WIDTH, JS_WINDOW_HEIGHT, false); 793 } else if (LockKey.UPDATE_CONTAINERLIST_TYPE.equals(lockKey.getType())) { 794 launcher = drawContainerListPropertiesLauncher((ContentContainerList)contentObject, false); 795 } 796 } else if (contentObject instanceof ContentField) { 797 if (LockKey.UPDATE_FIELD_TYPE.equals(lockKey.getType())) { 798 launcher = drawUpdateFieldLauncher((ContentField)contentObject, false); 799 } 800 } else if (contentObject instanceof ContentContainer) { 801 if (LockKey.UPDATE_CONTAINER_TYPE.equals(lockKey.getType())) { 802 launcher = drawUpdateContainerLauncher((ContentContainer)contentObject, JS_WINDOW_WIDTH, JS_WINDOW_HEIGHT, false); 803 } else if (LockKey.DELETE_CONTAINER_TYPE.equals(lockKey.getType())) { 804 launcher = drawDeleteContainerLauncher((ContentContainer)contentObject, false); 805 } 806 } else if (contentObject instanceof ContentPage) { 807 if (LockKey.UPDATE_PAGE_TYPE.equals(lockKey.getType())) { 808 launcher = drawPagePropertiesLauncher(false); 809 } 810 } 811 LockService lockRegistry = ServicesRegistry.getInstance().getLockService(); 812 if (lockRegistry.isAlreadyAcquired(lockKey)) { 813 if (lockRegistry.canRelease(lockKey, jParams.getUser(), jParams.getSessionID())) { 814 return jParams.composeReleaseLockURL(lockKey); 815 } else { 816 return "javascript:" + launcher; 817 } 818 } 819 return null; 821 } 822 823 824 public String drawLockEngineLauncher(LockKey lockKey) 825 throws JahiaException { 826 String out = ""; 827 StringBuffer name = new StringBuffer ("lock_"); 829 if (jParams.getPage() != null) { 830 name.append(jParams.getPage().getID()); 831 } 832 name.append(cleanSessionID(jParams.getSessionID())); 833 String lockURL = gui.drawLockUrl(lockKey); 834 out = "".equals(lockURL) ? "" : 835 "javascript:OpenJahiaScrollableWindow('" + lockURL + "','" + name.toString() + "'," + 836 JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT + ")"; 837 return out; 839 } 840 841 846 private String drawLauncher( String url, String windowName ) 847 throws JahiaException 848 { 849 String html = ""; 850 if (!url.equals("")) { 852 html += "OpenJahiaScrollableWindow('"; 853 html += url; 854 html += "','" + windowName + "'," + JS_WINDOW_WIDTH + "," + JS_WINDOW_HEIGHT + ")"; 855 } 856 return html; 857 } 859 860 861 866 private String drawButton( String launcher, String buttonLabel ) 867 throws JahiaException 868 { 869 String html = ""; 870 if (!launcher.equals("")) { 872 html += "<a HREF=\"javascript:"; 873 html += launcher; 874 html += "\">" + buttonLabel + "</a>"; 875 } 876 return html; 877 } 879 880 881 885 private String drawLinkButton( String launcher, String buttonLabel ) 886 throws JahiaException 887 { 888 String html = ""; 889 if (!launcher.equals("")) { 891 html += "<a HREF=\""; 892 html += launcher; 893 html += "\">" + buttonLabel + "</a>"; 894 } 895 return html; 896 } 898 899 903 public String drawAnchor(JahiaField theField){ 904 905 if ( theField == null ){ 906 return ""; 907 } 908 909 StringBuffer anchor = new StringBuffer ("<A NAME="); 910 anchor.append("field_"); 911 anchor.append(theField.getID()); 912 anchor.append("></A>"); 913 914 return anchor.toString(); 915 } 916 917 918 922 public String drawAnchor(JahiaContainerList cList){ 923 924 if ( cList == null ){ 925 return ""; 926 } 927 928 StringBuffer anchor = new StringBuffer ("<A NAME="); 929 anchor.append("cList_"); 930 anchor.append(cList.getID()); 931 anchor.append("></A>"); 932 933 return anchor.toString(); 934 } 935 936 937 941 public String drawAnchor(JahiaContainer container){ 942 943 if ( container == null ){ 944 return ""; 945 } 946 947 StringBuffer anchor = new StringBuffer ("<A NAME="); 948 anchor.append("container_"); 949 anchor.append(container.getID()); 950 anchor.append("></A>"); 951 952 return anchor.toString(); 953 } 954 955 956 960 public String drawAnchor(JahiaPage page){ 961 962 if ( page == null ){ 963 return ""; 964 } 965 966 StringBuffer anchor = new StringBuffer ("<A NAME="); 967 anchor.append("page_"); 968 anchor.append(page.getID()); 969 anchor.append("></A>"); 970 971 return anchor.toString(); 972 } 973 974 977 978 999 public void drawBeginActionMenu (Object contentObject, String lockIcon, 1000 String actionIcon, 1001 boolean useFieldSet, 1002 String namePostFix, 1003 String resourceBundle, 1004 String labelKey, 1005 JspWriter out) 1006 throws IOException { 1007 if (!ParamBean.EDIT.equals(jParams.getOperationMode())) { 1008 return; 1010 } 1011 if (contentObject instanceof ContainerListBean) { 1012 ContainerListBean containerListBean = (ContainerListBean) 1013 contentObject; 1014 beginContainerListMenu(containerListBean, lockIcon, actionIcon, useFieldSet, namePostFix, resourceBundle, labelKey, out); 1015 } else if (contentObject instanceof ContainerBean) { 1016 ContainerBean containerBean = (ContainerBean) contentObject; 1017 beginContainerMenu(containerBean, lockIcon, actionIcon, useFieldSet, namePostFix, resourceBundle, labelKey, out); 1018 } else if (contentObject instanceof FieldBean) { 1019 FieldBean fieldBean = (FieldBean) contentObject; 1020 beginFieldMenu(fieldBean, lockIcon, actionIcon, useFieldSet, namePostFix, resourceBundle, labelKey, out); 1021 } else if (contentObject instanceof PageBean) { 1022 PageBean pageBean = (PageBean) contentObject; 1023 beginPageMenu(pageBean, lockIcon, actionIcon, useFieldSet, namePostFix, resourceBundle, labelKey, out); 1024 } else { 1025 logger.error("Expected Container list, container, field or page when generating menu for object "); 1026 } 1027 } 1028 1029 1050 public void drawEndActionMenu (Object contentObject, String lockIcon, 1051 String actionIcon, 1052 boolean useFieldSet, 1053 String namePostFix, 1054 String resourceBundle, 1055 String labelKey, 1056 JspWriter out) 1057 throws IOException { 1058 if (!ParamBean.EDIT.equals(jParams.getOperationMode())) { 1059 return; 1061 } 1062 Map actionURIBeans = null; 1063 if (contentObject instanceof ContainerListBean) { 1064 ContainerListBean containerListBean = (ContainerListBean) 1065 contentObject; 1066 actionURIBeans = containerListBean.getActionURIBeans(); 1067 } else if (contentObject instanceof ContainerBean) { 1068 ContainerBean containerBean = (ContainerBean) contentObject; 1069 actionURIBeans = containerBean.getActionURIBeans(); 1070 1071 } else if (contentObject instanceof FieldBean) { 1072 FieldBean fieldBean = (FieldBean) contentObject; 1073 actionURIBeans = fieldBean.getActionURIBeans(); 1074 1075 } else if (contentObject instanceof PageBean) { 1076 PageBean pageBean = (PageBean) contentObject; 1077 actionURIBeans = pageBean.getActionURIBeans(); 1078 1079 } else { 1080 logger.error("Expected Container list, container, field or page when generating menu for object "); 1081 return; 1082 } 1083 endMenu(actionURIBeans, useFieldSet, out); 1084 } 1085 1086 private void beginContainerListMenu (ContainerListBean containerListBean, 1087 String lockIcon, String actionIcon, 1088 boolean useFieldSet, 1089 String namePostFix, 1090 String resourceBundle, 1091 String labelKey, 1092 JspWriter out) 1093 throws IOException { 1094 Map actionURIBeans = containerListBean.getActionURIBeans(); 1095 beginMenu(actionURIBeans, "contentContainerList", 1096 containerListBean.getId(), 1097 containerListBean.getContainerDefinitionID(), 1098 containerListBean.getParentContainerID(), 1099 containerListBean.getPageID(), 1100 containerListBean.isCompletelyLocked(), 1101 containerListBean.isPartiallyLocked(), lockIcon, actionIcon, 1102 useFieldSet, namePostFix, resourceBundle, labelKey, out); 1103 } 1104 1105 private void beginContainerMenu (ContainerBean containerBean, 1106 String lockIcon, String actionIcon, 1107 boolean useFieldSet, 1108 String namePostFix, 1109 String resourceBundle, 1110 String labelKey, 1111 JspWriter out) 1112 throws IOException { 1113 Map actionURIBeans = containerBean.getActionURIBeans(); 1114 beginMenu(actionURIBeans, "contentContainer", containerBean.getId(), 1115 containerBean.getDefinition().getID(), 1116 containerBean.getContainerListID(), 1117 containerBean.getPageID(), 1118 containerBean.isCompletelyLocked(), 1119 containerBean.isPartiallyLocked(), lockIcon, actionIcon, 1120 useFieldSet, namePostFix, resourceBundle, labelKey, out); 1121 } 1122 1123 private void beginFieldMenu (FieldBean fieldBean, String lockIcon, 1124 String actionIcon, 1125 boolean useFieldSet, 1126 String namePostFix, 1127 String resourceBundle, 1128 String labelKey, 1129 JspWriter out) 1130 throws IOException { 1131 Map actionURIBeans = fieldBean.getActionURIBeans(); 1132 beginMenu(actionURIBeans, "contentField", fieldBean.getId(), 1133 fieldBean.getDefinition().getID(), 1134 fieldBean.getContainerID(), 1135 fieldBean.getPageID(), 1136 fieldBean.isCompletelyLocked(), 1137 fieldBean.isPartiallyLocked(), lockIcon, actionIcon, 1138 useFieldSet, namePostFix, resourceBundle, labelKey, out); 1139 } 1140 1141 private void beginPageMenu (PageBean pageBean, String lockIcon, 1142 String actionIcon, 1143 boolean useFieldSet, 1144 String namePostFix, 1145 String resourceBundle, 1146 String labelKey, 1147 JspWriter out) 1148 throws IOException { 1149 Map actionURIBeans = pageBean.getActionURIBeans(); 1150 beginMenu(actionURIBeans, "contentPage", pageBean.getId(), 1151 pageBean.getTemplateID(), 1152 pageBean.getId(), 1153 pageBean.getId(), 1154 pageBean.isCompletelyLocked(), 1155 pageBean.isPartiallyLocked(), lockIcon, actionIcon, 1156 useFieldSet, namePostFix, resourceBundle, labelKey, out); 1157 } 1158 1159 private void beginMenu (Map actionURIBeans, 1160 String typeName, 1161 int idInType, 1162 int definitionID, 1163 int parentID, 1164 int pageID, 1165 boolean completelyLocked, 1166 boolean partiallyLocked, 1167 String lockIcon, 1168 String actionIcon, 1169 boolean useFieldSet, 1170 String namePostFix, 1171 String resourceBundle, 1172 String labelKey, 1173 JspWriter out) 1174 throws IOException { 1175 if (actionURIBeans.isEmpty()) { 1176 return; 1177 } 1178 if (useFieldSet) { 1179 if (completelyLocked) { 1180 out.println( 1181 "<fieldset style=\"padding: 5px;border: 1px solid #FF0000;\">"); 1182 } else if (partiallyLocked) { 1183 out.println( 1184 "<fieldset style=\"padding: 5px;border: 1px solid #FF8000;\">"); 1185 } else { 1186 out.println("<fieldset style=\"padding: 5px;\">"); 1187 } 1188 1189 out.println("<legend align=\"right\">"); 1190 } 1191 out.println(" <a class=\"admin-menu-link\" HREF=\"\" onclick=\"return buttonClick(event, '" + 1192 buildUniqueContentID(typeName,idInType,definitionID,parentID,pageID) + "');\""); 1193 out.println(" onmouseover=\"buttonMouseover(event, '" + 1194 buildUniqueContentID(typeName,idInType,definitionID,parentID,pageID) + "');\">"); 1195 out.print(" <span class=\""); 1196 if (completelyLocked) { 1197 out.print("lockIcon\""); 1198 if (lockIcon != null) { 1199 out.print(" style=\"background-image: url('" + lockIcon + "');background-repeat: no-repeat;padding-right:7px;\" >"); 1200 } else { 1201 out.println("><img class=\"lockIcon\" SRC=\"" + 1202 getURLImageContext() + "/lock.gif" + "\" alt=\"" + 1203 getResource(resourceBundle, typeName + "Operations") + "\""); 1204 out.println(" border=\"0\"/>"); 1205 } 1206 } else { 1207 out.print("actionIcon\""); 1208 if (actionIcon != null) { 1209 out.println(" style=\"background-image: url('" + actionIcon + "');background-repeat: no-repeat;padding-right:7px;\"> "); 1210 } else { 1211 out.println("><img class=\"actionIcon\" SRC=\"" + 1212 getURLImageContext() + "/action.gif" + "\" alt=\"" + 1213 getResource(resourceBundle, typeName + "Operations") + "\""); 1214 out.println(" border=\"0\"/>"); 1215 } 1216 } 1217 out.println("</span>"); 1218 if (labelKey != null) { 1219 out.println(getResource(resourceBundle, labelKey)); 1220 } 1221 out.println("</a>"); 1222 if (useFieldSet) { 1223 out.println("</legend>"); 1224 } 1225 1226 out.println("<div id=\"" + buildUniqueContentID(typeName,idInType,definitionID,parentID,pageID) + 1227 "\" class=\"menu\" style=\"left: 161px; top: 265px; visibility: hidden;\">"); 1228 Iterator actionURIIter = actionURIBeans.entrySet().iterator(); 1229 while (actionURIIter.hasNext()) { 1230 Map.Entry curEntry = (Map.Entry ) actionURIIter.next(); 1231 ActionURIBean curActionURIBean = (ActionURIBean) curEntry.getValue(); 1232 if (curActionURIBean.isAuthorized()) { 1233 out.println("<a class=\"menuItem\" HREF=\"javascript:" + 1234 curActionURIBean.getLauncherUri() + "\">"); 1235 out.print(" <span class='"); 1236 if (curActionURIBean.isLocked()) { 1237 out.println("lockgreyIcon'>"); 1238 out.println(" <img class=\"lockgreyIcon\" SRC=\"" + getURLImageContext() + 1239 "/lock_grey.gif\" alt=\"\" border=\"0\"/>"); 1240 } else { 1241 out.println(curActionURIBean.getName() + "Icon'>"); 1242 out.println(" <img class=\"" + curActionURIBean.getName() + "Icon\" SRC=\"" + 1243 getURLImageContext() + "/" + curActionURIBean.getName() + 1244 ".gif\" alt=\"\" border=\"0\"/>"); 1245 } 1246 out.println(" </span>" + 1247 getResource(resourceBundle, curActionURIBean.getName() + namePostFix)); 1248 out.println("</a>"); 1249 } 1250 } 1251 out.println("</div>"); 1252 } 1253 1254 private void endMenu (Map actionURIBeans, boolean useFieldSet, 1255 JspWriter out) 1256 throws IOException { 1257 if (actionURIBeans.isEmpty()) { 1258 return; 1259 } 1260 if (useFieldSet) { 1261 out.println("</fieldset>"); 1262 } 1263 } 1264 1265 private String getResource (String resourceBundle, 1266 String resourceName) { 1267 ResourceBundle res = null; 1268 String resValue = null; 1269 1270 Locale locale = jParams.getLocale(); 1271 try { 1272 res = ResourceBundle.getBundle(resourceBundle, locale); 1273 resValue = JahiaResourceBundle.getString(res, resourceName, 1274 locale); 1275 } catch (MissingResourceException mre) { 1276 logger.warn("Error accessing resource " + resourceName + 1277 " in bundle " + resourceBundle + " for locale " + 1278 locale + ":" + mre.getMessage()); 1279 } 1280 return resValue; 1281 } 1282 1283 private String getURLImageContext () { 1284 return jParams.getRequest().getContextPath() + 1285 "/jsp/jahia/engines/images/actions"; 1286 } 1287 1288 private String buildUniqueContentID (String typeName, 1289 int idInType, 1290 int definitionID, 1291 int parentID, 1292 int pageID) { 1293 StringBuffer result = new StringBuffer (typeName); 1294 result.append("_"); 1295 result.append(idInType); 1296 result.append("_"); 1297 result.append(definitionID); 1298 result.append("_"); 1299 result.append(parentID); 1300 result.append("_"); 1301 result.append(pageID); 1302 return result.toString(); 1303 } 1304 1305 1306 } | Popular Tags |