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