1 40 41 package org.jahia.services.pages; 42 43 import java.util.ArrayList ; 44 import java.util.Enumeration ; 45 import java.util.HashMap ; 46 import java.util.Iterator ; 47 import java.util.List ; 48 import java.util.Map ; 49 import java.util.Set ; 50 import java.util.Vector ; 51 52 import org.jahia.bin.Jahia; 53 import org.jahia.content.ContentObject; 54 import org.jahia.data.JahiaDOMObject; 55 import org.jahia.data.events.JahiaEvent; 56 import org.jahia.data.fields.JahiaField; 57 import org.jahia.data.fields.LoadFlags; 58 import org.jahia.data.files.JahiaFile; 59 import org.jahia.exceptions.JahiaException; 60 import org.jahia.exceptions.JahiaInitializationException; 61 import org.jahia.exceptions.JahiaOperationNotAllowedException; 62 import org.jahia.exceptions.JahiaPageNotFoundException; 63 import org.jahia.exceptions.JahiaTemplateNotFoundException; 64 import org.jahia.params.ParamBean; 65 import org.jahia.registries.ServicesRegistry; 66 import org.jahia.services.acl.ACLNotFoundException; 67 import org.jahia.services.acl.JahiaBaseACL; 68 import org.jahia.services.cache.Cache; 69 import org.jahia.services.cache.CacheFactory; 70 import org.jahia.services.fields.ContentField; 71 import org.jahia.services.sites.JahiaSite; 72 import org.jahia.services.usermanager.JahiaUser; 73 import org.jahia.services.version.ActivationTestResults; 74 import org.jahia.services.version.EntryLoadRequest; 75 import org.jahia.services.version.JahiaSaveVersion; 76 import org.jahia.services.version.StateModificationContext; 77 import org.jahia.settings.SettingsBean; 78 79 87 public class JahiaPageBaseService extends JahiaPageService { 88 private static org.apache.log4j.Logger logger = 89 org.apache.log4j.Logger.getLogger(JahiaPageBaseService.class); 90 91 private static final int VERSION_START_STATUS = 2; 92 93 94 private static JahiaPageBaseService instance; 95 96 private static int undefined_counter = 0; 97 98 public static final String PAGE_INFO_CACHE = "PageInfoCache"; 100 public static final String VERSIONING_PAGE_INFO_CACHE = "VersioningPageInfoCache"; 102 public static final String CONTENT_PAGE_CACHE = "ContentPageCache"; 104 105 106 private static Cache mPageInfosCache; 107 108 109 private static Cache mVersioningPageInfosCache; 110 111 112 114 private Cache mContentPageCache; 115 116 private JahiaPagesDB mPageDB; 117 private JahiaPageUtilsDB mUtilsDB; 118 private JahiaPageTemplateService mTemplateService; 119 120 125 protected JahiaPageBaseService () 126 throws JahiaException { 127 } 128 129 135 private boolean authorizePageLoad (JahiaPage page, int loadFlag, 136 JahiaUser user) { 137 138 if (!page.checkReadAccess(user)) { 139 return false; 140 } 141 if (loadFlag == PageLoadFlags.ALL) { 142 return true; 143 } 144 switch (page.getPageType()) { 145 case (JahiaPageInfo.TYPE_DIRECT): 146 return loadFlag == PageLoadFlags.DIRECT; 147 case (JahiaPageInfo.TYPE_LINK): 148 return loadFlag == PageLoadFlags.INTERNAL; 149 case (JahiaPageInfo.TYPE_URL): 150 return loadFlag == PageLoadFlags.URL; 151 } 152 return false; 153 } 154 155 public synchronized JahiaPage createPage (int siteID, 157 int parentID, 158 int pageType, 159 String title, 160 int pageTemplateID, 161 String remoteURL, 162 int pageLinkID, 163 String creator, 164 int parentAclID, 165 ParamBean jParam) 166 throws JahiaException { 167 checkService(); 169 170 logger.debug("Creating Page " + title + " ..."); 171 172 if (parentID > 0) { 178 Vector parentPageInfoVector = lookupPageInfos(parentID, 179 EntryLoadRequest.CURRENT); 180 if (parentPageInfoVector == null) { 181 throw new JahiaException("Could not create page.", 182 "Could not create a new page : parent page [" + 183 parentID + "] not found.", 184 JahiaException.PAGE_ERROR, 185 JahiaException.ERROR_SEVERITY); 186 } 187 parentPageInfoVector = null; 189 } 190 191 195 int pageID = mPageDB.getNextID(); 197 198 int counter = 0; 200 201 String dateOfCreation = new Long ( (new java.util.Date ()).getTime()). 203 toString(); 204 205 ContentPage linkedPage = null; 206 JahiaBaseACL acl = null; 207 208 switch (pageType) { 213 214 case JahiaPage.TYPE_DIRECT: 215 case JahiaPage.TYPE_URL: 216 217 acl = new JahiaBaseACL(); 219 if (acl != null) { 220 try { 221 acl.create(parentAclID); 222 } catch (ACLNotFoundException ex) { 223 throw new JahiaException("Could not create page.", 224 "The parent ACL ID [" + 225 parentAclID + 226 "] could not be found," + 227 " while trying to create a new page.", 228 JahiaException.PAGE_ERROR, 229 JahiaException.ERROR_SEVERITY); 230 } 231 } else { 232 throw new JahiaException("Could not create page.", 233 "Could not instanciate a new ACL object while trying to create a new page.", 234 JahiaException.PAGE_ERROR, 235 JahiaException.CRITICAL_SEVERITY); 236 } 237 break; 238 239 case JahiaPage.TYPE_LINK: 240 linkedPage = 241 lookupContentPage(pageLinkID, jParam.getEntryLoadRequest(), true); 242 acl = new JahiaBaseACL(); 244 if (acl != null) { 245 try { 246 acl.create(parentAclID); 247 } catch (ACLNotFoundException ex) { 248 throw new JahiaException("Could not create page.", 249 "The parent ACL ID [" + 250 parentAclID + 251 "] could not be found," + 252 " while trying to create a new page.", 253 JahiaException.PAGE_ERROR, 254 JahiaException.ERROR_SEVERITY); 255 } 256 } else { 257 throw new JahiaException("Could not create page.", 258 "Could not instanciate a new ACL object while trying to create a new page.", 259 JahiaException.PAGE_ERROR, 260 JahiaException.CRITICAL_SEVERITY); 261 } 262 break; 263 } 264 265 JahiaPageDefinition pageTemplate = null; 266 switch (pageType) { 267 case JahiaPageInfo.TYPE_DIRECT: 268 pageTemplate = mTemplateService.lookupPageTemplate( 269 pageTemplateID); 270 break; 271 272 case JahiaPageInfo.TYPE_LINK: 273 pageTemplate = linkedPage.getPageTemplate(jParam); 274 pageTemplateID = pageTemplate.getID(); 275 break; 276 } 277 linkedPage = null; 278 279 if ( (title == null) || ("".equals(title))) { 281 undefined_counter++; 282 title = "Undefined Page " + undefined_counter; 283 } 284 285 291 boolean newPage = true; 292 ContentPage contentPage = null; 293 JahiaPage page = null; 294 if (newPage) { 295 296 JahiaSite site = ServicesRegistry.getInstance() 297 .getJahiaSitesService().getSite(siteID); 298 302 int newVersionID = 0; 304 int newVersionStatus = VERSION_START_STATUS; 305 309 String languageCode = null; 310 if (jParam != null) { 311 languageCode = jParam.getEntryLoadRequest().getFirstLocale(true). 312 toString(); 313 } else { 314 languageCode = site.getLanguageSettingsAsLocales(true).get(0). 315 toString(); 316 } 317 318 JahiaPageInfo pageInfo = new JahiaPageInfo(pageID, siteID, parentID, 319 pageType, title, pageTemplateID, remoteURL, pageLinkID, creator, 320 dateOfCreation, counter, acl.getID(), newVersionID, 321 newVersionStatus, 322 languageCode); 323 Vector pageInfoVector = new Vector (); 325 pageInfoVector.add(pageInfo); 326 dateOfCreation = null; 327 if (pageInfo == null) { 328 throw new JahiaException("Could not create page.", 329 "Could not instanciate a new JahiaPageInfo object.", 330 JahiaException.PAGE_ERROR, 331 JahiaException.CRITICAL_SEVERITY); 332 } 333 334 if (!mPageDB.createPageInfo(pageInfo)) { 336 throw new JahiaException("Could not create page.", 337 "Could not insert the page info into the database", 338 JahiaException.PAGE_ERROR, 339 JahiaException.CRITICAL_SEVERITY); 340 } 341 342 contentPage = new ContentPage(pageID, pageInfoVector, acl); 344 page = 345 new JahiaPage(contentPage, pageTemplate, acl, 346 jParam.getEntryLoadRequest()); 347 acl = null; 348 if (page == null) { 349 throw new JahiaException("Could not create page.", 350 "Could not instanciate a new JahiaPage object.", 351 JahiaException.PAGE_ERROR, 352 JahiaException.CRITICAL_SEVERITY); 353 } 354 355 mPageInfosCache.put(new Integer (pageID), pageInfoVector); 357 pageInfo = null; 358 } 359 JahiaEvent theEvent = new JahiaEvent(this, jParam, page); 363 ServicesRegistry.getInstance().getJahiaEventService(). 364 fireAddPage(theEvent); 365 theEvent = null; 366 367 return page; 368 } 369 370 private void deleteAllPageContainerLists (JahiaPage thePage, 373 ParamBean jParams) 374 throws JahiaException { 375 ContentPage contentPage = lookupContentPage( 376 thePage.getID(), jParams.getEntryLoadRequest(), false); 377 Vector cListIDs = ServicesRegistry.getInstance() 378 .getJahiaContainersService() 379 .getContainerListIDsInPage(contentPage, 380 jParams.getEntryLoadRequest()); 381 for (int i = 0; i < cListIDs.size(); i++) { 382 int cListID = ( (Integer ) cListIDs.elementAt(i)).intValue(); 383 logger.debug("Deleting container list ID " + cListID); 384 ServicesRegistry.getInstance().getJahiaContainersService(). 385 deleteContainerList(cListID, jParams); 386 } 387 cListIDs = null; 388 } 389 390 private void deleteAllPageFields (JahiaPage thePage, ParamBean jParam) 393 throws JahiaException { 394 Vector fieldIDs = ServicesRegistry.getInstance().getJahiaFieldService(). 395 getNonContainerFieldIDsInPage(thePage.getID()); 396 for (int i = 0; i < fieldIDs.size(); i++) { 397 int fieldID = ( (Integer ) fieldIDs.elementAt(i)).intValue(); 398 ServicesRegistry.getInstance().getJahiaFieldService().deleteField( 399 fieldID, 400 jParam); 401 } 402 fieldIDs = null; 403 } 404 405 private void deleteLinksOnPage (JahiaPage thePage, ParamBean jParam) 408 throws JahiaException { 409 Vector links = getPagesPointingOnPage(thePage.getID(), jParam); 410 for (int i = 0; i < links.size(); i++) { 411 JahiaPage theLink = (JahiaPage) links.elementAt(i); 412 int fieldID = mUtilsDB.getPageFieldID(theLink.getID()); 413 if (fieldID != -1) { 414 ServicesRegistry.getInstance().getJahiaFieldService(). 415 deleteField(fieldID, 416 jParam); 417 } 418 } 419 links = null; 420 } 421 422 public synchronized void deletePage (JahiaPage theVictim, ParamBean jParam) 424 throws JahiaException, JahiaOperationNotAllowedException { 425 checkService(); 427 428 if (theVictim == null) { 430 return; 431 } 432 433 int currentPageID = -1; 434 if (jParam != null) { 435 currentPageID = jParam.getPageID(); 436 } 437 438 if (jParam.isInAdminMode() || (theVictim.getID() != currentPageID)) { 440 441 mPageInfosCache.remove(new Integer (theVictim.getID())); 443 mVersioningPageInfosCache.remove(new Integer (theVictim.getID())); 444 445 if (theVictim.getPageType() == JahiaPage.TYPE_DIRECT) { 447 deleteAllPageFields(theVictim, jParam); 449 450 deleteAllPageContainerLists(theVictim, jParam); 452 453 deleteLinksOnPage(theVictim, jParam); 455 } 456 457 if (theVictim.getPageType() != JahiaPage.TYPE_LINK) { 460 JahiaBaseACL acl = theVictim.getACL(); 462 acl.delete(); 463 acl = null; 464 } 465 466 Vector files = ServicesRegistry.getInstance(). 468 getJahiaFilemanagerService(). 469 getFilesByPage(theVictim.getJahiaID(), 470 theVictim.getID(), false); 471 JahiaFile f = null; 472 for (int i = 0; i < files.size(); i++) { 473 f = (JahiaFile) files.get(i); 474 ServicesRegistry.getInstance(). 475 getJahiaFilemanagerService(). 476 deleteFileDB(f.getFileID()); 477 ServicesRegistry.getInstance(). 478 getJahiaFilemanagerService(). 479 deleteFile(f); 480 } 481 482 485 486 Vector pageInfoVector = theVictim.getContentPage().getPageInfos(true); 489 Enumeration pageInfoEnum = pageInfoVector.elements(); 490 while (pageInfoEnum.hasMoreElements()) { 491 JahiaPageInfo curPageInfo = (JahiaPageInfo) pageInfoEnum. 492 nextElement(); 493 mPageDB.deletePageInfo(curPageInfo); 494 } 495 496 theVictim = null; 498 } else { 499 throw new JahiaOperationNotAllowedException(theVictim.getID(), 500 "It is not allowed to delete the current page. Delete it from its parent page."); 501 } 502 503 } 504 505 512 public int findPageIDFromLevel (int pageID, int levelNb, ParamBean jParams) 513 throws JahiaException { 514 int levelCount = 0; 515 int parentID = -1; 516 ContentPage thePage = lookupContentPage(pageID, true); 517 518 if (levelNb != -1) { 519 while (levelCount < levelNb) { 520 parentID = thePage.getParentID(jParams.getEntryLoadRequest()); 521 if (parentID > 0) { 522 thePage = 523 lookupContentPage(parentID, jParams.getEntryLoadRequest(), true); 524 } else { 525 return -1; 526 } 527 levelCount++; 528 } 529 } else { 530 while (parentID > 0) { 531 parentID = thePage.getParentID(jParams.getEntryLoadRequest()); 532 if (parentID > 0) { 533 thePage = lookupContentPage(parentID, true); 534 } 535 } 536 } 537 538 return thePage.getID(); 539 } 540 541 549 public Enumeration getAllPages (int siteID, int loadFlag, ParamBean jParam, 550 JahiaUser user) 551 throws JahiaException { 552 checkService(); 554 555 Vector result = new Vector (); 556 557 if (user != null) { 559 560 Vector allPages = getPageIDsInSite(siteID); 562 563 for (int i = 0; i < allPages.size(); i++) { 566 try { 567 Integer id = (Integer ) allPages.get(i); 568 if (id.intValue() > 0) { 569 JahiaPage page = lookupPage(id.intValue(), 570 jParam.getEntryLoadRequest(), 571 jParam.getOperationMode(), 572 jParam.getUser(), false); 573 574 if (page != null) { 575 if (authorizePageLoad(page, loadFlag, user)) { 576 result.add(page); 577 } 578 } 579 } 580 id = null; 581 } catch (JahiaPageNotFoundException ex) { 582 } catch (JahiaTemplateNotFoundException ex) { 585 } catch (JahiaException ex) { 588 } 591 } 592 allPages = null; 593 } 594 return result.elements(); 595 } 596 597 602 public static synchronized JahiaPageBaseService getInstance () 603 throws JahiaException { 604 if (instance == null) { 605 instance = new JahiaPageBaseService(); 606 } 607 return instance; 608 } 609 610 616 public Vector getAllSiteIDs () 617 throws JahiaException { 618 checkService(); 620 621 Vector sites = new Vector (); 622 sites.add(new Integer (1)); return sites; 624 } 625 626 631 public Vector getPageIDsInSite (int siteID) 632 throws JahiaException { 633 checkService(); 635 636 return mUtilsDB.getPageIDsInSite(siteID); 637 } 638 639 public Vector getPageIDsInSite (int siteID, int linkType) 641 throws JahiaException { 642 checkService(); 644 645 return mUtilsDB.getPageIDsInSite(siteID, linkType); 646 } 647 648 public Vector getPageIDsWithTemplate (int templateID) 650 throws JahiaException { 651 checkService(); 653 654 return mUtilsDB.getPageIDsWithTemplate(templateID); 655 } 656 657 667 public int getPageFieldID (int pageID) 668 throws JahiaException { 669 checkService(); 670 return mUtilsDB.getPageFieldID(pageID); 671 } 672 673 681 public int getActivePageFieldID (int pageID) 682 throws JahiaException { 683 checkService(); 684 return mUtilsDB.getActivePageFieldID(pageID); 685 } 686 687 695 public int getStagedPageFieldID (int pageID) 696 throws JahiaException { 697 checkService(); 698 return mUtilsDB.getStagedPageFieldID(pageID); 699 } 700 701 709 public Set getStagingPageFieldIDsInPage (int pageID) 710 throws JahiaException { 711 return mUtilsDB.getStagingPageFieldIDsInPage(pageID); 712 } 713 714 722 public Vector getStagingAndActivePageFieldIDs (int pageID) 723 throws JahiaException { 724 return mUtilsDB.getStagingAndActivePageFieldIDs(pageID); 725 } 726 727 public Vector getPageChilds (int pageID, int loadFlag, 729 EntryLoadRequest loadRequest) 730 throws JahiaException { 731 732 ContentPage contentPage = lookupContentPage(pageID, true); 734 JahiaUser user = ServicesRegistry.getInstance(). 735 getJahiaUserManagerService() 736 .lookupUser(contentPage.getJahiaID(), "guest"); 737 ParamBean jParams = Jahia.getThreadParamBean(); 738 if ( jParams != null ){ 739 user = jParams.getUser(); 740 } 741 742 return getPageChilds(pageID, loadFlag, user, loadRequest); 743 } 744 745 public Vector getPageChilds (int pageID, int loadFlag, ParamBean jParam) 746 throws JahiaException { 747 748 return getPageChilds(pageID, loadFlag, jParam.getUser(), jParam); 749 } 750 751 public Vector getPageChilds (int pageID, int loadFlag, JahiaUser user) 752 throws JahiaException { 753 ParamBean jParams = Jahia.getThreadParamBean(); 756 EntryLoadRequest loadRequest = null; 757 if ( jParams != null ){ 758 loadRequest = jParams.getEntryLoadRequest(); 759 } 760 return getPageChilds(pageID, loadFlag, user,loadRequest); 761 } 762 763 public Vector getPageChilds (int pageID, int loadFlag, JahiaUser user, 764 EntryLoadRequest loadRequest) 765 throws JahiaException { 766 767 checkService(); 769 770 Vector childs = new Vector (); 771 772 boolean directPageOnly = (( loadFlag & ( PageLoadFlags.ALL | 773 PageLoadFlags.INTERNAL | 774 PageLoadFlags.JAHIA | 775 PageLoadFlags.LINKS | 776 PageLoadFlags.URL ) )==0 ); 777 778 Vector contentPageChilds = 779 getContentPageChilds(pageID,user, 780 (ContentPage.STAGING_PAGE_INFOS | ContentPage.ACTIVE_PAGE_INFOS), 781 ContentObject.SHARED_LANGUAGE,directPageOnly); 782 783 int size = contentPageChilds.size(); 784 for (int i = 0; i < size; i++) { 786 ContentPage contentPage = (ContentPage) contentPageChilds.get(i); 787 788 try { 790 JahiaPage page = lookupPage(contentPage.getID(), loadRequest, user); 791 if ( (page != null) && (user != null)) { 794 if (authorizePageLoad(page, loadFlag, user)) { 795 childs.add(page); 796 } 797 } 798 } catch (JahiaPageNotFoundException ex) { 799 } catch (JahiaTemplateNotFoundException ex) { 802 } 805 } 806 807 contentPageChilds = null; 808 809 sortPages(childs); 811 return childs; 812 } 813 814 private Vector getPageChilds (int pageID, int loadFlag, JahiaUser user, 815 ParamBean jParam) 816 throws JahiaException { 817 if (jParam != null) { 818 return getPageChilds(pageID, loadFlag, user, 819 jParam.getEntryLoadRequest()); 820 } else { 821 logger.debug( 822 "FIXME : Method called with null ParamBean, returning null... "); 823 return null; 824 } 825 826 } 827 828 840 public Vector getDirectContentPageChilds (int pageID, JahiaUser user, 841 int pageInfosFlag, 842 String languageCode) 843 throws JahiaException { 844 checkService(); 846 Vector childs = new Vector (); 847 Vector childIDs = null; 848 childIDs = mUtilsDB.getPageChildIDs(pageID); 852 856 EntryLoadRequest loadRequest = null; 857 ArrayList langs = new ArrayList (); 858 langs.add( 859 org.jahia.utils.LanguageCodeConverters.languageCodeToLocale( 860 ContentField.SHARED_LANGUAGE)); 861 if (languageCode != null) { 862 langs.add( 863 org.jahia.utils.LanguageCodeConverters.languageCodeToLocale( 864 languageCode)); 865 } 866 if ( (pageInfosFlag & ContentPage.STAGING_PAGE_INFOS) != 0) { 867 loadRequest = 868 new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, 869 langs); 870 loadRequest.setWithMarkedForDeletion(true); 871 } else if ( (pageInfosFlag & ContentPage.ACTIVE_PAGE_INFOS) != 0) { 872 loadRequest = 873 new EntryLoadRequest(EntryLoadRequest.ACTIVE_WORKFLOW_STATE, 0, 874 langs); 875 loadRequest.setWithMarkedForDeletion(true); 876 } else if ( (pageInfosFlag & ContentPage.ARCHIVED_PAGE_INFOS) != 0) { 877 loadRequest = 878 new EntryLoadRequest(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 879 0, langs); 880 loadRequest.setWithDeleted(true); 881 loadRequest.setWithMarkedForDeletion(true); 882 } 883 884 EntryLoadRequest activeLoadRequest = 885 new EntryLoadRequest(EntryLoadRequest.ACTIVE_WORKFLOW_STATE, 0, 886 langs); 887 888 for (int i = 0; i < childIDs.size(); i++) { 890 Integer id = (Integer ) childIDs.get(i); 891 try { 893 ContentPage pageContent = ServicesRegistry.getInstance(). 894 getJahiaPageService(). 895 lookupContentPage(id.intValue(), 896 loadRequest, 897 false); 898 if ( (pageContent != null) && (user != null)) { 899 if (pageContent.getPageType(loadRequest) == 900 PageInfoInterface.TYPE_DIRECT && 901 pageContent.checkReadAccess(user)) { 902 if (pageID != pageContent.getParentID(activeLoadRequest)) { 903 continue; 904 } 905 if (pageInfosFlag == ContentPage.ARCHIVED_PAGE_INFOS) { 906 childs.add(pageContent); 907 } else { 908 JahiaPageInfo pageInfo = null; 909 if (languageCode != null && 910 pageContent.hasEntries(pageInfosFlag, 911 languageCode)) { 912 pageInfo = 913 pageContent.getPageInfoVersion(loadRequest, false, 914 false); 915 } else if (pageContent.hasEntries(pageInfosFlag)) { 916 pageInfo = 917 pageContent.getPageInfoVersion(loadRequest, false, 918 true); 919 } 920 if (pageInfo != null) { 921 childs.add(pageContent); 922 } 923 } 924 } 925 } 926 } catch (JahiaPageNotFoundException ex) { 927 } catch (JahiaTemplateNotFoundException ex) { 930 } 933 } 934 childIDs = null; 935 return childs; 936 } 937 938 971 public Vector getContentPageChilds (int pageID, 972 JahiaUser user, 973 int pageInfosFlag, 974 String languageCode, 975 int versionId, 976 boolean directPageOnly) 977 throws JahiaException { 978 checkService(); 980 Vector childs = new Vector (); 981 Vector childIDs = new Vector (); 982 983 if ( ((pageInfosFlag & ContentPage.STAGING_PAGE_INFOS) != 0) 984 && ((pageInfosFlag & ContentPage.ACTIVE_PAGE_INFOS) != 0) ) { 985 childIDs = mUtilsDB.getStagingPageChildIDs(pageID); 986 Vector activeChildIDs = mUtilsDB.getActivePageChildIDs(pageID); 987 int size = activeChildIDs.size(); 989 Integer I = null; 990 for ( int i=0; i<size; i++ ){ 991 I = (Integer )activeChildIDs.get(i); 992 if ( !childIDs.contains(I) ){ 993 int size2 = childIDs.size(); 994 Integer J = null; 995 int pos = -1; 996 boolean bigger = false; 997 for ( int j=0; j<size2; j++ ){ 998 J = (Integer )childIDs.get(j); 999 bigger = false; 1000 if ( I.intValue() > J.intValue() ){ 1001 pos = j; 1002 bigger = true; 1003 } 1004 if ( pos != -1 && !bigger ){ 1005 break; 1006 } 1007 } 1008 if ( pos != -1 ){ 1009 childIDs.add(pos+1,I); 1010 } else { 1011 childIDs.add(0,I); 1012 } 1013 } 1014 } 1015 } else if ( ((pageInfosFlag & ContentPage.ARCHIVED_PAGE_INFOS) != 0) 1016 && ((pageInfosFlag & ContentPage.STAGING_PAGE_INFOS) != 0) ) { 1017 childIDs = mUtilsDB.getVersioningPageChildIDs(pageID, versionId); 1018 Vector stagingChildIDs = mUtilsDB.getStagingPageChildIDs(pageID); 1019 int size = stagingChildIDs.size(); 1021 Integer I = null; 1022 for ( int i=0; i<size; i++ ){ 1023 I = (Integer )stagingChildIDs.get(i); 1024 if ( !childIDs.contains(I) ){ 1025 int size2 = childIDs.size(); 1026 Integer J = null; 1027 int pos = -1; 1028 boolean bigger = false; 1029 for ( int j=0; j<size2; j++ ){ 1030 J = (Integer )childIDs.get(j); 1031 bigger = false; 1032 if ( I.intValue() > J.intValue() ){ 1033 pos = j; 1034 bigger = true; 1035 } 1036 if ( pos != -1 && !bigger ){ 1037 break; 1038 } 1039 } 1040 if ( pos != -1 ){ 1041 childIDs.add(pos+1,I); 1042 } else { 1043 childIDs.add(0,I); 1044 } 1045 } 1046 } 1047 } else if ( (pageInfosFlag & ContentPage.STAGING_PAGE_INFOS) != 0) { 1048 childIDs = mUtilsDB.getStagingPageChildIDs(pageID); 1049 } else if ( (pageInfosFlag & ContentPage.ACTIVE_PAGE_INFOS) != 0) { 1050 childIDs = mUtilsDB.getActivePageChildIDs(pageID); 1051 } else if ( (pageInfosFlag & ContentPage.ARCHIVED_PAGE_INFOS) != 0) { 1052 childIDs = mUtilsDB.getVersioningPageChildIDs(pageID,versionId); 1053 } 1054 1055 EntryLoadRequest loadRequest = null; 1056 ArrayList langs = new ArrayList (); 1057 langs.add( 1058 org.jahia.utils.LanguageCodeConverters.languageCodeToLocale( 1059 ContentField.SHARED_LANGUAGE)); 1060 if (languageCode != null) { 1061 langs.add( 1062 org.jahia.utils.LanguageCodeConverters.languageCodeToLocale( 1063 languageCode)); 1064 } 1065 if ( (pageInfosFlag & ContentPage.STAGING_PAGE_INFOS) != 0) { 1066 loadRequest = 1067 new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, 1068 langs); 1069 loadRequest.setWithMarkedForDeletion(true); 1070 } else if ( (pageInfosFlag & ContentPage.ACTIVE_PAGE_INFOS) != 0) { 1071 loadRequest = 1072 new EntryLoadRequest(EntryLoadRequest.ACTIVE_WORKFLOW_STATE, 0, 1073 langs); 1074 loadRequest.setWithMarkedForDeletion(true); 1075 } else if ( (pageInfosFlag & ContentPage.ARCHIVED_PAGE_INFOS) != 0) { 1076 loadRequest = 1077 new EntryLoadRequest(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 1078 0, langs); 1079 loadRequest.setWithDeleted(true); 1080 loadRequest.setWithMarkedForDeletion(true); 1081 } 1082 1083 1093 1094 for (int i = 0; i < childIDs.size(); i++) { 1096 Integer id = (Integer ) childIDs.get(i); 1097 try { 1099 1100 ContentPage pageContent = ContentPage.getPage(id.intValue()); 1101 1102 if ( (pageInfosFlag == ContentPage.ACTIVE_PAGE_INFOS) ){ 1104 if ( pageID != pageContent.getParentID(loadRequest) ){ 1105 continue; 1106 } 1107 } 1108 1109 if ( (pageContent != null) && (user != null)) { 1110 if ( (!directPageOnly || 1111 (directPageOnly && pageContent.getPageType( 1112 loadRequest) == PageInfoInterface.TYPE_DIRECT)) && 1113 pageContent.checkReadAccess(user)) { 1114 childs.add(pageContent); 1115 } 1116 } 1117 } catch (JahiaPageNotFoundException ex) { 1118 } catch (JahiaTemplateNotFoundException ex) { 1121 } 1124 } 1125 childIDs = null; 1126 return childs; 1127 } 1128 1129 1144 public Vector getContentPageChilds (int pageID, JahiaUser user, 1145 int pageInfosFlag, 1146 String languageCode, 1147 boolean directPageOnly) 1148 throws JahiaException { 1149 checkService(); 1151 Vector childs = new Vector (); 1152 Vector childIDs = null; 1153 childIDs = mUtilsDB.getPageChildIDs(pageID); 1157 1161 EntryLoadRequest loadRequest = null; 1162 ArrayList langs = new ArrayList (); 1163 langs.add( 1164 org.jahia.utils.LanguageCodeConverters.languageCodeToLocale( 1165 ContentField.SHARED_LANGUAGE)); 1166 if (languageCode != null) { 1167 langs.add( 1168 org.jahia.utils.LanguageCodeConverters.languageCodeToLocale( 1169 languageCode)); 1170 } 1171 if ( (pageInfosFlag & ContentPage.STAGING_PAGE_INFOS) != 0) { 1172 loadRequest = 1173 new EntryLoadRequest(EntryLoadRequest.STAGING_WORKFLOW_STATE, 0, 1174 langs); 1175 loadRequest.setWithMarkedForDeletion(true); 1176 } else if ( (pageInfosFlag & ContentPage.ACTIVE_PAGE_INFOS) != 0) { 1177 loadRequest = 1178 new EntryLoadRequest(EntryLoadRequest.ACTIVE_WORKFLOW_STATE, 0, 1179 langs); 1180 loadRequest.setWithMarkedForDeletion(true); 1181 } else if ( (pageInfosFlag & ContentPage.ARCHIVED_PAGE_INFOS) != 0) { 1182 loadRequest = 1183 new EntryLoadRequest(EntryLoadRequest.VERSIONED_WORKFLOW_STATE, 1184 0, langs); 1185 loadRequest.setWithDeleted(true); 1186 loadRequest.setWithMarkedForDeletion(true); 1187 } 1188 1189 for (int i = 0; i < childIDs.size(); i++) { 1191 Integer id = (Integer ) childIDs.get(i); 1192 try { 1194 1195 1199 ContentPage pageContent = ContentPage.getPage(id.intValue()); 1200 1201 if ( (pageInfosFlag == ContentPage.ACTIVE_PAGE_INFOS) ){ 1203 if ( pageID != pageContent.getParentID(loadRequest) ){ 1204 continue; 1205 } 1206 } 1207 1208 if ( (pageContent != null) && (user != null)) { 1209 if ( (!directPageOnly || 1210 (directPageOnly && pageContent.getPageType( 1211 loadRequest) == PageInfoInterface.TYPE_DIRECT)) && 1212 pageContent.checkReadAccess(user)) { 1213 if (pageInfosFlag == ContentPage.ARCHIVED_PAGE_INFOS) { 1214 childs.add(pageContent); 1215 } else { 1216 JahiaPageInfo pageInfo = null; 1217 if (languageCode != null && 1218 pageContent.hasEntries(pageInfosFlag, 1219 languageCode)) { 1220 pageInfo = 1221 pageContent.getPageInfoVersion(loadRequest, false, 1222 false); 1223 } else if (pageContent.hasEntries(pageInfosFlag)) { 1224 pageInfo = 1225 pageContent.getPageInfoVersion(loadRequest, false, 1226 true); 1227 } 1228 if (pageInfo != null) { 1229 childs.add(pageContent); 1230 } 1231 } 1232 } 1233 } 1234 } catch (JahiaPageNotFoundException ex) { 1235 } catch (JahiaTemplateNotFoundException ex) { 1238 } 1241 } 1242 childIDs = null; 1243 return childs; 1244 } 1245 1246 1256 public Vector getContentPagePath (int pageID, EntryLoadRequest loadRequest, 1257 String opMode, JahiaUser user) 1258 throws JahiaException { 1259 checkService(); 1261 1262 Vector path = new Vector (); 1263 ContentPage contentPage = lookupContentPage (pageID, true); 1264 if (contentPage != null) { 1265 do { 1266 path.insertElementAt(contentPage, 0); 1267 EntryLoadRequest newLoadRequest = loadRequest; 1272 if (loadRequest != null && loadRequest.isCurrent () && !contentPage.hasActiveEntries ()) { 1273 newLoadRequest = 1274 new EntryLoadRequest (EntryLoadRequest.STAGING_WORKFLOW_STATE, 1275 0, loadRequest.getLocales ()); 1276 newLoadRequest.setWithDeleted (loadRequest.isWithDeleted ()); 1277 newLoadRequest.setWithMarkedForDeletion (loadRequest.isWithMarkedForDeletion ()); 1278 } 1279 int parentId = contentPage.getParentID(newLoadRequest); 1280 contentPage = parentId > 0 ? lookupContentPage (parentId, true) : null; 1281 1282 if (contentPage != null && contentPage.getID() == pageID) { contentPage = null; 1284 } 1285 } while (contentPage != null); 1286 } 1287 return path; 1288 } 1289 1290 1301 public Vector getPagePath (int pageID, EntryLoadRequest loadRequest, 1302 String opMode, 1303 JahiaUser user) 1304 throws JahiaException { 1305 checkService(); 1307 1308 Vector path = new Vector (); 1309 JahiaPage thePage; 1310 1311 thePage = lookupPage(pageID, loadRequest, opMode, user, true); 1312 if (thePage != null) { 1313 path.add(thePage); 1314 while (thePage.getParentID() > 0) { 1315 thePage = lookupPage(thePage.getParentID(), loadRequest, opMode, 1316 user, true); 1317 if (thePage != null && thePage.getID() != pageID) { path.insertElementAt(thePage, 0); 1319 } else { 1320 return path; 1321 } 1322 } 1323 } 1324 thePage = null; 1325 return path; 1326 } 1327 1328 1336 public Vector getContentPagePath (int pageID, ParamBean jParams) 1337 throws JahiaException { 1338 if (jParams != null) { 1339 return getContentPagePath(pageID, jParams.getEntryLoadRequest(), 1340 jParams.getOperationMode(), 1341 jParams.getUser()); 1342 } else { 1343 logger.debug( 1344 "FIXME : Method called with null ParamBean, returning null"); 1345 return null; 1346 } 1347 } 1348 1349 1356 public Vector getPagePath (int pageID, ParamBean jParams) 1357 throws JahiaException { 1358 if (jParams != null) { 1359 return getPagePath(pageID, jParams.getEntryLoadRequest(), 1360 jParams.getOperationMode(), jParams.getUser()); 1361 } else { 1362 logger.debug( 1363 "FIXME : Method called with null ParamBean, returning null"); 1364 return null; 1365 } 1366 } 1367 1368 public Vector getPagesPointingOnPage (int pageID, ParamBean jParam) 1369 throws JahiaException { 1370 return getPagesPointingOnPage(pageID, jParam.getEntryLoadRequest()); 1371 } 1372 1373 public Vector getPagesPointingOnPage (int pageID, 1374 EntryLoadRequest loadRequest) 1375 throws JahiaException { 1376 checkService(); 1378 1379 Vector pages = new Vector (); 1380 Vector pageIDs = mUtilsDB.getPageIDsPointingOnPage(pageID, loadRequest); 1381 1382 for (int i = 0; i < pageIDs.size(); i++) { 1383 int pID = ( (Integer ) pageIDs.elementAt(i)).intValue(); 1385 1386 try { 1388 JahiaPage aPage = lookupPage(pID, loadRequest); 1389 1390 if (aPage != null) { 1392 if (aPage.getPageLinkID() != pageID) { 1393 logger.debug("Page link " + pID + " no longer points to page " + pageID); 1396 } else { 1397 pages.add(aPage); 1398 } 1399 } 1400 aPage = null; 1401 } catch (JahiaPageNotFoundException ex) { 1402 logger.debug("Not returning page " + pID + 1403 " for referring pages, error:", ex); 1404 } catch (JahiaTemplateNotFoundException ex) { 1405 logger.debug("Not returning page " + pID + 1406 " for referring pages, error:", ex); 1407 } 1408 } 1409 1410 pageIDs = null; 1411 1412 return pages; 1413 } 1414 1415 public Vector getPageSubTree (int pageID, int loadFlag, ParamBean jParam) 1416 throws JahiaException { 1417 checkService(); 1419 1420 Vector subTree = getPageChilds(pageID, loadFlag, jParam); 1421 Vector results = new Vector (subTree); 1422 for (int i = 0; i < subTree.size(); i++) { 1423 JahiaPage aPage = (JahiaPage) subTree.elementAt(i); 1424 results.addAll(results.size(),getPageSubTree(aPage.getID(), loadFlag, jParam)); 1425 } 1426 1427 return results; 1428 } 1429 1430 public synchronized void init (SettingsBean jSettings) 1431 throws JahiaInitializationException { 1432 logger.debug("** Initializing the Page Service ..."); 1433 if (!isInitialized()) { 1435 logger.debug(" - Instanciate the page cache ..."); 1437 1438 mPageInfosCache = CacheFactory.createCache(PAGE_INFO_CACHE); 1439 1440 mVersioningPageInfosCache = CacheFactory.createCache( 1441 VERSIONING_PAGE_INFO_CACHE); 1442 1443 1446 mContentPageCache = CacheFactory.createCache( 1447 CONTENT_PAGE_CACHE); 1448 1449 logger.debug(" - Instanciate the database page tools ..."); 1451 mPageDB = JahiaPagesDB.getInstance(); 1452 1453 logger.debug(" - Instanciate the database page utility tools ..."); 1455 mUtilsDB = JahiaPageUtilsDB.getInstance(); 1456 1457 logger.debug(" - Get the Page Template Service instance ..."); 1459 ServicesRegistry services = ServicesRegistry.getInstance(); 1460 if (services != null) { 1461 mTemplateService = services.getJahiaPageTemplateService(); 1462 } 1463 1464 if ( (mPageInfosCache != null) && 1465 (mVersioningPageInfosCache != null) && 1466 (mPageDB != null) && 1467 (mUtilsDB != null) && 1468 (mTemplateService != null)) { 1469 mIsServiceInitialized = true; 1470 logger.debug(" ** Page Service successfully initialized!"); 1471 1472 try { 1473 mPageDB.preloadingPageInfos(mPageInfosCache, 1475 mVersioningPageInfosCache); 1476 1477 ArrayList pageIDs = mUtilsDB.getFirstNPageIDs(jSettings.getPreloadCountForPageProperties()); 1478 PagePropertyDB.getInstance().preloadCacheByPageID(pageIDs); 1479 } catch (JahiaException je) { 1480 throw new JahiaInitializationException("Error while preloading pages", je); 1481 } 1482 1483 } else { 1484 mPageInfosCache = null; 1486 mVersioningPageInfosCache = null; 1487 mPageDB = null; 1488 mUtilsDB = null; 1489 mTemplateService = null; 1490 1491 throw new JahiaInitializationException("Page Service initialization error."); 1493 } 1494 } 1495 } 1496 1497 public JahiaPage lookupPageWhitoutTemplates (int pageID) 1498 throws JahiaException, 1499 JahiaPageNotFoundException, 1500 JahiaTemplateNotFoundException { 1501 return lookupPage(pageID, EntryLoadRequest.CURRENT, false); 1502 } 1503 1504 1511 public JahiaPage lookupPage (int pageID) 1512 throws JahiaException, 1513 JahiaPageNotFoundException, 1514 JahiaTemplateNotFoundException { 1515 return lookupPage(pageID, EntryLoadRequest.CURRENT, true); 1516 } 1517 1518 1527 public JahiaPage lookupPage (int pageID, ParamBean jParam) 1528 throws JahiaException, 1529 JahiaPageNotFoundException, 1530 JahiaTemplateNotFoundException { 1531 return lookupPage(pageID, jParam, true); 1532 } 1533 1534 1546 public JahiaPage lookupPage (int pageID, EntryLoadRequest loadRequest, 1547 boolean withTemplates) 1548 throws JahiaException, 1549 JahiaPageNotFoundException, 1550 JahiaTemplateNotFoundException { 1551 1552 JahiaUser user = null; 1553 ParamBean jParams = Jahia.getThreadParamBean(); 1554 if ( jParams != null ){ 1555 user = jParams.getUser(); 1556 } 1557 return lookupPage(pageID, loadRequest, user, withTemplates); 1558 } 1559 1560 1571 public JahiaPage lookupPage (int pageID, EntryLoadRequest loadRequest, 1572 JahiaUser user, boolean withTemplates) 1573 throws JahiaException, 1574 JahiaPageNotFoundException, 1575 JahiaTemplateNotFoundException { 1576 String operationMode = null; 1577 if (loadRequest.getWorkflowState() == 1578 EntryLoadRequest.ACTIVE_WORKFLOW_STATE) { 1579 operationMode = ParamBean.NORMAL; 1580 } 1581 if ( (loadRequest.getWorkflowState() > 1582 EntryLoadRequest.ACTIVE_WORKFLOW_STATE) 1583 || (loadRequest.getWorkflowState() < EntryLoadRequest.VERSIONED_WORKFLOW_STATE) ) { 1584 operationMode = ParamBean.EDIT; 1585 } 1586 return lookupPage(pageID, loadRequest, operationMode, user, 1587 withTemplates); 1588 } 1589 1590 1600 public JahiaPage lookupPage (int pageID, EntryLoadRequest loadRequest) 1601 throws JahiaException, 1602 JahiaPageNotFoundException, 1603 JahiaTemplateNotFoundException { 1604 return lookupPage(pageID, loadRequest, true); 1605 } 1606 1607 1617 public JahiaPage lookupPage (int pageID, 1618 EntryLoadRequest loadRequest, 1619 JahiaUser user) 1620 throws JahiaException, 1621 JahiaPageNotFoundException, 1622 JahiaTemplateNotFoundException { 1623 return lookupPage(pageID, loadRequest, user, true); 1624 } 1625 1626 1639 public ContentPage lookupContentPage (int pageID, 1640 boolean withTemplates) 1641 throws JahiaException, 1642 JahiaPageNotFoundException, 1643 JahiaTemplateNotFoundException { 1644 return lookupContentPage(pageID, EntryLoadRequest.CURRENT, 1645 withTemplates, false); 1646 } 1647 1648 1662 public ContentPage lookupContentPage (int pageID, 1663 boolean withTemplates, 1664 boolean forceLoadFromDB) 1665 throws JahiaException, 1666 JahiaPageNotFoundException, 1667 JahiaTemplateNotFoundException { 1668 return lookupContentPage(pageID, EntryLoadRequest.CURRENT, 1669 withTemplates, forceLoadFromDB); 1670 } 1671 1672 1673 1689 public ContentPage lookupContentPage (int pageID, 1690 EntryLoadRequest loadRequest, 1691 boolean withTemplates) 1692 throws JahiaException, 1693 JahiaPageNotFoundException, 1694 JahiaTemplateNotFoundException { 1695 return lookupContentPage(pageID, loadRequest, 1696 withTemplates, false); 1697 } 1698 1699 1716 public ContentPage lookupContentPage (int pageID, 1717 EntryLoadRequest loadRequest, 1718 boolean withTemplates, 1719 boolean forceLoadFromDB) 1720 throws JahiaException, 1721 JahiaPageNotFoundException, 1722 JahiaTemplateNotFoundException { 1723 ContentPage contentPage = null; 1725 1726 checkService(); 1728 if (!forceLoadFromDB) { 1729 contentPage = (ContentPage) mContentPageCache.get(new 1730 Integer (pageID)); 1731 if (contentPage != null) { 1732 return contentPage; 1733 } 1734 } 1735 1736 Vector activePageInfoVector = lookupPageInfos(pageID, 1738 EntryLoadRequest.CURRENT); 1739 Vector archivePageInfoVector = lookupPageInfos(pageID, 1740 EntryLoadRequest.VERSIONED); 1741 if (archivePageInfoVector == null) { 1742 archivePageInfoVector = new Vector (); 1743 } 1744 1745 if (activePageInfoVector == null) { 1746 throw new JahiaPageNotFoundException(pageID); 1747 } 1748 1749 if (activePageInfoVector.size() == 0 && 1750 archivePageInfoVector.size() == 0) { 1751 throw new JahiaPageNotFoundException(pageID); 1752 } 1753 1754 Vector pageInfoVector = new Vector (); 1755 pageInfoVector.addAll(activePageInfoVector); 1756 pageInfoVector.addAll(archivePageInfoVector); 1757 1758 JahiaPageInfo sharedPageInfo = (JahiaPageInfo) pageInfoVector.elementAt( 1759 0); 1760 1761 1769 if (withTemplates) { if ( (sharedPageInfo.getPageType() == JahiaPageInfo.TYPE_DIRECT) || 1774 (sharedPageInfo.getPageType() == JahiaPageInfo.TYPE_LINK)) { 1775 mTemplateService.lookupPageTemplate( 1776 sharedPageInfo.getPageTemplateID()); 1777 } 1778 } 1779 1780 JahiaBaseACL acl = new JahiaBaseACL(sharedPageInfo.getAclID()); 1783 if (acl == null) { 1784 throw new JahiaException("Page ACL not found.", 1785 "The ACL [" + sharedPageInfo.getAclID() + 1786 "] could not be found in the" + 1787 " database for page [" + pageID + "]", 1788 JahiaException.PAGE_ERROR, 1789 JahiaException.ERROR_SEVERITY); 1790 } 1791 1792 contentPage = new ContentPage(pageID, pageInfoVector, acl); 1794 mContentPageCache.put(new Integer (pageID), contentPage); 1795 return contentPage; 1796 } 1797 1798 public JahiaPage lookupPage (int pageID, EntryLoadRequest loadRequest, 1801 String operationMode, JahiaUser user, 1802 boolean withTemplates) 1803 throws JahiaException, 1804 JahiaPageNotFoundException, 1805 JahiaTemplateNotFoundException { 1806 1807 ContentPage contentPage = lookupContentPage(pageID, withTemplates); 1808 JahiaPage page = null; 1810 if (contentPage != null) { 1811 page = contentPage.getPage(loadRequest, operationMode, user); 1812 } 1813 1814 return page; 1815 } 1816 1817 public JahiaPage lookupPage (int pageID, ParamBean jParam, 1818 boolean withTemplates) 1819 throws JahiaException, 1820 JahiaPageNotFoundException, 1821 JahiaTemplateNotFoundException { 1822 if (jParam != null) { 1823 return lookupPage(pageID, jParam.getEntryLoadRequest(), 1824 jParam.getOperationMode(), jParam.getUser(), 1825 withTemplates); 1826 } else { 1827 logger.debug( 1828 "FIXME : Method called with null ParamBean, returning null"); 1829 return null; 1830 } 1831 } 1832 1833 private Vector lookupPageInfos (int pageID, EntryLoadRequest loadRequest) 1839 throws JahiaException { 1840 Vector pageInfoVector = null; 1842 boolean versioning = ! (loadRequest.getWorkflowState() >= 1843 EntryLoadRequest.ACTIVE_WORKFLOW_STATE); 1844 if (!versioning) { 1845 pageInfoVector = (Vector ) mPageInfosCache.get(new Integer (pageID)); 1846 } else { 1847 pageInfoVector = (Vector ) mVersioningPageInfosCache.get(new Integer ( 1848 pageID)); 1849 } 1850 if (pageInfoVector == null) { 1851 pageInfoVector = mPageDB.loadPageInfos(pageID, loadRequest); 1854 if (pageInfoVector == null) { 1855 pageInfoVector = new Vector (); 1856 } 1857 if (!versioning) { 1858 mPageInfosCache.put(new Integer (pageID), pageInfoVector); 1859 } else { 1860 mVersioningPageInfosCache.put(new Integer (pageID), 1861 pageInfoVector); 1862 } 1863 } 1864 return pageInfoVector; 1865 } 1866 1867 public synchronized void shutdown () { 1869 1878 if (isInitialized()) { 1879 mPageInfosCache.flush(); 1880 mVersioningPageInfosCache.flush(); 1881 mIsServiceInitialized = false; 1883 } 1884 } 1885 1886 private void sortPages (Vector pagesList) { 1889 JahiaPage pageA; 1890 JahiaPage pageB; 1891 1892 for (int i = 0; i < pagesList.size(); i++) { 1893 for (int j = i; j < pagesList.size(); j++) { 1894 pageA = (JahiaPage) pagesList.elementAt(i); 1895 pageB = (JahiaPage) pagesList.elementAt(j); 1896 if (pageA.getID() > pageB.getID()) { 1897 pagesList.setElementAt(pageB, i); 1898 pagesList.setElementAt(pageA, j); 1899 } 1900 } 1901 } 1902 pageA = null; 1903 pageB = null; 1904 } 1905 1906 1920 public synchronized JahiaPage clonePage (int newParentID, 1921 int newParentAclID, 1922 JahiaPage pageToClone, 1923 ParamBean jParam, 1924 boolean childrenCloned) 1925 throws JahiaException { 1926 if (pageToClone == null) { 1927 return null; 1928 } 1929 1930 checkService(); 1932 ServicesRegistry sReg = ServicesRegistry.getInstance(); 1933 1934 int pageToCloneID = pageToClone.getID(); 1936 Vector pageToCloneInfoVector = pageToClone.getContentPage(). 1937 getPageInfos(true); 1938 if (pageToCloneInfoVector == null) { 1939 throw new JahiaException("Could not clone page.", 1940 "Could not clone the page : page [" + 1941 pageToCloneID + "] not found.", 1942 JahiaException.PAGE_ERROR, 1943 JahiaException.ERROR_SEVERITY); 1944 } 1945 1946 1950 int pageID = mPageDB.getNextID(); 1952 1953 String dateOfCreation = new Long ( (new java.util.Date ()).getTime()). 1955 toString(); 1956 1957 JahiaBaseACL aclToClone = pageToClone.getACL(); 1959 if (aclToClone == null) { 1960 throw new JahiaException("Could not clone page.", 1961 "Could not get JahiaBaseACL object.", 1962 JahiaException.PAGE_ERROR, 1963 JahiaException.CRITICAL_SEVERITY); 1964 } 1965 JahiaBaseACL clonedACL = null; 1966 1967 clonedACL = (JahiaBaseACL) aclToClone.clone(); 1968 if (clonedACL == null) { 1969 throw new JahiaException("Could not clone page.", 1970 "Could not clone acl.", 1971 JahiaException.PAGE_ERROR, 1972 JahiaException.CRITICAL_SEVERITY); 1973 } 1974 1975 if (newParentAclID != -1) { 1976 clonedACL.setParentID(newParentAclID); 1977 } 1978 int pageAclID = clonedACL.getID(); 1979 1980 JahiaPageDefinition pageTemplate = pageToClone.getPageTemplate(); 1982 1983 Enumeration pageInfoEnum = pageToCloneInfoVector.elements(); 1984 Vector pageInfoVector = new Vector (); 1985 while (pageInfoEnum.hasMoreElements()) { 1986 1987 JahiaPageInfo pageToCloneInfo = (JahiaPageInfo) pageInfoEnum. 1988 nextElement(); 1989 1990 JahiaPageInfo pageInfo = pageToCloneInfo.clonePageInfo(clonedACL. 1992 getID(), 1993 newParentID, pageID, dateOfCreation); 1994 if (pageInfo == null) { 1995 throw new JahiaException("Could not clone page.", 1996 "Could not clone JahiaPageInfo object.", 1997 JahiaException.PAGE_ERROR, 1998 JahiaException.CRITICAL_SEVERITY); 1999 } 2000 2001 pageInfoVector.add(pageInfo); 2002 2003 if (!mPageDB.createPageInfo(pageInfo)) { 2005 throw new JahiaException("Could not clone page.", 2006 "Could not insert the page info into the database", 2007 JahiaException.PAGE_ERROR, 2008 JahiaException.CRITICAL_SEVERITY); 2009 } 2010 } 2011 2012 ContentPage contentPage = new ContentPage(pageID, pageInfoVector, 2014 clonedACL); 2015 JahiaPage page = new JahiaPage(contentPage, pageTemplate, clonedACL, 2016 jParam.getEntryLoadRequest()); 2017 if (page == null) { 2018 throw new JahiaException("Could not clone page.", 2019 "Could not instanciate a new JahiaPage object.", 2020 JahiaException.PAGE_ERROR, 2021 JahiaException.CRITICAL_SEVERITY); 2022 } 2023 2024 mPageInfosCache.put(new Integer (pageID), pageInfoVector); 2026 2027 JahiaEvent theEvent = new JahiaEvent(this, jParam, page); 2029 sReg.getJahiaEventService(). 2030 fireAddPage(theEvent); 2031 2032 ContentPage contentPageToClone = lookupContentPage(pageToClone.getID(), 2034 jParam.getEntryLoadRequest(), true); 2035 Vector cListIDs = sReg.getJahiaContainersService( 2036 ).getContainerListIDsInPage(contentPageToClone, 2037 jParam.getEntryLoadRequest()); 2038 2039 int cListID; 2040 for (int i = 0; i < cListIDs.size(); i++) { 2041 cListID = ( (Integer ) cListIDs.elementAt(i)).intValue(); 2042 2043 sReg.getJahiaContainersService().cloneContainerList(cListID, pageID, 2044 pageAclID, 2045 childrenCloned); 2046 2047 } 2048 2049 Vector fieldIDs = sReg.getJahiaFieldService(). 2051 getNonContainerFieldIDsInPageByWorkflowState( 2052 pageToClone.getID(), 2053 EntryLoadRequest.CURRENT); 2054 2055 int fieldID; 2056 JahiaField field; 2057 2058 for (int i = 0; i < fieldIDs.size(); i++) { 2059 fieldID = ( (Integer ) fieldIDs.elementAt(i)).intValue(); 2061 field = 2062 sReg.getJahiaFieldService().loadField(fieldID, 2063 LoadFlags.NOTHING, jParam); 2064 sReg.getJahiaFieldService().cloneField(field, 0, pageID, pageAclID, 2065 childrenCloned); 2066 } 2067 2068 return page; 2069 } 2070 2071 public int getNbPages () 2076 throws JahiaException { 2077 return mUtilsDB.getNbPages(); 2078 } 2079 2080 public int getNbPages (int siteID) 2085 throws JahiaException { 2086 return mUtilsDB.getNbPages(siteID); 2087 } 2088 2089 public int getRealActiveNbPages () 2094 throws JahiaException { 2095 return mUtilsDB.getRealActiveNbPages(); 2096 } 2097 2098 public int getRealActiveNbPages (int siteID) 2103 throws JahiaException { 2104 return mUtilsDB.getRealActiveNbPages(siteID); 2105 } 2106 2107 2113 public JahiaDOMObject getPagesAsDOM (int siteID) 2114 throws JahiaException { 2115 2116 return JahiaPageUtilsDB.getInstance().getPagesAsDOM(siteID); 2117 2118 } 2119 2120 2127 public Vector getAclIDs (int siteID) 2128 throws JahiaException { 2129 return mUtilsDB.db_get_all_acl_id(siteID); 2130 } 2131 2132 public void invalidatePageCache (int pageID) { 2133 synchronized (mPageInfosCache) { 2134 mPageInfosCache.remove(new Integer (pageID)); 2135 mVersioningPageInfosCache.remove(new Integer (pageID)); 2136 mContentPageCache.remove(new Integer (pageID)); 2139 } 2140 } 2141 2142 2148 public Map getPageProperties (int pageID) 2149 throws JahiaException { 2150 return PagePropertyDB.getInstance().getPageProperties(pageID); 2151 } 2152 2153 2162 public ArrayList getPagePropertiesByValue (String propertyValue) 2163 throws JahiaException { 2164 return PagePropertyDB.getInstance().getPagePropertiesByValue( 2165 propertyValue); 2166 } 2167 2168 2175 public int getPageIDFromPageKeyAndSiteID( String pageKey, int siteID )throws JahiaException{ 2176 return PagePropertyDB.getInstance().getPageIDFromPageKeyAndSiteID( pageKey, siteID ); 2177 } 2178 2179 2187 public boolean isKeyAlreadyUsedInSiteWithID( String key, int siteID, int currentPageID ) 2188 throws JahiaException{ 2189 return PagePropertyDB.getInstance().isKeyAlreadyUsedInSiteWithID( key, siteID, currentPageID ); 2190 } 2191 2192 2193 2198 public void updateContentPageCache(ContentPage contentPage) { 2199 mContentPageCache.put(new Integer (contentPage.getID()), contentPage); 2200 } 2201 2202 2209 public Vector sortPages(List pageIDs, EntryLoadRequest loadRequest, 2210 JahiaUser user, String operationMode) 2211 throws JahiaException { 2212 Vector sortedPages = new Vector (); 2214 if ( pageIDs == null ){ 2215 return sortedPages; 2216 } 2217 2218 HashMap sortedPagePaths = new HashMap (); 2219 2220 boolean found = false; 2221 Iterator iterator = pageIDs.iterator(); 2222 int pos = -1; 2223 while (iterator.hasNext ()) { 2224 pos = -1; 2225 Integer pageId = (Integer ) iterator.next(); 2226 int size = sortedPages.size(); 2227 Integer I = null; 2228 for (int i = 0; i < size; i++) { 2229 I = (Integer ) sortedPages.get(i); 2230 Vector thePath = (Vector )sortedPagePaths.get(I); 2231 if ( thePath == null ){ 2232 thePath = ServicesRegistry.getInstance() 2233 .getJahiaPageService().getContentPagePath(I. 2234 intValue(), 2235 loadRequest, operationMode, user); 2236 if ( thePath != null ){ 2237 sortedPagePaths.put(I,thePath); 2238 } else { 2239 thePath = new Vector (); 2240 } 2241 } 2242 Enumeration enume = thePath.elements(); 2243 found = false; 2244 while (enume.hasMoreElements()) { 2245 ContentPage aPage = (ContentPage) enume.nextElement(); 2246 if (aPage.getID() == pageId.intValue()) { 2247 pos = i; 2248 found = true; 2249 break; 2250 } 2251 } 2252 if (pos != -1 && !found) { 2253 break; 2254 } 2255 } 2256 if (pos == -1) { 2257 sortedPages.add(0,pageId); 2258 } else { 2259 sortedPages.add(pos+1,pageId); 2260 } 2261 } 2262 if ( sortedPages == null ){ 2263 sortedPages = new Vector (); 2264 } 2265 return sortedPages; 2266 } 2267 2268 public ActivationTestResults arePageFieldsValidForActivation ( 2269 Set languageCodes, 2270 int pageID, 2271 JahiaUser user, 2272 JahiaSaveVersion saveVersion, 2273 ParamBean jParams, 2274 StateModificationContext stateModifContext) 2275 throws JahiaException { 2276 2277 Set fieldIDs = getStagingPageFieldIDsInPage(pageID); 2278 2279 ActivationTestResults activationResults = new ActivationTestResults (); 2280 for (Iterator it = fieldIDs.iterator(); it.hasNext(); ) { 2283 int id = ((Integer ) it.next()).intValue (); 2284 2285 ContentField theField = ContentField.getField (id); 2286 ActivationTestResults fieldResult = theField.isValidForActivation (languageCodes, 2287 jParams, stateModifContext); 2288 2289 if (fieldResult.getStatus () == ActivationTestResults.FAILED_OPERATION_STATUS) { 2290 fieldResult.setStatus (ActivationTestResults.PARTIAL_OPERATION_STATUS); 2291 fieldResult.moveErrorsToWarnings (); 2292 } 2293 activationResults.merge (fieldResult); 2294 } 2295 return activationResults; 2296 2297 } 2298} 2299 | Popular Tags |