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

📄 cmsxmltemplate.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                query = paramQuery.substring(0,paramQuery.length()-1).toString();
            }
        } catch (Exception exc){
            exc.printStackTrace();
        }

        // get the parameters in the tagcontent
        if((tagcontent != null) && (!"".equals(tagcontent))){
            if(tagcontent.startsWith("?")){
                tagcontent = tagcontent.substring(1);
            }
            query = tagcontent +"&" + query;
        }
        return getUri(cms, query, doc, userObject);
    }

    /**
     * Indicates if the current template class is able to stream it's results
     * directly to the response oputput stream.
     * <P>
     * Classes must not set this feature, if they might throw special
     * exception that cause HTTP errors (e.g. 404/Not Found), or if they
     * might send HTTP redirects.
     * <p>
     * If a class sets this feature, it has to check the
     * isStreaming() property of the RequestContext. If this is set
     * to <code>true</code> the results must be streamed directly
     * to the output stream. If it is <code>false</code> the results
     * must not be streamed.
     * <P>
     * Complex classes that are able top include other subtemplates
     * have to check the streaming ability of their subclasses here!
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public boolean isStreamable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return true;
    }

    /**
     * Collect caching informations from the current template class.
     * <P>
     * Complex classes that are able to include other subtemplates
     * have to check the streaming ability of their subclasses here!
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public CmsCacheDirectives collectCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {

        // Frist build our own cache directives.
        boolean isCacheable = isCacheable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isProxyPrivateCacheable = isProxyPrivateCacheable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isProxyPublicCacheable = isProxyPublicCacheable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isExportable = isExportable(cms, templateFile, elementName, parameters, templateSelector);
        boolean isStreamable = isStreamable(cms, templateFile, elementName, parameters, templateSelector);
        CmsCacheDirectives result = new CmsCacheDirectives(isCacheable, isProxyPrivateCacheable, isProxyPublicCacheable, isExportable, isStreamable);

        // Collect all subelements of this page
        CmsXmlTemplateFile doc = null;
        Vector subtemplates = null;
        try {
            doc = this.getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
            doc.init(cms, templateFile);
            subtemplates = doc.getAllSubElements();

            // Loop through all subelements and get their cache directives
            int numSubtemplates = subtemplates.size();
            for(int i = 0;i < numSubtemplates;i++) {
                String elName = (String)subtemplates.elementAt(i);
                String className = null;
                String templateName = null;

                className = getTemplateClassName(elName, doc, parameters);
                templateName = getTemplateFileName(elName, doc, parameters);

                if(className != null) {
                    I_CmsTemplate templClass = (I_CmsTemplate)CmsTemplateClassManager.getClassInstance(cms, className);
                    CmsCacheDirectives cd2 = templClass.collectCacheDirectives(cms, templateName, elName, parameters, null);
                    /*System.err.println("*                INT PUB PRV EXP STR");
                    debugPrint(elementName, result.m_cd);
                    System.err.println(" ");
                    debugPrint(elName, cd2.m_cd);
                    System.err.println(" " + templClass.getClass());
                    System.err.println("*                -------------------");*/

                    //result.merge(templClass.collectCacheDirectives(cms, templateName, elName, parameters, null));
                    result.merge(cd2);
                    /*debugPrint(elementName, result.m_cd);
                    System.err.println(" ");
                    System.err.println("* ");*/
                } else {
                    // This template file includes a subelement not exactly defined.
                    // The name of it's template class is missing at the moment, so
                    // we cannot say anything about the cacheablility.
                    // Set it to false.
                    return new CmsCacheDirectives(false);
                }
            }
        }
        catch(CmsException e) {
            if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                A_OpenCms.log(C_OPENCMS_INFO, getClassName() + "Cannot determine cache directives for my template file " + templateFile + " (" + e + "). ");
                A_OpenCms.log(C_OPENCMS_INFO, getClassName() + "Resuming normal operation, setting cacheability to false.");
                return new CmsCacheDirectives(false);
            }
        }
        return result;

    }

    /**
     * gets the caching information from the current template class.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {

        // First build our own cache directives.
        CmsCacheDirectives result = new CmsCacheDirectives(true);
        Vector para = new Vector();
        para.add("cmsframe");
        result.setCacheParameters(para);
        return result;
    }

    /**
     *  gets the caching information for a specific methode.
     *  @param cms the cms object.
     *  @param methodName the name of the method for witch the MethodCacheDirectives are wanted.
     */
    public CmsMethodCacheDirectives getMethodCacheDirectives(CmsObject cms, String methodName){
        if("getTitle".equals(methodName) || "getUri".equals(methodName)
                                         || "getFileUri".equals(methodName)
                                         || "getDescription".equals(methodName)
                                         || "getKeywords".equals(methodName)
                                         || "getProperty".equals(methodName)
                                         || "getPathUri".equals(methodName)){
            CmsMethodCacheDirectives mcd = new CmsMethodCacheDirectives(true);
            mcd.setCacheUri(true);
            return mcd;
        }
        if ("getFrameQueryString".equals(methodName)
                                || "getQueryString".equals(methodName)
                                || "getRequestIp".equals(methodName)
                                || "getSessionId".equals(methodName)
                                || "getUriWithParameter".equals(methodName)
                                || "parameters".equals(methodName)
                                || "getStylesheet".equals(methodName)){
            return new CmsMethodCacheDirectives(false);
        }
        return null;
    }

    /**
     * Tests, if the template cache is setted.
     * @return <code>true</code> if setted, <code>false</code> otherwise.
     */
    public final boolean isTemplateCacheSet() {
        return m_cache != null;
    }

    /**
     * For debugging purposes only.
     * Prints out all parameters.
     * <P>
     * May be called from the template file using
     * <code>&lt;METHOD name="parameters"&gt;</code>.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return Debugging information about all parameters.
     */
    public String parameters(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) {
        Hashtable param = (Hashtable)userObject;
        Enumeration keys = param.keys();
        String s = "";
        while(keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            s = s + "<B>" + key + "</B>: " + param.get(key) + "<BR>";
        }
        s = s + "<B>" + tagcontent + "</B><BR>";
        return s;
    }

    /**
     * Set the instance of template cache that should be used to store
     * cacheable results of the subtemplates.
     * If the template cache is not set, caching will be disabled.
     * @param c Template cache to be used.
     */
    public final void setTemplateCache(I_CmsTemplateCache c) {
        m_cache = c;
    }

    /**
     * Indicates if a previous cached result should be reloaded.
     * <P>
     * <em>not implemented.</em> Returns always <code>false</code>.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <code>false</code>
     */
    public boolean shouldReload(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }

    /**
     * Saves the dependencies for this elementvariante.
     * We save the deps two ways.
     * First we have an so called extern Hashtable where we use as key a resource
     * (represented by a String) and as values an Vector with all ElementVariants
     * that depend on this resource (again represented by a String in which we save
     * the variant and the element it is in)
     * The second saveplace is the elementvariant itselv. The intern way to save.
     * There we store which resoucess affect this variant.
     *
     * @param cms The cms object.
     * @param templateName.
     * @param elementName only needed for getCachDirectives, if it is not used there it may be null
     * @param templateSelector only needed for getCachDirectives, if it is not used there it may be null
     * @param parameters.
     * @param vfsDeps A vector (of CmsResource objects) with the resources that variant depends on.
     * @param cosDeps A vector (of CmsContentDefinitions) with the cd-resources that variant depends on.
     * @param cosClassDeps A vector (of Class objects) with the contentdefinitions that variant depends on.
     */
    protected void registerVariantDeps(CmsObject cms, String templateName, String elementName,
                        String templateSelector, Hashtable parameters, Vector vfsDeps,
                        Vector cosDeps, Vector cosClassDeps) throws CmsException {

        String cacheKey = getCacheDirectives(cms, templateName, elementName,
                                parameters, templateSelector).getCacheKey(cms, parameters);
        if(cms.getRequestContext().isElementCacheEnabled() && (cacheKey != null) &&
                (cms.getRequestContext().currentProject().equals(cms.onlineProject()) )) {
            boolean exportmode = cms.getMode() == cms.C_MODUS_EXPORT;
            Hashtable externVarDeps = cms.getVariantDependencies();
            long exTimeForVariant = Long.MAX_VALUE;
            long now = System.currentTimeMillis();
            // this will be the entry for the extern hashtable
            String variantEntry = getClass().getName() + "|"+ templateName +"|"+ cacheKey;

            // the vector for the intern variant store. it contains the keys for the extern Hashtable
            Vector allDeps = new Vector();
            // first the dependencies for the cos system
            if(cosDeps != null){
                for (int i = 0; i < cosDeps.size(); i++){
                    A_CmsContentDefinition contentDef = (A_CmsContentDefinition)cosDeps.elementAt(i);
                    String key = cms.getSiteName() + cms.C_ROOTNAME_COS + "/"+contentDef.getClass().getName() +"/"+contentDef.getUniqueId(cms);
                    if(exportmode){
                        cms.getRequestContext().addDependency(key);
                    }
                    allDeps.add(key);

⌨️ 快捷键说明

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