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