opencmscore.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,617 行 · 第 1/5 页
JAVA
1,617 行
/**
* Returns the initialized OpenCms security manager.<p>
*
* @return the initialized OpenCms security manager
*/
protected CmsSecurityManager getSecurityManager() {
return m_securityManager;
}
/**
* Returns the session manager.<p>
*
* @return the session manager
*/
protected CmsSessionManager getSessionManager() {
return m_sessionManager;
}
/**
* Returns the initialized site manager,
* which contains information about all configured sites.<p>
*
* @return the initialized site manager
*/
protected CmsSiteManagerImpl getSiteManager() {
return m_siteManager;
}
/**
* Returns an instance of the common sql manager.<p>
*
* @return an instance of the common sql manager
*/
protected CmsSqlManager getSqlManager() {
return m_securityManager.getSqlManager();
}
/**
* Returns the properties for the static export.<p>
*
* @return the properties for the static export
*/
protected CmsStaticExportManager getStaticExportManager() {
return m_staticExportManager;
}
/**
* Returns the system information storage.<p>
*
* @return the system information storage
*/
protected CmsSystemInfo getSystemInfo() {
return m_systemInfo;
}
/**
* Returns the OpenCms Thread store.<p>
*
* @return the OpenCms Thread store
*/
protected CmsThreadStore getThreadStore() {
return m_threadStore;
}
/**
* Returns the runtime validation handler.<p>
*
* @return the validation handler
*/
protected I_CmsValidationHandler getValidationHandler() {
return m_validationHandler;
}
/**
* Returns the initialized workplace manager,
* which contains information about the global workplace settings.<p>
*
* @return the initialized workplace manager
*/
protected CmsWorkplaceManager getWorkplaceManager() {
return m_workplaceManager;
}
/**
* Returns the XML content type manager.<p>
*
* @return the XML content type manager
*/
protected CmsXmlContentTypeManager getXmlContentTypeManager() {
if (m_xmlContentTypeManager != null) {
return m_xmlContentTypeManager;
}
if (getRunLevel() == OpenCms.RUNLEVEL_1_CORE_OBJECT) {
// this is only to enable test cases to run
m_xmlContentTypeManager = CmsXmlContentTypeManager.createTypeManagerForTestCases();
}
return m_xmlContentTypeManager;
}
/**
* Returns an independent copy of the provided CmsObject.<p>
*
* This can be useful in case a permanent reference to a CmsObject is stored.
* Changing the request context values (for example project, siteroot) in the new CmsObject
* will have no side effects to the CmsObject it was copied form.<p>
*
* The request time (<code>{@link CmsRequestContext#getRequestTime()}</code>)
* is set to the current time.<p>
*
* @param cms the CmsObject to create a copy of
*
* @return an independent copy of the provided CmsObject
*
* @throws CmsException in case the intialization failed
*
* @see OpenCms#initCmsObject(CmsObject)
* @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
* @see OpenCms#initCmsObject(String)
*/
protected CmsObject initCmsObject(CmsObject cms) throws CmsException {
CmsContextInfo contextInfo = new CmsContextInfo(cms.getRequestContext());
contextInfo.setRequestTime(CmsContextInfo.CURRENT_TIME);
return initCmsObject(contextInfo);
}
/**
* Returns an initialized CmsObject with the user and context initialized as provided.<p>
*
* Note: Only if the provided <code>adminCms</code> CmsObject has admin permissions,
* this method allows the creation a CmsObject for any existing user. Otherwise
* only the default users 'Guest' and 'Export' can initialized with
* this method, all other user names will throw an Exception.<p>
*
* @param adminCms must either be initialized with "Admin" permissions, or null
* @param contextInfo the context info to create a CmsObject for
*
* @return an initialized CmsObject with the given users permissions
*
* @throws CmsException if an invalid user name was provided
* @throws CmsRoleViolationException if the current user does not have the role permissions to create a context for the requested user
*
* @see org.opencms.db.CmsDefaultUsers#getUserGuest()
* @see org.opencms.db.CmsDefaultUsers#getUserExport()
* @see OpenCms#initCmsObject(CmsObject)
* @see OpenCms#initCmsObject(CmsObject, CmsContextInfo)
* @see OpenCms#initCmsObject(String)
*/
protected CmsObject initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo)
throws CmsRoleViolationException, CmsException {
String userName = contextInfo.getUserName();
if ((adminCms == null) || !m_roleManager.hasRole(adminCms, CmsRole.ROOT_ADMIN)) {
if (!userName.endsWith(getDefaultUsers().getUserGuest())
&& !userName.endsWith(getDefaultUsers().getUserExport())) {
// if no admin object is provided, only "Guest" or "Export" user can be generated
CmsMessageContainer message = Messages.get().container(
Messages.ERR_INVALID_INIT_USER_2,
userName,
((adminCms != null) ? (adminCms.getRequestContext().currentUser().getName()) : ""));
if (LOG.isWarnEnabled()) {
LOG.warn(message.key());
}
throw new CmsRoleViolationException(message);
}
}
return initCmsObject(contextInfo);
}
/**
* Returns an initialized CmsObject with the user initialized as provided,
* with the "Online" project selected and "/" set as the current site root.<p>
*
* Note: Only the default users 'Guest' and 'Export' can initialized with
* this method, all other user names will throw an Exception.<p>
*
* @param user the user name to initialize, can only be
* {@link org.opencms.db.CmsDefaultUsers#getUserGuest()} or
* {@link org.opencms.db.CmsDefaultUsers#getUserExport()}
*
* @return an initialized CmsObject with the given users permissions
*
* @throws CmsException if an invalid user name was provided, or if something else goes wrong
*
* @see org.opencms.db.CmsDefaultUsers#getUserGuest()
* @see org.opencms.db.CmsDefaultUsers#getUserExport()
* @see OpenCms#initCmsObject(String)
* @see #initCmsObject(CmsObject, CmsContextInfo)
*/
protected CmsObject initCmsObject(String user) throws CmsException {
return initCmsObject(null, new CmsContextInfo(user));
}
/**
* Initializes a new cms object from the session data of the request.<p>
*
* If no session data is found, <code>null</code> is returned.<p>
*
* @param req the request
*
* @return the new initialized cms object
*
* @throws CmsException if something goes wrong
*/
protected CmsObject initCmsObjectFromSession(HttpServletRequest req) throws CmsException {
// try to get an OpenCms user session info object for this request
CmsSessionInfo sessionInfo = m_sessionManager.getSessionInfo(req);
if (sessionInfo == null) {
return null;
}
// initialize the requested site root
CmsSite site = getSiteManager().matchRequest(req);
// a user name is found in the session manager, reuse this user information
CmsUUID project = sessionInfo.getProject();
// initialize site root from request
String siteroot = null;
// a dedicated workplace site is configured
if ((getSiteManager().getWorkplaceSiteMatcher().equals(site.getSiteMatcher()))) {
// if no dedicated workplace site is configured,
// or for the dedicated workplace site, use the site root from the session attribute
siteroot = sessionInfo.getSiteRoot();
}
if (siteroot == null) {
siteroot = site.getSiteRoot();
}
return initCmsObject(
req,
m_securityManager.readUser(null, sessionInfo.getUserId()),
siteroot,
project,
sessionInfo.getOrganizationalUnitFqn());
}
/**
* Constructor to create a new OpenCms object.<p>
*
* It reads the configurations from the <code>opencms.properties</code>
* file in the <code>config/</code> subdirectory. With the information
* from this file is inits a ResourceBroker (Database access module),
* various caching systems and other options.<p>
*
* This will only be done once per accessing class.
*
* @param configuration the configurations from the <code>opencms.properties</code> file
* @throws CmsInitException in case OpenCms can not be initialized
*/
protected synchronized void initConfiguration(ExtendedProperties configuration) throws CmsInitException {
String systemEncoding = null;
try {
systemEncoding = System.getProperty("file.encoding");
} catch (SecurityException se) {
// security manager is active, but we will try other options before giving up
}
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_FILE_ENCODING_1, systemEncoding));
}
// read server ethernet address (MAC) and init UUID generator
String ethernetAddress = configuration.getString("server.ethernet.address", CmsUUID.getDummyEthernetAddress());
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ETHERNET_ADDRESS_1, ethernetAddress));
}
CmsUUID.init(ethernetAddress);
// set the server name
String serverName = configuration.getString("server.name", "OpenCmsServer");
getSystemInfo().setServerName(serverName);
// check the installed Java SDK
try {
if (CmsLog.INIT.isInfoEnabled()) {
String jdkinfo = System.getProperty("java.vm.name") + " ";
jdkinfo += System.getProperty("java.vm.version") + " ";
jdkinfo += System.getProperty("java.vm.info") + " ";
jdkinfo += System.getProperty("java.vm.vendor") + " ";
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_JAVA_VM_1, jdkinfo));
String osinfo = System.getProperty("os.name") + " ";
osinfo += System.getProperty("os.version") + " ";
osinfo += System.getProperty("os.arch") + " ";
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_OPERATING_SYSTEM_1, osinfo));
}
} catch (Exception e) {
throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_PROP_0), e);
}
// create the configuration manager instance
m_configurationManager = new CmsConfigurationManager(getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
CmsSystemInfo.FOLDER_CONFIG));
// store the configuration read from "opencms.properties" in the configuration manager
m_configurationManager.setConfiguration(configuration);
// now load the XML configuration
try {
m_configurationManager.loadXmlConfiguration();
} catch (Exception e) {
throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_XML_0), e);
}
// get the system configuration
CmsSystemConfiguration systemConfiguration = (CmsSystemConfiguration)m_configurationManager.getConfiguration(CmsSystemConfiguration.class);
// initialize the memory monitor
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?