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

📄 cmsxmltemplate.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (parameterTags != null) {
            int numParameterTags = parameterTags.size();
            for (int i = 0; i < numParameterTags; i++) {
                String paramName = (String)parameterTags.elementAt(i);
                String paramValue = templateFile.getParameter(tagcontent, paramName);
                if (!parameterHashtable.containsKey(paramName)) {
                    parameterHashtable.put(tagcontent + "." + paramName, paramValue);
                }
            }
        }

        // all parameters are now parsed. Finally give the own subelement name
        // as parameter
        parameterHashtable.put(C_ELEMENT, tagcontent);

        // Try to get the result from the cache
        //if(subTemplate.isCacheable(cms, templateFilename, tagcontent, parameterHashtable, null)) {
        if (subTemplate.collectCacheDirectives(cms, templateFilename, tagcontent, parameterHashtable, null).isInternalCacheable()) {
            subTemplateKey = subTemplate.getKey(cms, templateFilename, parameterHashtable, null);
            if (m_cache != null
                && m_cache.has(subTemplateKey)
                && (!subTemplate.shouldReload(cms, templateFilename, tagcontent, parameterHashtable, null))) {
                result = m_cache.get(subTemplateKey);
            }
        }

        // OK. let's call the subtemplate
        if (result == null) {
            try {
                result = subTemplate.getContent(cms, templateFilename, tagcontent, parameterHashtable, templateSelector);
            } catch (Exception e) {

                // Oh, oh..

                // There were errors while getting the content of the subtemplate
                if (CmsLog.getLog(this).isErrorEnabled()) {
                    CmsLog.getLog(this).error("Could not generate output for template file \""
                        + templateFilename + "\" included as element \"" + tagcontent + "\"", e);
                }

                // The anonymous user gets an error String instead of an exception
                if (isAnonymousUser) {
                    return C_ERRORTEXT;
                } else {
                    if (e instanceof CmsException) {
                        throw (CmsException)e;
                    } else {
                        throw new CmsLegacyException(
                            "Error while executing getContent for subtemplate \"" + tagcontent
                                + "\". " + e);
                    }
                }
            }

            // Store the results in the template cache, if cacheable
            //if(subTemplate.isCacheable(cms, templateFilename, tagcontent, parameterHashtable, null)) {
            if (subTemplate.collectCacheDirectives(cms, templateFilename, tagcontent, parameterHashtable, null).isInternalCacheable()
                && m_cache != null) {

                // we don't need to re-get the caching-key here since it already exists
                m_cache.put(subTemplateKey, result);
            }
        }
        return new CmsProcessedString(result, cms.getRequestContext().getEncoding());
    }

    /**
     * Find the corresponding template class to be loaded.
     * this should be defined in the template file of the parent
     * template and can be overwritten in the body file.
     *
     * @param elementName Element name of this template in our parent template.
     * @param doc CmsXmlTemplateFile object of our template file including a subtemplate.
     * @param parameters Hashtable with all template class parameters.
     * @return Name of the class that should generate the output for the included template file.
     * @throws CmsException if something goes wrong
     */
    protected String getTemplateClassName(String elementName, CmsXmlTemplateFile doc,
        Hashtable parameters) throws CmsException {

        String result = null;
        if (parameters.containsKey(elementName + "._CLASS_")) {
            result = (String)parameters.get(elementName + "._CLASS_");
        } else {
            if (doc.hasSubtemplateClass(elementName)) {
                result = doc.getSubtemplateClass(elementName);
            } else {

                // Fallback to "body" element
                if (parameters.containsKey("body._CLASS_")) {
                    result = (String)parameters.get("body._CLASS_");
                }
            }
        }
        if (result == null) {
            CmsElementDefinitionCollection elDefs = (CmsElementDefinitionCollection)parameters.get("_ELDEFS_");
            if (elDefs != null) {
                CmsElementDefinition elDef = elDefs.get(elementName);
                if (elDef != null) {
                    result = elDef.getClassName();
                }
            }
        }
        return result;
    }

    /**
     * Find the corresponding template file to be loaded by the template class.
     * this should be defined in the template file of the parent
     * template and can be overwritten in the body file.
     *
     * @param elementName Element name of this template in our parent template.
     * @param doc CmsXmlTemplateFile object of our template file including a subtemplate.
     * @param parameters Hashtable with all template class parameters.
     * @return Name of the template file that should be included.
     * @throws CmsException if something goes wrong
     */
    protected String getTemplateFileName(String elementName, CmsXmlTemplateFile doc,
        Hashtable parameters) throws CmsException {

        String result = null;
        if (parameters.containsKey(elementName + "._TEMPLATE_")) {
            result = (String)parameters.get(elementName + "._TEMPLATE_");
        } else {
            if (doc.hasSubtemplateFilename(elementName)) {
                result = doc.getSubtemplateFilename(elementName);
            } else {
                // Fallback to "body" element
                if (parameters.containsKey("body._TEMPLATE_")) {
                    result = (String)parameters.get("body._TEMPLATE_");
                }
            }
        }
        if (result == null) {
            CmsElementDefinitionCollection elDefs = (CmsElementDefinitionCollection)parameters.get("_ELDEFS_");
            if (elDefs != null) {
                CmsElementDefinition elDef = elDefs.get(elementName);
                if (elDef != null) {
                    result = elDef.getTemplateName();
                }
            }
        }
        return result;
    }

    /**
     * Find the corresponding template selector to be activated.
     * This may be defined in the template file of the parent
     * template and can be overwritten in the body file.
     *
     * @param elementName Element name of this template in our parent template.
     * @param doc CmsXmlTemplateFile object of our template file including a subtemplate.
     * @param parameters Hashtable with all template class parameters.
     * @return Name of the class that should generate the output for the included template file.
     * @throws CmsException if something goes wrong
     */
    protected String getTemplateSelector(String elementName, CmsXmlTemplateFile doc,
        Hashtable parameters) throws CmsException {

        if (parameters.containsKey(elementName + "._TEMPLATESELECTOR_")) {
            return (String)parameters.get(elementName + "._TEMPLATESELECTOR_");
        } else {
            if (doc.hasSubtemplateSelector(elementName)) {
                return doc.getSubtemplateSelector(elementName);
            } else {
                CmsElementDefinitionCollection elDefs = (CmsElementDefinitionCollection)parameters.get("_ELDEFS_");
                if (elDefs != null) {
                    CmsElementDefinition elDef = elDefs.get(elementName);
                    if (elDef != null) {
                        return elDef.getTemplateSelector();
                    }
                }
                return null;
            }
        }
    }

    /**
     * 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 (CmsXmlTemplateLoader.isElementCacheEnabled() && (cacheKey != null)
            && (cms.getRequestContext().currentProject().isOnlineProject())) {
            boolean exportmode = false;
            Hashtable externVarDeps = CmsXmlTemplateLoader.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.getRequestContext().addSiteRoot(contentDef.getClass().getName()
                        + "/" + contentDef.getUniqueId(cms));
                    //                    if(exportmode){
                    //                        cms.getRequestContext().addDependency(key);
                    //                    }
                    allDeps.add(key);
                    if (contentDef.isTimedContent()) {
                        long time = ((I_CmsTimedContentDefinition)cosDeps.elementAt(i)).getPublicationDate();
                        if (time > now && time < exTimeForVariant) {
                            exTimeForVariant = time;
                        }
                        time = ((I_CmsTimedContentDefinition)cosDeps.elementAt(i)).getPurgeDate();
                        if (time > now && time < exTimeForVariant) {
                            exTimeForVariant = time;
                        }
                        time = ((I_CmsTimedContentDefinition)cosDeps.elementAt(i)).getAdditionalChangeDate();
                        if (time > now && time < exTimeForVariant) {
                            exTimeForVariant = time;
                        }
                    }
                }
            }
            //            // now for the Classes
            //            if(cosClassDeps != null){
            //                for(int i=0; i<cosClassDeps.size(); i++){
            //                    String key = cms.getRequestContext().addSiteRoot(((Class)cosClassDeps.elementAt(i)).getName() + "/");
            //                    allDeps.add(key);
            //                    if(exportmode){
            //                        cms.getRequestContext().addDependency(key);
            //                    }
            //                }
            //            }
            // now for the vfs
            //            if(vfsDeps != null){
            //                for(int i = 0; i < vfsDeps.size(); i++){
            //                    allDeps.add(((CmsResource)vfsDeps.elementAt(i)).getName());
            //                    if(exportmode){
            //                        cms.getRequestContext().addDependency(((CmsResource)vfsDeps.elementAt(i)).getName());
            //                    }
            //                }
            //            }
            // now put them all in the extern store
            for (int i = 0; i < allDeps.size(); i++) {
                String key = (String)allDeps.elementAt(i);
                Vector variantsForDep = (Vector)externVarDeps.get(key);
                if (variantsForDep == null) {
                    variantsForDep = new Vector();
                }
                if (!variantsForDep.contains(variantEntry)) {
                    variantsForDep.add(variantEntry);
                }
                externVarDeps.put(key, variantsForDep);
            }
            // at last we have to fill the intern store. that means we have to
            // put the alldeps vector in our variant that will be created later
            // in the startproccessing method.
            // Get current element.
            CmsElementCache elementCache = CmsXmlTemplateLoader.getElementCache();
            CmsElementDescriptor elKey = new CmsElementDescriptor(getClass().getName(),
                templateName);
            A_CmsElement currElem = elementCache.getElementLocator().get(cms, elKey, parameters);
            // add an empty variant with the vector to the element
            CmsElementVariant emptyVar = new CmsElementVariant();
            emptyVar.addDependencies(allDeps);
            if (exTimeForVar

⌨️ 快捷键说明

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