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

📄 opencms.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            String extern = conf.getString("linkrules."+exportDefault+".extern");
            String[] linkRulesExtern;
            if(extern != null && !"".equals(extern)){
                linkRulesExtern = conf.getStringArray("ruleset."+extern);
                // now replace ${WEB_APP_NAME} with the correct name of the webapplication and replace the other variables
                for(int i = 0; i < linkRulesExtern.length; i++) {
                    linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], C_WEB_APP_REPLACE_KEY, CmsBase.getWebAppName());
                    linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_EXPORT+"}", staticUrlPrefix[0]);
                    linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_HTTP+"}", staticUrlPrefix[1]);
                    linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_HTTPS+"}", staticUrlPrefix[2]);
                    linkRulesExtern[i] = Utils.replace(linkRulesExtern[i], "${"+C_URL_PREFIX_SERVERNAME+"}", staticUrlPrefix[3]);
                }
                c_exportProperties.setLinkRulesExtern(linkRulesExtern);
            }
            c_exportProperties.setStartRule(null); // temporary out of order: conf.getString("exportfirstrule");

            Vector staticExportStart=new Vector();
            staticExportStart.add("/");
            c_exportProperties.setStartPoints(staticExportStart);

            // at last the target for the export
            c_exportProperties.setExportPath( com.opencms.boot.CmsBase.getAbsoluteWebPath(CmsBase.getAbsoluteWebPath(conf.getString(C_STATICEXPORT_PATH))));

            // should the links in static export be relative?
            c_exportProperties.setExportRelativeLinks(conf.getBoolean("relativelinks_in_export", false));
            // is the static export enabled?
            String activCheck = conf.getString("staticexport.enabled", "false");
            c_exportProperties.setStaticExportEnabledValue(activCheck);
            if("true".equalsIgnoreCase(activCheck)){
                c_exportProperties.setStaticExportEnabled(true);
            }else{
                c_exportProperties.setStaticExportEnabled(false);
            }
            if(c_exportProperties.isStaticExportEnabled()){
                // we have to generate the dynamic rulessets
                createDynamicLinkRules();
            }else{
                if("false_ssl".equalsIgnoreCase(activCheck)){
                    // no static esport, but we need the dynamic rules for setting the protokoll to https
                    c_exportProperties.setLinkRulesOffline(new String[]{"s#^#" + staticUrlPrefix[1] + "#"});
                    c_exportProperties.setLinkRulesOnline(new String[]{"*dynamicRules*", "s#^#" + staticUrlPrefix[1] + "#"});
                    // and we have to change the standart export prefix to stay in opencms
                    c_exportProperties.getUrlPrefixArray()[0] = staticUrlPrefix[1];
                    // if we need them we should create them
                    createDynamicLinkRules();
                }else{
                    // no static export. We need online and offline rules to stay in OpenCms.
                    // we generate them with the url_prefix_http so the user can still configure
                    // the servletpath.
                    c_exportProperties.setLinkRulesOffline(new String[]{"s#^#" + staticUrlPrefix[1] + "#"});
                    c_exportProperties.setLinkRulesOnline(new String[]{"s#^#" + staticUrlPrefix[1] + "#"});
                }
            }
            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Link rules init      : finished");
        }catch(Exception e){
            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Link rules init      : non-critical error " + e.toString());
        }
        
        // initialize 1 instance per class listed in the checkresource node
        try{
            Hashtable checkresourceNode = getRegistry().getSystemValues( "checkresource" );
            if (checkresourceNode!=null) {
                for (int i=1;i<=checkresourceNode.size();i++) {
                    String currentClass = (String)checkresourceNode.get( "class" + i );
                    try {
                        m_checkFile.add(Class.forName(currentClass).newInstance());
                             if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Checkfile class init : " + currentClass + " instanciated");
                    } catch (Exception e1){
                        if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Checkfile class init : non-critical error " + e1.toString());
                    }
                }
            }
        } catch (Exception e2){
            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Checkfile class init : non-critical error " + e2.toString());
        }
    }

    /**
     * Creates the dynamic linkrules.
     * The CmsStaticExport class needs a CmsObject to create them.
     */
    private void createDynamicLinkRules(){
        //create a valid cms-object
        CmsObject cms = new CmsObject();
        try{
            initUser(cms, null, null, C_USER_ADMIN, C_GROUP_ADMIN, C_PROJECT_ONLINE_ID, null);
            new CmsStaticExport(cms, null, false, null, null, null, null);
        }catch(Exception e){
            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Dynamic link rules   : non-critical error " + e.toString());
        }
    }
    
    /**
     * Initialize the startup classes of this OpenCms object.<p>
     * 
     * A startup class has to be configured in the <code>registry.xml</code> 
     * file of OpenCms. Startup classes are a way to create plug-in 
     * functions that required to be initialized once at OpenCms load time 
     * without the need to add initializing code to the constructor of this 
     * class.<p>
     * 
     * This must be done only once per running OpenCms object instance.
     * Usually this will be done by the OpenCms servlet.
     * 
     * @param req the current request
     * @param res the current response 
     */
    void initStartupClasses(HttpServletRequest req, HttpServletResponse res) throws CmsException {
        if (m_isInitialized) return;

        synchronized (this) {
            // Set the initialized flag to true
            m_isInitialized = true;
            
            if (res == null) {
                // currently no init action depends on res, this might change in the future
            }
    
            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : starting");
    
            // set context once and for all
            String context = req.getContextPath() + req.getServletPath();
            if (! context.endsWith("/")) context += "/";
            A_OpenCms.setOpenCmsContext(context);
            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". OpenCms context      : " + context);
            
            // check for old webapp names and extend with context
            ArrayList webAppNames = (ArrayList)A_OpenCms.getRuntimeProperty("compatibility.support.webAppNames");
            if (webAppNames == null) {
                webAppNames = new ArrayList();
            } 
            if (! webAppNames.contains(context)) {
                webAppNames.add(context);
                setRuntimeProperty("compatibility.support.webAppNames", webAppNames);
            }            
    
            // check for the JSP export URL runtime property
            String jspExportUrl = (String)getRuntimeProperty(CmsJspLoader.C_LOADER_JSPEXPORTURL);
            if (jspExportUrl == null) {
                StringBuffer url = new StringBuffer(256);
                url.append(req.getScheme());
                url.append("://");
                url.append(req.getServerName());
                url.append(":");
                url.append(req.getServerPort());
                url.append(context);        
                String flexExportUrl = new String(url);    
                // check if the URL ends with a "/", this is not allowed
                if (flexExportUrl.endsWith(C_FOLDER_SEPARATOR)) {
                    flexExportUrl = flexExportUrl.substring(0, flexExportUrl.length()-1);
                }
                setRuntimeProperty(CmsJspLoader.C_LOADER_JSPEXPORTURL, flexExportUrl);
                CmsJspLoader.setJspExportUrl(flexExportUrl);
                if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". JSP export URL       : using value from first request - " + flexExportUrl);
            }
            
    
            // initialize 1 instance per class listed in the startup node
            try{
                Hashtable startupNode = getRegistry().getSystemValues( "startup" );
                if (startupNode!=null) {
                    for (int i=1;i<=startupNode.size();i++) {
                        String currentClass = (String)startupNode.get( "class" + i );
                        try {
                            Class.forName(currentClass).newInstance();
    
                            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : " + currentClass + " instanciated");
                        } catch (Exception e1){
                            if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : non-critical error " + e1.toString());
                        }
                    }
                }
            } catch (Exception e2){
                if(C_LOGGING && isLogging(C_OPENCMS_INIT)) log(C_OPENCMS_INIT, ". Startup class init   : non-critical error " + e2.toString());
            }
            
            if(C_LOGGING && A_OpenCms.isLogging(C_OPENCMS_INIT)) {
                A_OpenCms.log(C_OPENCMS_INIT, ". Startup class init   : finished");
                A_OpenCms.log(C_OPENCMS_INIT, ".                      ...............................................................");        
                A_OpenCms.log(C_OPENCMS_INIT, ".");        
            }    
        }
    }

    /**
     * Destructor, called when the the servlet is shut down.
     * 
     * @throws CmsException If something goes wrong during shutdown.
     */
    public void destroy() throws CmsException {
        if (m_scheduler!=null) {
            m_scheduler.shutDown();
        }
        
        if (m_resourceBroker!=null) {
            CmsObject cms = new CmsObject();
            cms.init(m_resourceBroker);
            cms.destroy();
        }
    }

    /**
     * Returns the launcher manager used.
     * 
     * @return The launcher manager used.
     */
    public CmsLauncherManager getLauncherManager() {
        return m_launcherManager;
    }

    /**
     * Returns the ElementCache used for the online project.
     * 
     * @return The ElementCache used for the online project.
     */
    public static CmsElementCache getOnlineElementCache(){
        return c_elementCache;
    }

    /**
     * Returns the Class that is used for the password validation.
     * 
     * @return The Class that is used for the password validation.
     */
    public static String getPasswordValidatingClass(){
        return c_passwordValidatingClass;
    }

    /**
     * Returns the properties for the static export.
     * 
     * @return The properties for the static export.
     */
    public static CmsStaticExportProperties getStaticExportProperties(){
        return c_exportProperties;
    }

    /**
     * Returns the hashtable with the variant dependencies used for the elementcache.
     * 
     * @return The hashtable with the variant dependencies used for the elementcache.
     */
    public static Hashtable getVariantDependencies(){
        return c_variantDeps;
    }
    
    /**
     * Returns the file name translator this OpenCms has read from the opencms.properties.
     * 
     * @return The file name translator this OpenCms has read from the opencms.properties
     */
    public CmsResourceTranslator getFileTranslator() {
        return m_fileTranslator;
    } 
    
    /**
     * This method reads the requested document from the OpenCms request context
     * and returns it to the calling module, which will usually be 

⌨️ 快捷键说明

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