⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opencmscore.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        m_securityManager = CmsSecurityManager.newInstance(
            m_configurationManager,
            systemConfiguration.getRuntimeInfoFactory());

        // initialize the Thread store
        m_threadStore = new CmsThreadStore();

        // initialize the link manager
        m_linkManager = new CmsLinkManager();

        // store the runtime properties
        m_runtimeProperties.putAll(systemConfiguration.getRuntimeProperties());

        // get an Admin cms context object with site root set to "/"
        CmsObject adminCms;
        try {
            adminCms = initCmsObject(null, null, getDefaultUsers().getUserAdmin(), null);
        } catch (CmsException e) {
            throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_ADMINCMS_0), e);
        }

        // now initialize the managers
        try {
            // initialize the scheduler
            m_scheduleManager.initialize(initCmsObject(adminCms));

            // initialize the locale manager
            m_localeManager = systemConfiguration.getLocaleManager();
            m_localeManager.initialize(initCmsObject(adminCms));

            // initialize the site manager
            m_siteManager.initialize(initCmsObject(adminCms));

            // initialize the static export manager
            m_staticExportManager.initialize(initCmsObject(adminCms));

            // initialize the XML content type manager
            m_xmlContentTypeManager.initialize(initCmsObject(adminCms));

            // intialize the module manager
            m_moduleManager.initialize(initCmsObject(adminCms), m_configurationManager);

            // initialize the resource manager
            m_resourceManager.initialize(initCmsObject(adminCms));

            // initialize the search manager
            m_searchManager.initialize(initCmsObject(adminCms));

            // initialize the workplace manager
            m_workplaceManager.initialize(initCmsObject(adminCms));
        } catch (CmsException e) {
            throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_MANAGERS_0), e);
        }
    }

    /**
     * Initialization of the OpenCms runtime environment.<p>
     *
     * The connection information for the database is read 
     * from the <code>opencms.properties</code> configuration file and all 
     * driver manager are initialized via the initalizer, 
     * which usually will be an instance of a <code>OpenCms</code> class.
     *
     * @param context configuration of OpenCms from <code>web.xml</code>
     * @throws CmsInitException in case OpenCms can not be initialized
     */
    protected synchronized void initContext(ServletContext context) throws CmsInitException {

        // read the the OpenCms servlet mapping from the servlet context parameters
        String servletMapping = context.getInitParameter(OpenCmsServlet.SERVLET_PARAM_OPEN_CMS_SERVLET);
        if (servletMapping == null) {
            throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_SERVLET_0));
        }

        // check for OpenCms home (base) directory path
        String webInfPath = context.getInitParameter(OpenCmsServlet.SERVLET_PARAM_OPEN_CMS_HOME);
        if (CmsStringUtil.isEmpty(webInfPath)) {
            webInfPath = CmsFileUtil.searchWebInfFolder(context.getRealPath("/"));
            if (CmsStringUtil.isEmpty(webInfPath)) {
                throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_FOLDER_0));
            }
        }

        // read the the default context name from the servlet context parameters
        String defaultWebApplication = context.getInitParameter("DefaultWebApplication");
        if (defaultWebApplication == null) {
            // not set in web.xml, so we use "ROOT" which should usually work since it is the (de-facto) standard 
            defaultWebApplication = "ROOT";
        }

        // read the the webapp context name from the servlet context parameters
        // this is needed in case an application server specific deployment descriptor is used to changed the webapp context
        String webApplicationContext = context.getInitParameter(OpenCmsServlet.SERVLET_PARAM_WEB_APPLICATION_CONTEXT);

        // now initialize the system info with the path and mapping information
        getSystemInfo().init(webInfPath, servletMapping, webApplicationContext, defaultWebApplication);

        // Collect the configurations 
        ExtendedProperties configuration = null;
        try {
            configuration = CmsPropertyUtils.loadProperties(getSystemInfo().getConfigurationFileRfsPath());
        } catch (Exception e) {
            throw new CmsInitException(Messages.get().container(
                Messages.ERR_CRITICAL_INIT_PROPFILE_1,
                getSystemInfo().getConfigurationFileRfsPath()), e);
        }

        // check if the wizard is enabled, if so stop initialization
        if (configuration.getBoolean("wizard.enabled", true)) {
            throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_WIZARD_0));
        }
        // output startup message and copyright to STDERR
        System.err.println(Messages.get().getBundle().key(
            Messages.LOG_STARTUP_CONSOLE_NOTE_2,
            OpenCms.getSystemInfo().getVersionName(),
            getSystemInfo().getWebApplicationName()));
        for (int i = 0; i < Messages.COPYRIGHT_BY_ALKACON.length; i++) {
            System.err.println(Messages.COPYRIGHT_BY_ALKACON[i]);
        }
        System.err.println();

        // output startup message to logfile
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0));
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0));
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0));
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0));
            for (int i = 0; i < Messages.COPYRIGHT_BY_ALKACON.length; i++) {
                CmsLog.INIT.info(". " + Messages.COPYRIGHT_BY_ALKACON[i]);
            }
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LINE_0));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_STARTUP_TIME_1,
                new Date(System.currentTimeMillis())));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_OPENCMS_VERSION_1,
                OpenCms.getSystemInfo().getVersionName()));
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SERVLET_CONTAINER_1, context.getServerInfo()));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_WEBAPP_NAME_1,
                getSystemInfo().getWebApplicationName()));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_SERVLET_PATH_1,
                getSystemInfo().getServletPath()));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_OPENCMS_CONTEXT_1,
                getSystemInfo().getOpenCmsContext()));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_WEBINF_PATH_1,
                getSystemInfo().getWebInfRfsPath()));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_PROPERTY_FILE_1,
                getSystemInfo().getConfigurationFileRfsPath()));
            CmsLog.INIT.info(Messages.get().getBundle().key(
                Messages.INIT_LOG_FILE_1,
                getSystemInfo().getLogFileRfsPath()));
        }

        // initialize the configuration
        initConfiguration(configuration);
    }

    /**
     * Initialize member variables.<p>
     */
    protected void initMembers() {

        synchronized (LOCK) {
            m_resourceInitHandlers = new ArrayList();
            m_requestHandlers = new HashMap();
            m_systemInfo = new CmsSystemInfo();
            m_exportPoints = Collections.EMPTY_SET;
            m_defaultUsers = new CmsDefaultUsers();
            m_localeManager = new CmsLocaleManager(Locale.ENGLISH);
            m_sessionManager = new CmsSessionManager();
            m_runtimeProperties = new Hashtable();
            // the default event manager must be available because the configuration already registers events 
            m_eventManager = new CmsEventManager();
        }
    }

    /**
     * Reads the requested resource from the OpenCms VFS,
     * in case a directory name is requested, the default files of the 
     * directory will be looked up and the first match is returned.<p>
     *
     * The resource that is returned is always a <code>{@link org.opencms.file.CmsFile}</code>,
     * even though the content will usually not be loaded in the result. Folders are never returned since
     * the point of this method is really to load the default file if just a folder name is requested.<p>
     *
     * The URI stored in the given OpenCms user context will be changed to the URI of the resource 
     * that was found and returned.<p>
     * 
     * Implementing and configuring an <code>{@link I_CmsResourceInit}</code> handler 
     * allows to customize the process of default resource selection.<p>
     *
     * @param cms the current users OpenCms context
     * @param resourceName the path of the requested resource in the OpenCms VFS
     * @param req the current http request
     * @param res the current http response
     * 
     * @return the requested resource read from the VFS
     * 
     * @throws CmsException in case the requested file does not exist or the user has insufficient access permissions
     * 
     * @see OpenCms#initResource(CmsObject, String, HttpServletRequest, HttpServletResponse)
     */
    protected CmsResource initResource(
        CmsObject cms,
        String resourceName,
        HttpServletRequest req,
        HttpServletResponse res) throws CmsException {

        CmsResource resource = null;
        CmsException tmpException = null;

        try {
            // try to read the requested resource
            resource = cms.readResource(resourceName);
            // resource exists, lets check if we have a file or a folder
            if (resource.isFolder()) {
                // the resource is a folder, check if PROPERTY_DEFAULT_FILE is set on folder
                try {
                    String defaultFileName = cms.readPropertyObject(
                        CmsResource.getFolderPath(cms.getSitePath(resource)),
                        CmsPropertyDefinition.PROPERTY_DEFAULT_FILE,
                        false).getValue();
                    if (defaultFileName != null) {
                        // property was set, so look up this file first
                        String tmpResourceName = CmsResource.getFolderPath(cms.getSitePath(resource)) + defaultFileName;
                        resource = cms.readResource(tmpResourceName);
                        // no exception? so we have found the default file                         
                        cms.getRequestContext().setUri(tmpResourceName);
                    }
                } catch (CmsSecurityException se) {
                    // permissions deny access to the resource
                    throw se;
                } catch (CmsException e) {
                    // ignore all other exceptions and continue the lookup process
                }
                if (resource.isFolder()) {
                    // resource is (still) a folder, check default files specified in configuration
                    for (int i = 0; i < m_defaultFiles.size(); i++) {
                        String tmpResourceName = CmsResource.getFolderPath(cms.getSitePath(resource))
                            + m_defaultFiles.get(i);
                        try {
                            resource = cms.readResource(tmpResourceName);
                            // no exception? So we have found the default file                         
                            cms.getRequestContext().setUri(tmpResourceName);
                            // stop looking for default files   
                            break;
                        } catch (CmsSecurityException se) {
                            // permissions deny access to the resource
                            throw se;
                        } catch (CmsException e) {
                            // ignore all other exceptions and continue the lookup process
                        }
                    }
                }
            }
            if (resource.isFolder()) {
                // we only want files as a result for further processing
                resource = null;
            }
        } catch (CmsException e) {
            // file or folder with given name does not exist, store exception
            tmpException = e;
            resource = null;
        }

        if (resource != null) {
            // test if this file is only available for internal access operations
            if ((resource.getFlags() & CmsResource.FLAG_INTERNAL) > 0) {
                throw new CmsException(Messages.get().container(
                    Messages.ERR_READ_INTERNAL_RESOURCE_1,
                    cms.getRequestContext().getUri()));
            }

            // check online project
            if (cms.getRequestContext().currentProject().isOnlineProject()) {
                // check if resource is secure
                boolean secure = Boolean.valueOf(
                    cms.readPropertyObject(cms.getSitePath(resource), CmsPropertyDefinition.PROPERTY_SECURE, true).getValue()).booleanValue();
                if (secure) {
                    // resource is secure, check site config
                    CmsSite site = CmsSiteManager.getCurrentSite(cms);
                    // check the secure url
                    boolean usingSec = req.getRequestURL().toString().toUpperCase().startsWith(
                        site.getSecureUrl().toUpperCase());
                    if (site.isExclusiveUrl() && !usingSec) {
                        resource = null;
                        // secure resource without secure protocol, check error config
                        if (site.isExclusiveError()) {
                            // trigger 404 error
                            throw new CmsVfsResourceNotFoundException(Messages.get().container(
                                Messages.ERR_REQUEST_SECURE_RESOURCE_0));
                        } else {
                            // redirect
                            String uri = req.getRequestURL().toString();
                            String target = site.getSecureUrl()
                                + uri.substring(uri.indexOf("/", uri.indexOf("//") + 2));
                            try {
                                res.sendRedirect(target);
                            } catch (Exception e) {
                                // ignore, but should never happen
                            }
                        }
                    }
                }
            }
        }

        // test if this file has to be checked or modified
        Iterator i = m_resourceInitHandlers.iterator();
        while (i.hasNext()) {
            try {
                resource = ((I_CmsResourceInit)i.next()).initResource(resource, cms, req, res);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -