1 19 package org.jahia.gui; 20 21 import java.util.Enumeration ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 25 import org.jahia.bin.Jahia; 26 import org.jahia.content.ContentObject; 27 import org.jahia.data.containers.JahiaContainer; 28 import org.jahia.data.containers.JahiaContainerList; 29 import org.jahia.data.containers.JahiaContainerListPagination; 30 import org.jahia.data.fields.JahiaField; 31 import org.jahia.data.fields.LoadFlags; 32 import org.jahia.engines.JahiaEngine; 33 import org.jahia.engines.containerlistproperties.ContainerListProperties_Engine; 34 import org.jahia.exceptions.JahiaException; 35 import org.jahia.params.ParamBean; 36 import org.jahia.registries.EnginesRegistry; 37 import org.jahia.registries.ServicesRegistry; 38 import org.jahia.services.acl.ACLResource; 39 import org.jahia.services.acl.ACLResourceInterface; 40 import org.jahia.services.containers.ContentContainer; 41 import org.jahia.services.containers.ContentContainerList; 42 import org.jahia.services.fields.ContentField; 43 import org.jahia.services.lock.LockKey; 44 import org.jahia.services.pages.ContentPage; 45 import org.jahia.services.pages.JahiaPage; 46 import org.jahia.services.pages.JahiaPageDefinition; 47 import org.jahia.services.pages.JahiaPageService; 48 import org.jahia.services.usermanager.JahiaUser; 49 import org.jahia.utils.JahiaTools; 50 51 public class GuiBean { 52 53 private static org.apache.log4j.Logger logger = 54 org.apache.log4j.Logger.getLogger(GuiBean.class); 55 56 private ParamBean jParams; 57 private HTMLToolBox html; 58 private JahiaUser currentUser; 59 private JahiaPage thePage; 60 61 62 67 public GuiBean( ParamBean jahiaParams ) 68 { 69 this.jParams = jahiaParams; 70 this.html = new HTMLToolBox( this, jParams ); 71 this.currentUser = jahiaParams.getUser(); 72 this.thePage = jahiaParams.getPage(); 73 } 75 76 81 public HTMLToolBox html() 82 { 83 return html; 84 } 86 87 88 93 public String drawHttpPath() 94 { 95 if (jParams != null) { 96 return jParams.settings().getJahiaTemplatesHttpPath(); 97 } else { 98 return ""; 99 } 100 } 102 103 108 public String drawHttpPath(String theTemplateFolderName) 109 { 110 if (jParams != null) { 111 return jParams.settings().getJahiaTemplatesHttpPath() + theTemplateFolderName; 112 } else { 113 return ""; 114 } 115 } 117 118 121 public String drawHttpJspContext (HttpServletRequest req){ 122 123 StringBuffer path = new StringBuffer (); 124 path.append(req.getRequestURI().substring(0,req.getRequestURI().lastIndexOf("/"))); 125 return path.toString(); 126 } 127 128 133 public String drawPageLink(int thePageID) 134 throws JahiaException 135 { 136 String result = ""; 137 138 if (jParams != null) { 139 JahiaPage currentPage = jParams.getPage(); 141 if (currentPage != null) { 142 result = jParams.composePageUrl(thePageID, jParams.getLocale().toString()); 143 } 144 } 145 return result; 146 } 148 149 153 public String drawSwitchModeLink() 154 throws JahiaException 155 { 156 String result = ""; 157 158 if (jParams != null) { 159 JahiaPage currentPage = jParams.getPage(); 161 if (currentPage != null) { 162 if (currentPage.checkWriteAccess (jParams.getUser())) { 164 if (jParams.getOperationMode().equals( ParamBean.NORMAL ) 165 || jParams.getOperationMode().equals( ParamBean.COMPARE )) { 166 result = jParams.composeOperationUrl( ParamBean.EDIT, "" ); 167 } else { 168 result = jParams.composeOperationUrl( ParamBean.NORMAL, "" ); 169 } 170 } 171 } 172 } 173 return result; 174 } 176 181 public String drawNormalModeLink() 182 throws JahiaException 183 { 184 String result = ""; 185 186 if (jParams != null) { 187 JahiaPage currentPage = jParams.getPage(); 189 if (currentPage != null) { 190 result = jParams.composeOperationUrl( ParamBean.NORMAL, "" ); 192 } 193 } 194 return result; 195 } 196 197 203 public String drawEditModeLink() 204 throws JahiaException 205 { 206 String result = ""; 207 208 if (jParams != null) { 209 JahiaPage currentPage = jParams.getPage(); 211 if (currentPage != null) 213 result = jParams.composeOperationUrl(ParamBean.EDIT, ""); 214 } 215 return result; 216 } 217 218 227 public String drawRevDifferenceModeLink(int revisionDiffID, String operationMode) 228 throws JahiaException 229 { 230 String result = ""; 231 232 String opMode = operationMode; 235 236 if (jParams != null) { 237 JahiaPage currentPage = jParams.getPage(); 239 if (currentPage != null) { 240 241 if (currentPage.checkWriteAccess (jParams.getUser()) 243 || currentPage.checkAdminAccess (jParams.getUser())) { 244 result = jParams.composeRevDifferenceUrl(revisionDiffID,opMode,""); 245 } else { 246 result = ""; 247 } 248 } 250 } 251 return result; 252 } 253 254 260 public String drawPreviewModeLink() 261 throws JahiaException 262 { 263 String result = ""; 264 265 if (jParams != null) { 266 JahiaPage currentPage = jParams.getPage(); 268 if (currentPage != null) 269 { 270 271 result = jParams.composeOperationUrl( ParamBean.PREVIEW, "" ); 273 } 274 } 275 return result; 276 } 277 278 286 public String drawPageLanguageSwitch(String code) 287 throws JahiaException { 288 289 String result = ""; 290 if (jParams != null) { 291 JahiaPage currentPage = jParams.getPage(); 293 if (currentPage != null) { 294 result = jParams.composeLanguageURL(code); 295 } 296 } 297 return result; 298 } 299 300 301 public String drawPopupLoginUrl() 302 throws JahiaException 303 { return drawUrl( "login", "/pid/" + jParams.getPageID() ); } 304 305 public String drawPopupLoginUrl( int destinationPageID ) 306 throws JahiaException 307 { return drawUrl( "login", "/pid/" + destinationPageID ); } 308 309 public String drawLoginUrl() 310 throws JahiaException 311 { return drawUrl( "login", "/pid/" + jParams.getPageID() + "?screen=save" ); } 312 313 public String drawLoginUrl( int destinationPageID ) 314 throws JahiaException 315 { return drawUrl( "login", "/pid/" + destinationPageID + "?screen=save" ); } 316 318 319 public String drawPopupLogoutUrl( int destinationPageID ) 321 throws JahiaException 322 { 323 String result = ""; 324 if ( jParams.getUser().getUsername()!= "guest" ) 325 { 326 result = drawUrl( "logout", new Integer (destinationPageID) ); 327 } 328 return result; 329 } 330 331 public String drawPopupLogoutUrl() 332 throws JahiaException 333 { return drawPopupLogoutUrl( jParams.getPageID() ); } 334 335 public String drawLogoutUrl( int destinationPageID ) 336 throws JahiaException 337 { return drawPopupLogoutUrl( destinationPageID ); } 338 340 public String drawLogoutUrl() 341 throws JahiaException 342 { return drawPopupLogoutUrl( jParams.getPageID() ); } 343 344 351 public String drawUpdateFieldUrl( JahiaField theField ) 352 throws JahiaException { 353 ContentField contentField = theField.getContentField(); 354 return drawUrlCheckWriteAccess( "updatefield", contentField ); 355 } 356 357 363 public String drawUpdateFieldUrl(ContentField contentField) 364 throws JahiaException { 365 return drawUrlCheckWriteAccess("updatefield", contentField); 366 } 367 368 374 public String drawAddContainerUrl(JahiaContainerList jahiaContainerList ) 375 throws JahiaException { 376 if (jahiaContainerList != null) { 377 return drawUrlCheckWriteAccess( "addcontainer", jahiaContainerList ); 378 } else { 379 JahiaException je = new JahiaException( "Accessing non-existing data", 380 "GuiBean : Trying to access to non-existing containerlist (addContainerUrl)", 381 JahiaException.DATA_ERROR, JahiaException.WARNING_SEVERITY ); 382 logger.warn("Trying to generate URL for null container list", je); 383 return ""; 384 } 385 } 386 387 394 public String drawUpdateContainerUrl( JahiaContainer theContainer ) 395 throws JahiaException { 396 ContentContainer contentContainer = theContainer.getContentContainer(); 397 return drawUrlCheckWriteAccess( "updatecontainer", contentContainer ); 398 } 399 400 406 public String drawUpdateContainerUrl(ContentContainer contentContainer) 407 throws JahiaException { 408 return drawUrlCheckWriteAccess( "updatecontainer", contentContainer ); 409 } 410 411 412 419 public String drawDeleteContainerUrl( JahiaContainer theContainer ) 420 throws JahiaException { 421 ContentContainer contentContainer = theContainer.getContentContainer(); 422 return drawUrlCheckWriteAccess( "deletecontainer", contentContainer); 423 } 424 425 431 public String drawDeleteContainerUrl(ContentContainer contentContainer) 432 throws JahiaException { 433 return drawUrlCheckWriteAccess( "deletecontainer", contentContainer); 434 } 435 436 public String drawWorkflowUrl() 437 throws JahiaException { 438 439 return drawUrl("workflow", jParams.getPage()); 440 } 441 442 public String drawLockUrl(LockKey lockKey) 443 throws JahiaException { 444 return drawUrl("lock", lockKey); 445 } 446 447 public String drawPagePropertiesUrl() 448 throws JahiaException { return drawUrl( "pageproperties", jParams.getPage() ); } 449 450 public String drawUpdateTemplateUrl( JahiaPageDefinition theTemplate ) 451 throws JahiaException 452 { 453 return drawUrlCheckWriteAccess( "template", theTemplate ); 454 } 455 456 463 public String drawContainerListPropertiesUrl( JahiaContainerList theContainerList ) 464 throws JahiaException { 465 ContentContainerList contentContainerList = theContainerList.getContentContainerList(); 466 return drawUrlCheckWriteAccess( "containerlistproperties", contentContainerList ); 467 } 468 469 475 public String drawContainerListPropertiesUrl(ContentContainerList contentContainerList) 476 throws JahiaException { 477 if (contentContainerList != null) { 478 return drawUrlCheckWriteAccess("containerlistproperties", 479 contentContainerList); 480 } else { 481 return ""; 482 } 483 } 484 485 501 public String drawContainerListNextWindowPageURL( JahiaContainerList theContainerList, 502 int pageStep, 503 int newWindowSize, 504 boolean scrollingValueOnly ) 505 506 throws JahiaException { 507 return drawContainerListWindowPageURL( theContainerList, pageStep, 508 newWindowSize, 509 scrollingValueOnly); 510 } 511 512 528 public String drawContainerListPreviousWindowPageURL ( JahiaContainerList theContainerList, 529 int pageStep, 530 int newWindowSize, 531 boolean scrollingValueOnly ) 532 throws JahiaException { 533 return drawContainerListWindowPageURL( theContainerList, -pageStep, 534 newWindowSize, 535 scrollingValueOnly); 536 } 537 538 556 public String drawContainerListWindowPageURL ( JahiaContainerList theContainerList, 557 int pageStep, 558 int newWindowSize, 559 boolean scrollingValueOnly ) 560 throws JahiaException { 561 562 if ( theContainerList == null ){ 563 return null; 564 } 565 566 JahiaContainerListPagination cListPagination = theContainerList.getCtnListPagination(); 567 if ( cListPagination == null || cListPagination.getWindowSize()!=newWindowSize ) 568 { 569 cListPagination = new JahiaContainerListPagination(theContainerList,jParams, newWindowSize); 570 theContainerList.setCtnListPagination(cListPagination); 571 } 572 573 if ( !cListPagination.isValid() || (cListPagination.getNbPages()<2) ){ 575 return null; 577 } 578 579 if ( (cListPagination.getCurrentPageIndex()==1) && (pageStep<0) ){ 581 return null; 583 } 584 585 int nextPage = cListPagination.getCurrentPageIndex()+1; 587 if ( (nextPage>cListPagination.getNbPages()) && (pageStep>0) ){ 588 return null; 590 } 591 592 int windowSize = cListPagination.getWindowSize(); 593 int windowOffset = cListPagination.getWindowOffset(); 594 windowOffset += pageStep * windowSize; 595 596 String paramName = "ctnscroll_" + theContainerList.getDefinition().getName(); 598 String paramValue = Integer.toString(windowSize) + "_" + 599 Integer.toString(windowOffset); 600 601 if ( scrollingValueOnly ){ 602 return paramValue; 603 } 604 605 606 String cacheStatus = jParams.getCacheStatus(); 607 jParams.setCacheStatus(ParamBean.CACHE_OFFONCE); 608 String curPageURL = jParams.composePageUrl(jParams.getPageID(), jParams.getLocale().toString()); 609 jParams.setCacheStatus(cacheStatus); 610 curPageURL += "/" + paramName + "/" + paramValue; 611 return curPageURL; 612 } 613 614 628 public String drawContainerListWindowPageURL ( JahiaContainerList containerList, 629 int pageStep, 630 boolean scrollingValueOnly ) 631 632 throws JahiaException { 633 634 if ( containerList == null || containerList.getCtnListPagination()== null || 635 !containerList.getCtnListPagination().isValid() || (pageStep <= 0) ){ 636 return null; 637 } 638 639 String paramName = "ctnscroll_" + containerList.getDefinition().getName(); 640 String paramValue = Integer.toString(containerList.getCtnListPagination().getWindowSize()) + "_" + 641 Integer.toString((pageStep-1)*containerList.getCtnListPagination().getWindowSize()); 642 643 if ( scrollingValueOnly ){ 644 return paramValue; 645 } 646 647 648 String cacheStatus = jParams.getCacheStatus(); 649 jParams.setCacheStatus(ParamBean.CACHE_OFFONCE); 650 String curPageURL = jParams.composePageUrl(jParams.getPageID(), jParams.getLocale().toString()); 651 jParams.setCacheStatus(cacheStatus); 652 curPageURL += "/" + paramName + "/" + paramValue; 653 return curPageURL; 654 } 655 656 public String drawSearchUrl() 657 throws JahiaException { return drawUrl( "search", null ); } 658 660 public String drawMySettingsUrl () throws JahiaException { 661 return drawUrl ("mysettings", null); 662 } 663 664 public String drawMySettingsUrl(Object theObj) throws JahiaException 665 { 666 return drawUrl("mysettings", theObj); 667 } 668 669 public String drawNewUserRegistrationUrl () throws JahiaException { 670 return drawUrl("newuserregistration", null); 671 } 672 673 public String drawNewUserRegistrationUrl(Object theObj) 674 throws JahiaException 675 { 676 return drawUrl("newuserregistration", theObj); 677 } 678 679 public String drawSiteMapUrl() 680 throws JahiaException { return drawUrl( "sitemap", null ); } 681 683 688 public String drawAdministrationLauncher() 689 throws JahiaException { 690 691 return jParams.getResponse().encodeURL(jParams.getRequest().getContextPath() + Jahia.getInitAdminServletPath() + "?do=passthru"); 692 693 } 694 696 697 702 private String drawUrl( String engineName, Object theObj ) 703 throws JahiaException 704 { 705 String htmlResult = ""; 706 JahiaEngine theEngine = (JahiaEngine) EnginesRegistry.getInstance().getEngine( engineName ); 707 if (theEngine.authoriseRender(jParams)) { 708 htmlResult = theEngine.renderLink( jParams, theObj ); 709 } 710 return htmlResult; 711 } 712 714 private String drawUrlCheckWriteAccess(String engineName, Object anObject) 715 throws JahiaException { 716 JahiaEngine theEngine = (JahiaEngine) EnginesRegistry.getInstance().getEngine(engineName); 717 if (theEngine.authoriseRender(jParams)) { 718 if (anObject instanceof ContentObject) { 719 ContentObject contentObject = (ContentObject)anObject; 720 if (contentObject.checkWriteAccess(currentUser)) { 721 return theEngine.renderLink( jParams, anObject ); 722 } 723 } else if (anObject instanceof ACLResourceInterface) { 724 if (ACLResource.checkWriteAccess((ACLResourceInterface)anObject,currentUser)) { 725 return theEngine.renderLink( jParams, anObject ); 726 } 727 } else if (anObject instanceof JahiaContainerList) { 728 JahiaContainerList containerList = (JahiaContainerList)anObject; 732 if (engineName.equals(ContainerListProperties_Engine.ENGINE_NAME) ){ 733 if (containerList.getID() == 0 && jParams.getPage().checkAdminAccess(currentUser) 734 || containerList.getID() != 0 && containerList.checkWriteAccess(currentUser) ) { 735 return theEngine.renderLink( jParams, anObject ); 736 } 737 } else { 738 boolean hasWriteAccess = false; 740 if (containerList.getID() != 0) 741 hasWriteAccess = containerList.checkWriteAccess(currentUser); 742 else 743 { 744 int parentId = containerList.getParentEntryID(); 745 if (parentId != 0) 746 { 747 JahiaContainer parent = ServicesRegistry.getInstance() 748 .getJahiaContainersService().loadContainer( 749 parentId, LoadFlags.ALL, jParams, 750 jParams.getEntryLoadRequest()); 751 if (parent != null) 752 hasWriteAccess = parent.checkWriteAccess(currentUser); 753 else 754 parentId = 0; 755 } 756 if (parentId == 0) 757 { 758 hasWriteAccess = jParams.getPage().checkWriteAccess( 759 currentUser); 760 } 761 } 762 if (hasWriteAccess) 763 return theEngine.renderLink(jParams, anObject); 764 } 765 } 766 767 } 768 return ""; 769 } 770 771 776 public String drawUsername() 777 { 778 if (jParams != null) { 779 return currentUser.getUsername(); 780 } else { 781 return ""; 782 } 783 } 785 786 789 public boolean isEditMode() 790 { 791 if (jParams != null) { 792 return jParams.getOperationMode().equals(ParamBean.EDIT); 793 } else { 794 return false; 795 } 796 } 798 public boolean isNormalMode() 799 { 800 if (jParams != null) { 801 return jParams.getOperationMode().equals(ParamBean.NORMAL); 802 } else { 803 return false; 804 } 805 } 806 807 public boolean isCompareMode() 808 { 809 if (jParams != null) { 810 return jParams.getOperationMode().equals(ParamBean.COMPARE); 811 } else { 812 return false; 813 } 814 } 815 816 public boolean isPreviewMode() 817 { 818 if (jParams != null) { 819 return jParams.getOperationMode().equals(ParamBean.PREVIEW); 820 } else { 821 return false; 822 } 823 } 824 825 830 public boolean isLogged() 831 { 832 if (jParams != null) { 833 834 if (!"guest".equals(currentUser.getUsername())) { 835 return true; 836 } else { 837 return false; 838 } 839 } else { 840 return false; 841 } 842 } 844 845 850 public boolean isPageInPath( int destPageID ) 851 throws JahiaException 852 { 853 if (jParams != null) { 854 Enumeration thePath = thePage.getContentPagePath(jParams.getOperationMode(), currentUser); 855 while (thePath.hasMoreElements()) { 856 ContentPage aPage = (ContentPage) thePath.nextElement(); 857 if (aPage.getID() == destPageID) { 858 return true; 859 } 860 } 861 } 862 return false; 863 } 865 866 871 public boolean isPageInPath( int destPageID, int levels ) 872 throws JahiaException 873 { 874 if (jParams != null) { 875 Enumeration thePath = thePage.getContentPagePath(levels, jParams.getOperationMode(), currentUser); 876 while (thePath.hasMoreElements()) { 877 ContentPage aPage = (ContentPage) thePath.nextElement(); 878 if (aPage.getID() == destPageID) { 879 return true; 880 } 881 } 882 } 883 return false; 884 } 886 887 892 public boolean isNS(HttpServletRequest req) 893 { 894 String userAgent = req.getHeader( "user-agent" ); 895 if (userAgent != null) { 896 if (userAgent.indexOf( "Mozilla" ) != -1) { 897 if (userAgent.indexOf( "MSIE" ) == -1) { 898 return true; 899 } 900 } 901 } 902 return false; 903 } 905 906 911 public boolean isNS4(HttpServletRequest req) 912 { 913 String userAgent = req.getHeader( "user-agent" ); 914 if (userAgent != null) { 915 if (userAgent.indexOf( "Mozilla/4" ) != -1) { 916 if (userAgent.indexOf( "MSIE" ) == -1) { 917 return true; 918 } 919 } 920 } 921 return false; 922 } 924 925 930 public boolean isNS6(HttpServletRequest req) 931 { 932 String userAgent = req.getHeader( "user-agent" ); 933 if (userAgent != null) { 934 if (userAgent.indexOf( "Mozilla/5" ) != -1) { 935 return true; 936 } 937 } 938 return false; 939 } 941 942 947 public boolean isIE(HttpServletRequest req) 948 { 949 String userAgent = req.getHeader( "user-agent" ); 950 if (userAgent != null) { 951 if (userAgent.indexOf( "MSIE" ) != -1) { 952 return true; 953 } 954 } 955 return false; 956 } 958 959 964 public boolean isIE4(HttpServletRequest req) 965 { 966 String userAgent = req.getHeader( "user-agent" ); 967 if (userAgent != null) { 968 if (userAgent.indexOf( "MSIE 4" ) != -1) { 969 return true; 970 } 971 } 972 return false; 973 } 975 976 981 public boolean isIE5(HttpServletRequest req) 982 { 983 String userAgent = req.getHeader( "user-agent" ); 984 if (userAgent != null) { 985 if (userAgent.indexOf( "MSIE 5" ) != -1) { 986 return true; 987 } 988 } 989 return false; 990 } 992 993 998 public boolean isIE6(HttpServletRequest req) 999 { 1000 String userAgent = req.getHeader( "user-agent" ); 1001 if (userAgent != null) { 1002 if (userAgent.indexOf( "MSIE 6" ) != -1) { 1003 return true; 1004 } 1005 } 1006 return false; 1007 } 1009 1014 public boolean isIE7(HttpServletRequest req) 1015 { 1016 String userAgent = req.getHeader( "user-agent" ); 1017 if (userAgent != null) { 1018 if (userAgent.indexOf( "MSIE 7" ) != -1) { 1019 return true; 1020 } 1021 } 1022 return false; 1023 } 1025 1026 1030 public boolean isOpera(HttpServletRequest req) 1031 { 1032 String userAgent = req.getHeader( "user-agent" ); 1033 if (userAgent != null) { 1034 userAgent = userAgent.toLowerCase(); 1035 if (userAgent.indexOf( "opera" ) != -1) { 1036 return true; 1037 } 1038 } 1039 return false; 1040 } 1042 1047 public boolean isWindow(HttpServletRequest req) 1048 { 1049 String userAgent = req.getHeader( "user-agent" ); 1050 if (userAgent != null) { 1051 if (userAgent.indexOf( "Win" ) != -1) { 1052 return true; 1053 } 1054 } 1055 return false; 1056 } 1058 1059 1064 public boolean isUnix(HttpServletRequest req) 1065 { 1066 String userAgent = req.getHeader( "user-agent" ); 1067 if (userAgent != null) { 1068 if (userAgent.indexOf( "X11" ) != -1) { 1069 return true; 1070 } 1071 } 1072 return false; 1073 } 1075 1076 1081 public boolean isMac(HttpServletRequest req) 1082 { 1083 String userAgent = req.getHeader( "user-agent" ); 1084 if (userAgent != null) { 1085 if (userAgent.indexOf( "Mac" ) != -1) { 1086 return true; 1087 } 1088 } 1089 return false; 1090 } 1092 1093 1098 public boolean checkWriteAccess() 1099 { 1100 if (thePage.checkWriteAccess( currentUser )) { 1101 return true; 1102 } 1103 return false; 1104 } 1106 1122 public static String glueTitle( String in, int len ) 1123 { 1124 if (in == null){ 1125 return null; 1126 } 1127 in = JahiaTools.html2text(in); 1128 if ( (in.length()) > len && (len > 2)) { 1129 in = in.substring( 0, len - 3 ) + "..."; 1130 } 1131 in = JahiaTools.replacePattern(in," "," "); 1132 in = JahiaTools.text2html(in); 1133 return in; 1134 } 1136 1137 1156 public int getLevelID( int level ) 1157 throws JahiaException 1158 { 1159 Enumeration thePath = thePage.getContentPagePath(jParams.getOperationMode(), currentUser); 1160 int count_loop = 0; 1161 while (thePath.hasMoreElements()) { 1162 ContentPage aPage = (ContentPage) thePath.nextElement(); 1163 count_loop++; 1164 if (count_loop == (level)) { 1165 return aPage.getID(); 1166 } 1167 } 1168 return -1; 1169 } 1171 1172 1180 public int getLevel() 1181 throws JahiaException 1182 { 1183 Enumeration thePath = thePage.getContentPagePath(jParams.getOperationMode(), this.currentUser); 1184 int count_loop = 0; 1185 while (thePath.hasMoreElements()) { 1186 ContentPage aPage = (ContentPage) thePath.nextElement(); 1187 count_loop++; 1188 if (aPage.getID() == thePage.getID()) { 1189 return count_loop; 1190 } 1191 } 1192 return -1; 1193 } 1195 1196 1200 public JahiaPage getHomePage() 1201 throws JahiaException 1202 { 1203 if ( jParams.getSite() == null ) 1204 return null; 1205 1206 JahiaPageService pageService = ServicesRegistry.getInstance().getJahiaPageService(); 1207 1208 JahiaPage originPage = pageService.lookupPage(jParams.getSite().getHomePageID() 1210 ,jParams.getEntryLoadRequest(),jParams.getOperationMode(),jParams.getUser(),false); 1211 1212 return originPage; 1213 1214 } 1216 1219 public ContentPage getContentHomePage() 1220 throws JahiaException 1221 { 1222 if ( jParams.getSite() == null ) 1223 return null; 1224 return ContentPage.getPage(jParams.getSite().getHomePageID()); 1225 1226 } 1228} | Popular Tags |