001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.main; 029 030import org.opencms.ade.configuration.CmsADEManager; 031import org.opencms.cache.CmsVfsMemoryObjectCache; 032import org.opencms.configuration.CmsImageCacheConfiguration; 033import org.opencms.crypto.I_CmsTextEncryption; 034import org.opencms.db.CmsAliasManager; 035import org.opencms.db.CmsDefaultUsers; 036import org.opencms.db.CmsExportPoint; 037import org.opencms.db.CmsLoginManager; 038import org.opencms.db.CmsSqlManager; 039import org.opencms.db.CmsSubscriptionManager; 040import org.opencms.file.CmsObject; 041import org.opencms.file.CmsResource; 042import org.opencms.file.quota.CmsFolderSizeTracker; 043import org.opencms.flex.CmsFlexCache; 044import org.opencms.i18n.CmsLocaleManager; 045import org.opencms.importexport.CmsImportExportManager; 046import org.opencms.jsp.I_CmsElementMarker; 047import org.opencms.jsp.userdata.CmsUserDataRequestManager; 048import org.opencms.letsencrypt.CmsLetsEncryptConfiguration; 049import org.opencms.loader.CmsResourceManager; 050import org.opencms.loader.CmsTemplateContextManager; 051import org.opencms.module.CmsModuleManager; 052import org.opencms.monitor.CmsMemoryMonitor; 053import org.opencms.publish.CmsPublishManager; 054import org.opencms.repository.CmsRepositoryManager; 055import org.opencms.scheduler.CmsScheduleManager; 056import org.opencms.search.CmsSearchManager; 057import org.opencms.security.CmsOrgUnitManager; 058import org.opencms.security.CmsRole; 059import org.opencms.security.CmsRoleManager; 060import org.opencms.security.I_CmsAuthorizationHandler; 061import org.opencms.security.I_CmsCredentialsResolver; 062import org.opencms.security.I_CmsPasswordHandler; 063import org.opencms.security.I_CmsSecretStore; 064import org.opencms.security.I_CmsValidationHandler; 065import org.opencms.security.twofactor.CmsTwoFactorAuthenticationHandler; 066import org.opencms.site.CmsSiteManagerImpl; 067import org.opencms.staticexport.CmsLinkManager; 068import org.opencms.staticexport.CmsStaticExportManager; 069import org.opencms.ui.apps.CmsWorkplaceAppManager; 070import org.opencms.workflow.I_CmsWorkflowManager; 071import org.opencms.workplace.CmsWorkplaceManager; 072import org.opencms.xml.CmsXmlContentTypeManager; 073import org.opencms.xml.xml2json.I_CmsApiAuthorizationHandler; 074 075import java.util.List; 076import java.util.Map; 077import java.util.Set; 078import java.util.concurrent.ScheduledThreadPoolExecutor; 079 080import org.apache.commons.logging.Log; 081 082import jakarta.servlet.http.HttpServletRequest; 083import jakarta.servlet.http.HttpServletResponse; 084 085/** 086 * The OpenCms "operating system" that provides 087 * public static methods which can be used by other classes to access 088 * basic system features of OpenCms like logging etc.<p> 089 * 090 * This Object provides singleton access to the initialized OpenCms runtime system. 091 * Some methods are for internal or advanced use only, but others are of also of interest 092 * for general OpenCms development.<p> 093 * 094 * For example, to generate a new instance of <code>{@link org.opencms.file.CmsObject}</code> class in your application, 095 * use <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>. The argument String should be 096 * the name of the guest user, usually "Guest" and more formally obtained by <code>{@link org.opencms.db.CmsDefaultUsers#getUserGuest()}</code>. 097 * This will give you an initialized context with guest user permissions. 098 * Then use <code>{@link CmsObject#loginUser(String, String)}</code> to log in the user you want. 099 * Obviously you need the password for the new user.<p> 100 * 101 * Using <code>{@link #getSiteManager()}</code> you can obtain the initialized <code>{@link org.opencms.site.CmsSiteManagerImpl}</code> 102 * which provides information about the sites configured in the running OpenCms instance.<p> 103 * 104 * The <code>{@link org.opencms.db.CmsDefaultUsers}</code> instance returned by <code>{@link #getDefaultUsers()}</code> 105 * provides information about the names of the OpenCms default users.<p> 106 * 107 * Other objects of note that can be obtained by this class include the <code>{@link org.opencms.module.CmsModuleManager}</code> 108 * or the <code>{@link org.opencms.scheduler.CmsScheduleManager}</code>.<p> 109 * 110 * When using the instances returned by this object, keep in mind that applying changes to these may alter the basic OpenCms 111 * system configuration, which in turn may affect the systems performance or stability.<p> 112 * 113 * @since 6.0.0 114 */ 115public final class OpenCms { 116 117 /** Runlevel 0: System is offline. */ 118 public static final int RUNLEVEL_0_OFFLINE = 0; 119 120 /** Runlevel 1: Core object created, no database (some test cases run in this level). */ 121 public static final int RUNLEVEL_1_CORE_OBJECT = 1; 122 123 /** Runlevel 2: Initializing the system, required since this may take some seconds because of database connections. */ 124 public static final int RUNLEVEL_2_INITIALIZING = 2; 125 126 /** Runlevel 3: Shell access to the database possible, but no servlet context available. */ 127 public static final int RUNLEVEL_3_SHELL_ACCESS = 3; 128 129 /** Runlevel 4: Final runlevel where database and servlet are initialized. */ 130 public static final int RUNLEVEL_4_SERVLET_ACCESS = 4; 131 132 /** 133 * The public contructor is hidden to prevent generation of instances of this class.<p> 134 */ 135 private OpenCms() { 136 137 // empty 138 } 139 140 /** 141 * Add a cms event listener that listens to all events.<p> 142 * 143 * @param listener the listener to add 144 */ 145 public static void addCmsEventListener(I_CmsEventListener listener) { 146 147 OpenCmsCore.getInstance().getEventManager().addCmsEventListener(listener); 148 } 149 150 /** 151 * Add a cms event listener that listens only to particular events.<p> 152 * 153 * @param listener the listener to add 154 * @param eventTypes the events to listen for 155 */ 156 public static void addCmsEventListener(I_CmsEventListener listener, int[] eventTypes) { 157 158 OpenCmsCore.getInstance().getEventManager().addCmsEventListener(listener, eventTypes); 159 } 160 161 /** 162 * Notify all event listeners that a particular event has occurred.<p> 163 * 164 * @param event a CmsEvent 165 */ 166 public static void fireCmsEvent(CmsEvent event) { 167 168 OpenCmsCore.getInstance().getEventManager().fireEvent(event); 169 } 170 171 /** 172 * Notify all event listeners that a particular event has occurred.<p> 173 * 174 * The event will be given to all registered <code>{@link I_CmsEventListener}</code> objects.<p> 175 * 176 * @param type event type 177 * @param data event data 178 */ 179 public static void fireCmsEvent(int type, Map<String, Object> data) { 180 181 OpenCmsCore.getInstance().getEventManager().fireEvent(type, data); 182 } 183 184 /** 185 * Gets the initialized ADE manager.<p> 186 * 187 * @return the initialized ADE manager 188 */ 189 public static CmsADEManager getADEManager() { 190 191 return OpenCmsCore.getInstance().getADEManager(); 192 } 193 194 /** 195 * Gets the alias manager.<p> 196 * 197 * @return the alias manager 198 */ 199 public static CmsAliasManager getAliasManager() { 200 201 return OpenCmsCore.getInstance().getAliasManager(); 202 } 203 204 /** 205 * Gets the API authorization handler with the given name. 206 * 207 * <p>Returns null if there is no API authorization handler with that name. 208 * 209 * @param name the name of the API authorization handler 210 * 211 * @return an API authorization handler 212 */ 213 public static I_CmsApiAuthorizationHandler getApiAuthorization(String name) { 214 215 return OpenCmsCore.getInstance().getApiAuthorization(name); 216 } 217 218 /** 219 * Returns the configured authorization handler.<p> 220 * 221 * @return the configured authorization handler 222 */ 223 public static I_CmsAuthorizationHandler getAuthorizationHandler() { 224 225 return OpenCmsCore.getInstance().getAuthorizationHandler(); 226 } 227 228 /** 229 * Gets the credentials resolver instance.<p> 230 * 231 * @return the credentials resolver 232 */ 233 public static I_CmsCredentialsResolver getCredentialsResolver() { 234 235 return OpenCmsCore.getInstance().getCredentialsResolver(); 236 } 237 238 /** 239 * Gets the database pool names.<p> 240 * 241 * @return the database pool names 242 */ 243 public static List<String> getDbPoolNames() { 244 245 return OpenCmsCore.getInstance().getDbPoolNames(); 246 } 247 248 /** 249 * Returns the configured list of default directory file names (instances of <code>{@link String}</code>).<p> 250 * 251 * Caution: This list can not be modified.<p> 252 * 253 * @return the configured list of default directory file names 254 */ 255 public static List<String> getDefaultFiles() { 256 257 return OpenCmsCore.getInstance().getDefaultFiles(); 258 } 259 260 /** 261 * Gets the default text encryption. 262 * 263 * @return the default text encryption 264 */ 265 public static I_CmsTextEncryption getDefaultTextEncryption() { 266 267 return getTextEncryptions().get("default"); 268 } 269 270 /** 271 * Returns the default user and group name configuration.<p> 272 * 273 * @return the default user and group name configuration 274 */ 275 public static CmsDefaultUsers getDefaultUsers() { 276 277 return OpenCmsCore.getInstance().getDefaultUsers(); 278 } 279 280 /** 281 * Returns the configured element marker handler (a no-op default when none is configured). 282 * 283 * @return the element marker handler (never <code>null</code>) 284 */ 285 public static I_CmsElementMarker getElementMarker() { 286 287 return OpenCmsCore.getInstance().getElementMarker(); 288 } 289 290 /** 291 * Returns the event manger that handles all OpenCms events.<p> 292 * 293 * @return the event manger that handles all OpenCms events 294 */ 295 public static CmsEventManager getEventManager() { 296 297 return OpenCmsCore.getInstance().getEventManager(); 298 } 299 300 /** 301 * Gets the thread pool executor.<p> 302 * 303 * @return the thread pool executor 304 */ 305 public static ScheduledThreadPoolExecutor getExecutor() { 306 307 return OpenCmsCore.getInstance().getExecutor(); 308 } 309 310 /** 311 * Returns the configured export points, 312 * the returned set being an unmodifiable set.<p> 313 * 314 * @return an unmodifiable set of the configured export points 315 */ 316 public static Set<CmsExportPoint> getExportPoints() { 317 318 return OpenCmsCore.getInstance().getExportPoints(); 319 } 320 321 /** 322 * Returns the flex cache.<p> 323 * @return the current CmsFlexCache object 324 */ 325 326 public static CmsFlexCache getFlexCache() { 327 328 return OpenCmsCore.getInstance().getFlexCache(); 329 } 330 331 /** 332 * Creates a string containing all current flex cache keys, for use in debugging.<p> 333 * 334 * @return a string containing all current flex cache keys 335 */ 336 public static String getFlexCacheKeyDump() { 337 338 return OpenCmsCore.getInstance().getFlexCacheKeyDump(); 339 } 340 341 /** 342 * Gets the folder size tracker for the Offline or Online project. 343 * 344 * @param online if we want the Online folder size tracker, false for the Offline project one 345 * @return the folder size tracker 346 */ 347 public static CmsFolderSizeTracker getFolderSizeTracker(boolean online) { 348 349 return OpenCmsCore.getInstance().getFolderSizeTracker(online); 350 } 351 352 /** 353 * Returns the central image cache retention and maintenance configuration.<p> 354 * 355 * @return the image cache configuration 356 */ 357 public static CmsImageCacheConfiguration getImageCacheConfiguration() { 358 359 return OpenCmsCore.getInstance().getImageCacheConfiguration(); 360 } 361 362 /** 363 * Returns the initialized import/export manager, 364 * which contains information about how to handle imported resources.<p> 365 * 366 * @return the initialized import/export manager 367 */ 368 public static CmsImportExportManager getImportExportManager() { 369 370 return OpenCmsCore.getInstance().getImportExportManager(); 371 } 372 373 /** 374 * Gets the LetsEncrypt configuration.<p> 375 * 376 * Returns null if LetsEncrypt integration is not configured at all. 377 * 378 * @return the LetsEncrypt configuration 379 */ 380 public static CmsLetsEncryptConfiguration getLetsEncryptConfig() { 381 382 return OpenCmsCore.getInstance().getLetsEncryptConfig(); 383 384 } 385 386 /** 387 * Returns the link manager to resolve links in <link> tags.<p> 388 * 389 * @return the link manager to resolve links in <link> tags 390 */ 391 public static CmsLinkManager getLinkManager() { 392 393 return OpenCmsCore.getInstance().getLinkManager(); 394 } 395 396 /** 397 * Returns the locale manager used for obtaining the current locale.<p> 398 * 399 * @return the locale manager 400 */ 401 public static CmsLocaleManager getLocaleManager() { 402 403 return OpenCmsCore.getInstance().getLocaleManager(); 404 } 405 406 /** 407 * Returns the log for the selected object.<p> 408 * 409 * If the provided object is a String, this String will 410 * be used as channel name. Otherwise the objects 411 * class name will be used as channel name.<p> 412 * 413 * @param obj the object channel to use 414 * @return the log for the selected object channel 415 */ 416 public static Log getLog(Object obj) { 417 418 return CmsLog.getLog(obj); 419 } 420 421 /** 422 * Returns the login manager used to check if a login is possible.<p> 423 * 424 * @return the login manager 425 */ 426 public static CmsLoginManager getLoginManager() { 427 428 return OpenCmsCore.getInstance().getLoginManager(); 429 } 430 431 /** 432 * Returns the memory monitor.<p> 433 * 434 * @return the memory monitor 435 */ 436 public static CmsMemoryMonitor getMemoryMonitor() { 437 438 return OpenCmsCore.getInstance().getMemoryMonitor(); 439 } 440 441 /** 442 * Returns the module manager.<p> 443 * 444 * @return the module manager 445 */ 446 public static CmsModuleManager getModuleManager() { 447 448 return OpenCmsCore.getInstance().getModuleManager(); 449 } 450 451 /** 452 * Returns the organizational unit manager.<p> 453 * 454 * @return the organizational unit manager 455 */ 456 public static CmsOrgUnitManager getOrgUnitManager() { 457 458 return OpenCmsCore.getInstance().getOrgUnitManager(); 459 } 460 461 /** 462 * Returns the password handler.<p> 463 * 464 * @return the password handler 465 */ 466 public static I_CmsPasswordHandler getPasswordHandler() { 467 468 return OpenCmsCore.getInstance().getPasswordHandler(); 469 } 470 471 /** 472 * Returns the core publish manager class.<p> 473 * 474 * @return the publish manager instance 475 */ 476 public static CmsPublishManager getPublishManager() { 477 478 return OpenCmsCore.getInstance().getPublishManager(); 479 } 480 481 /** 482 * Returns the repository manager.<p> 483 * 484 * @return the repository manager 485 */ 486 public static CmsRepositoryManager getRepositoryManager() { 487 488 return OpenCmsCore.getInstance().getRepositoryManager(); 489 } 490 491 /** 492 * Returns the resource manager.<p> 493 * 494 * @return the resource manager 495 */ 496 public static CmsResourceManager getResourceManager() { 497 498 return OpenCmsCore.getInstance().getResourceManager(); 499 } 500 501 /** 502 * Returns the role manager.<p> 503 * 504 * @return the role manager 505 */ 506 public static CmsRoleManager getRoleManager() { 507 508 return OpenCmsCore.getInstance().getRoleManager(); 509 } 510 511 /** 512 * Returns the current OpenCms run level.<p> 513 * 514 * The following runlevels are defined: 515 * <dl> 516 * <dt>Runlevel {@link OpenCms#RUNLEVEL_0_OFFLINE}:</dt><dd> 517 * OpenCms is in the process of being shut down, the system is offline.</dd> 518 * 519 * <dt>Runlevel {@link OpenCms#RUNLEVEL_1_CORE_OBJECT}:</dt><dd> 520 * OpenCms instance available, but configuration has not been processed. 521 * No database or VFS available.</dd> 522 * 523 * <dt>Runlevel {@link OpenCms#RUNLEVEL_2_INITIALIZING}:</dt><dd> 524 * OpenCms is initializing, but the process is not finished. 525 * The database with the VFS is currently being connected but can't be accessed.</dd> 526 * 527 * <dt>Runlevel {@link OpenCms#RUNLEVEL_3_SHELL_ACCESS}:</dt><dd> 528 * OpenCms database and VFS available, but http processing (i.e. servlet) not initialized. 529 * This is the runlevel the OpenCms shell operates in.</dd> 530 * 531 * <dt>Runlevel {@link OpenCms#RUNLEVEL_4_SERVLET_ACCESS}:</dt><dd> 532 * OpenCms fully initialized, servlet and database available. 533 * This is the "default" when OpenCms is in normal operation.</dd> 534 * </dl> 535 * 536 * @return the OpenCms run level 537 */ 538 public static int getRunLevel() { 539 540 return OpenCmsCore.getInstance().getRunLevel(); 541 } 542 543 /** 544 * Looks up a value in the runtime property Map.<p> 545 * 546 * @param key the key to look up in the runtime properties 547 * @return the value for the key, or null if the key was not found 548 */ 549 public static Object getRuntimeProperty(Object key) { 550 551 return OpenCmsCore.getInstance().getRuntimeProperty(key); 552 } 553 554 /** 555 * Returns the configured schedule manager.<p> 556 * 557 * @return the configured schedule manager 558 */ 559 public static CmsScheduleManager getScheduleManager() { 560 561 return OpenCmsCore.getInstance().getScheduleManager(); 562 } 563 564 /** 565 * Returns the initialized search manager, 566 * which provides indexing and searching operations.<p> 567 * 568 * @return the initialized search manager 569 */ 570 public static CmsSearchManager getSearchManager() { 571 572 return OpenCmsCore.getInstance().getSearchManager(); 573 } 574 575 /** 576 * Get the secret store. 577 * 578 * @return the secret store 579 */ 580 public static I_CmsSecretStore getSecretStore() { 581 582 return OpenCmsCore.getInstance().getSecretStore(); 583 } 584 585 /** 586 * Returns the session manager that keeps track of the active users.<p> 587 * 588 * @return the session manager that keeps track of the active users 589 */ 590 public static CmsSessionManager getSessionManager() { 591 592 return OpenCmsCore.getInstance().getSessionManager(); 593 } 594 595 /** 596 * Returns the initialized site manager, 597 * which contains information about all configured sites.<p> 598 * 599 * @return the initialized site manager 600 */ 601 public static CmsSiteManagerImpl getSiteManager() { 602 603 return OpenCmsCore.getInstance().getSiteManager(); 604 } 605 606 /** 607 * Returns an instance of the common sql manager.<p> 608 * 609 * @return an instance of the common sql manager 610 */ 611 public static CmsSqlManager getSqlManager() { 612 613 return OpenCmsCore.getInstance().getSqlManager(); 614 } 615 616 /** 617 * Returns the properties for the static export.<p> 618 * 619 * @return the properties for the static export 620 */ 621 public static CmsStaticExportManager getStaticExportManager() { 622 623 return OpenCmsCore.getInstance().getStaticExportManager(); 624 } 625 626 /** 627 * Returns the subscription manager.<p> 628 * 629 * @return the subscription manager 630 */ 631 public static CmsSubscriptionManager getSubscriptionManager() { 632 633 return OpenCmsCore.getInstance().getSubscriptionManager(); 634 } 635 636 /** 637 * Returns the system information storage.<p> 638 * 639 * @return the system information storage 640 */ 641 public static CmsSystemInfo getSystemInfo() { 642 643 return OpenCmsCore.getInstance().getSystemInfo(); 644 } 645 646 /** 647 * Returns the list of system defined roles (instances of <code>{@link CmsRole}</code>).<p> 648 * 649 * Caution: This list can not be modified.<p> 650 * 651 * @return the list of system defined roles 652 */ 653 public static List<CmsRole> getSystemRoles() { 654 655 return CmsRole.getSystemRoles(); 656 } 657 658 /** 659 * Gets the template context manager.<p> 660 * 661 * @return the template context manager instance 662 */ 663 public static CmsTemplateContextManager getTemplateContextManager() { 664 665 return OpenCmsCore.getInstance().getTemplateContextManager(); 666 } 667 668 /** 669 * Gets the map of text encryption methods, with their names as keys. 670 * 671 * @return the map of text encryption methods 672 */ 673 public static Map<String, I_CmsTextEncryption> getTextEncryptions() { 674 675 return OpenCmsCore.getInstance().getTextEncryptions(); 676 } 677 678 /** 679 * Returns the OpenCms Thread store.<p> 680 * 681 * @return the OpenCms Thread store 682 */ 683 public static CmsThreadStore getThreadStore() { 684 685 return OpenCmsCore.getInstance().getThreadStore(); 686 } 687 688 /** 689 * Gets the two-factor authentication handler. 690 * 691 * @return the two-factor authentication handler 692 */ 693 public static CmsTwoFactorAuthenticationHandler getTwoFactorAuthenticationHandler() { 694 695 return OpenCmsCore.getInstance().getTwoFactorAuthenticationHandler(); 696 } 697 698 /** 699 * Gets the user data request manager. 700 * 701 * @return the user data request manager 702 */ 703 public static CmsUserDataRequestManager getUserDataRequestManager() { 704 705 return OpenCmsCore.getInstance().getUserDataRequestManager(); 706 } 707 708 /** 709 * Returns the runtime validation handler.<p> 710 * 711 * @return the validation handler 712 */ 713 public static I_CmsValidationHandler getValidationHandler() { 714 715 return OpenCmsCore.getInstance().getValidationHandler(); 716 } 717 718 /** 719 * Gets the default memory object cache instance. 720 * 721 * @return the memory object cache 722 */ 723 public static CmsVfsMemoryObjectCache getVfsMemoryObjectCache() { 724 725 return OpenCmsCore.getInstance().getVfsMemoryObjectCache(); 726 } 727 728 /** 729 * Gets the initialized workflow manager.<p> 730 * 731 * @return the initialized workflow manager 732 */ 733 public static I_CmsWorkflowManager getWorkflowManager() { 734 735 return OpenCmsCore.getInstance().getWorkflowManager(); 736 } 737 738 /** 739 * Returns the workplace app manager.<p> 740 * 741 * @return the app manager 742 */ 743 public static CmsWorkplaceAppManager getWorkplaceAppManager() { 744 745 return OpenCmsCore.getInstance().getWorkplaceAppManager(); 746 } 747 748 /** 749 * Returns the initialized workplace manager, 750 * which contains information about the global workplace settings.<p> 751 * 752 * @return the initialized workplace manager 753 */ 754 public static CmsWorkplaceManager getWorkplaceManager() { 755 756 return OpenCmsCore.getInstance().getWorkplaceManager(); 757 } 758 759 /** 760 * Returns the XML content type manager.<p> 761 * 762 * @return the XML content type manager 763 */ 764 public static CmsXmlContentTypeManager getXmlContentTypeManager() { 765 766 return OpenCmsCore.getInstance().getXmlContentTypeManager(); 767 } 768 769 /** 770 * Returns an independent copy of the provided CmsObject.<p> 771 * 772 * This can be useful in case a permanent reference to a CmsObject is stored. 773 * Changing the request context values (for example project, siteroot) in the new CmsObject 774 * will have no side effects to the CmsObject it was copied form.<p> 775 * 776 * @param cms the CmsObject to create a copy of 777 * 778 * @return an independent copy of the provided CmsObject 779 * 780 * @throws CmsException in case the initialization failed 781 * 782 * @see OpenCms#initCmsObject(CmsObject) 783 * @see OpenCms#initCmsObject(CmsObject, CmsContextInfo) 784 * @see OpenCms#initCmsObject(String) 785 */ 786 public static CmsObject initCmsObject(CmsObject cms) throws CmsException { 787 788 return OpenCmsCore.getInstance().initCmsObject(cms); 789 } 790 791 /** 792 * Returns an initialized CmsObject with the user and context initialized as provided.<p> 793 * 794 * Note: Only if the provided <code>adminCms</code> CmsObject has admin permissions, 795 * this method allows the creation a CmsObject for any existing user. Otherwise 796 * only the default users 'Guest' and 'Export' can initialized with 797 * this method, all other user names will throw an Exception.<p> 798 * 799 * @param adminCms must either be initialized with "Admin" permissions, or null 800 * @param contextInfo the context info to create a CmsObject for 801 * 802 * @return an initialized CmsObject with the given users permissions 803 * 804 * @throws CmsException if an invalid user name was provided, or if something else goes wrong 805 * 806 * @see org.opencms.db.CmsDefaultUsers#getUserGuest() 807 * @see org.opencms.db.CmsDefaultUsers#getUserExport() 808 * @see OpenCms#initCmsObject(CmsObject) 809 * @see OpenCms#initCmsObject(CmsObject, CmsContextInfo) 810 * @see OpenCms#initCmsObject(String) 811 */ 812 public static CmsObject initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo) throws CmsException { 813 814 return OpenCmsCore.getInstance().initCmsObject(adminCms, contextInfo); 815 } 816 817 /** 818 * Returns an initialized CmsObject (OpenCms user context) with the user initialized as provided, 819 * with the "Online" project selected and "/" set as the current site root.<p> 820 * 821 * Note: Only the default users 'Guest' and 'Export' can initialized with 822 * this method, all other user names will throw an Exception.<p> 823 * 824 * In order to initialize another user (for example, the {@link CmsDefaultUsers#getUserAdmin()}), 825 * you need to get the 'Guest' user context first, then login the target user with 826 * his user name and password, using {@link CmsObject#loginUser(String, String)}. 827 * There is no way to obtain a user context other then the 'Guest' or 'Export' user 828 * without the users password. This is a security feature.<p> 829 * 830 * @param user the user name to initialize, can only be 831 * {@link org.opencms.db.CmsDefaultUsers#getUserGuest()} or 832 * {@link org.opencms.db.CmsDefaultUsers#getUserExport()} 833 * 834 * @return an initialized CmsObject with the given users permissions 835 * 836 * @throws CmsException if an invalid user name was provided, or if something else goes wrong 837 * 838 * @see org.opencms.db.CmsDefaultUsers#getUserGuest() 839 * @see org.opencms.db.CmsDefaultUsers#getUserExport() 840 * @see OpenCms#initCmsObject(CmsObject) 841 * @see OpenCms#initCmsObject(CmsObject, CmsContextInfo) 842 * @see OpenCms#initCmsObject(String) 843 */ 844 public static CmsObject initCmsObject(String user) throws CmsException { 845 846 return OpenCmsCore.getInstance().initCmsObject(user); 847 } 848 849 /** 850 * Reads the requested resource from the OpenCms VFS, 851 * and in case a directory name is requested, the default files of the 852 * directory will be looked up and the first match is returned.<p> 853 * 854 * The resource that is returned is always a <code>{@link org.opencms.file.CmsFile}</code>, 855 * even though the content will usually not be loaded in the result. Folders are never returned since 856 * the point of this method is really to load the default file if just a folder name is requested.<p> 857 * 858 * The URI stored in the given OpenCms user context will be changed to the URI of the resource 859 * that was found and returned.<p> 860 * 861 * Implementing and configuring an <code>{@link I_CmsResourceInit}</code> handler 862 * allows to customize the process of default resource selection.<p> 863 * 864 * @param cms the current users OpenCms context 865 * @param resourceName the path of the requested resource in the OpenCms VFS 866 * @param req the current http request 867 * @param res the current http response 868 * @return the requested resource read from the VFS 869 * 870 * @throws CmsException in case the requested file does not exist or the user has insufficient access permissions 871 */ 872 public static CmsResource initResource( 873 CmsObject cms, 874 String resourceName, 875 HttpServletRequest req, 876 HttpServletResponse res) 877 throws CmsException { 878 879 return OpenCmsCore.getInstance().initResource(cms, resourceName, req, res); 880 } 881 882 /** 883 * Registers an action to be executed before shutdown. 884 * 885 * @param action the action to be executed before shutdown 886 */ 887 public static void registerShutdownAction(Runnable action) { 888 889 OpenCmsCore.getInstance().registerShutdownAction(action); 890 } 891 892 /** 893 * Removes a cms event listener.<p> 894 * 895 * @param listener the listener to remove 896 */ 897 public static void removeCmsEventListener(I_CmsEventListener listener) { 898 899 OpenCmsCore.getInstance().getEventManager().removeCmsEventListener(listener); 900 } 901 902 /** 903 * This method adds an Object to the OpenCms runtime properties. 904 * The runtime properties can be used to store Objects that are shared 905 * in the whole system.<p> 906 * 907 * @param key the key to add the Object with 908 * @param value the value of the Object to add 909 */ 910 public static void setRuntimeProperty(Object key, Object value) { 911 912 OpenCmsCore.getInstance().setRuntimeProperty(key, value); 913 } 914 915 /** 916 * Writes the XML configuration for the provided configuration class.<p> 917 * 918 * @param clazz the configuration class to write the XML for 919 */ 920 public static void writeConfiguration(Class<?> clazz) { 921 922 OpenCmsCore.getInstance().writeConfiguration(clazz); 923 } 924}