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

📄 cmsxmltemplate.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            styleSheetUri = getStylesheet(cms, tagcontent, "frametemplate", doc, userObject);
        } // The original behaviour is to throw an exception in case no stylesheed could be found
        if (styleSheetUri == null) styleSheetUri = "";
        return styleSheetUri;
    }
                
    /**
     * Internal method to do the actual lookup of the "stylesheet" tag
     * on the subtemplate / element specified.
     * 
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param templatename The subtemplate / element to look up the "stylesheet" tag
     *   in, if null the mastertemplate is used.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @throws CmsException In case no stylesheet was found (or there were errors accessing the CmsObject)
     */
    private String getStylesheet(CmsObject cms, String tagcontent, String templatename, A_CmsXmlContent doc, Object userObject) throws CmsException {
        CmsXmlTemplateFile tempTemplateFile = (CmsXmlTemplateFile)doc;
        
        // If templatename==null look in the master template
        CmsXmlTemplateFile templateFile = tempTemplateFile;
        
        if (templatename != null) {
            // Get the XML parsed content of the selected template file.
            // This can be done by calling the getOwnTemplateFile() method of the
            // mastertemplate class.
            // The content is needed to determine the HTML style of the body element.
            Object tempObj = CmsTemplateClassManager.getClassInstance(cms, tempTemplateFile.getSubtemplateClass(templatename));
            CmsXmlTemplate frameTemplateClassObject = (CmsXmlTemplate)tempObj;
            templateFile = frameTemplateClassObject.getOwnTemplateFile(cms, tempTemplateFile.getSubtemplateFilename(templatename), null, null, null);
        }
        
        // Get the styles from the parameter hashtable
        String styleIE = null;
        String styleNS = null;
        if(templateFile.hasData("stylesheet-ie")) {
            styleIE = templateFile.getDataValue("stylesheet-ie");
        }
        else {
            if(templateFile.hasData("stylesheet")) {
                styleIE = templateFile.getDataValue("stylesheet");
            }
            else {
                styleIE = "";
            }
        }
        if(templateFile.hasData("stylesheet-ns")) {
            styleNS = templateFile.getDataValue("stylesheet-ns");
        }
        else {
            if(templateFile.hasData("stylesheet")) {
                styleNS = templateFile.getDataValue("stylesheet");
            }
            else {
                styleNS = "";
            }
        }

        HttpServletRequest orgReq = (HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest();
        String servletPath = cms.getRequestContext().getRequest().getServletUrl();
        if(!servletPath.endsWith("/")){
            // Make sure servletPath always end's with a "/"
            servletPath = cms.getRequestContext().getRequest().getServletUrl() + "/";
        }

        // Make sure we don't have a double "/" in the style sheet path
        if (styleIE.startsWith("/")) styleIE = styleIE.substring(1);
        if (styleNS.startsWith("/")) styleNS = styleNS.substring(1);

        // Get the user's browser
        String browser = orgReq.getHeader("user-agent");
        if ((browser!= null) && (browser.indexOf("MSIE") > -1)) {
            return ("".equals(styleIE))?"":servletPath + styleIE;
        } else {
            // return NS style as default value
            return ("".equals(styleNS))?"":servletPath + styleNS;
        }
     
    }
    
    /**
     * 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.
     */
    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.
     */
    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.
     */
    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;
            }
        }
    }

    /**
     * Inserts the document title into the template.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getTitle"&gt;</code>
     * in the template file.
     *
     * @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 of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @throws CmsException
     */
    public Object getTitle(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String requestedUri = cms.getRequestContext().getUri();
        String title = cms.readProperty(requestedUri, C_PROPERTY_TITLE);
        if(title == null) {
            return "";
        }
        return title;
    }
    
    /**
     * Inserts the document title into the template, escaping special and non - ASCII characters
     * with their HTML number representation (e.g. &amp; becomes &amp;#38;).<p>
     * 
     * This method can be called using <code>&lt;METHOD name="getTitleEscaped"&gt;</code>
     * in the template file.
     *
     * @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 of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @throws CmsException
     */
    public Object getTitleEscaped(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String requestedUri = cms.getRequestContext().getUri();
        String title = cms.readProperty(requestedUri, C_PROPERTY_TITLE);
        if(title == null) {
            return "";
        }
        return Encoder.escapeHtml(title);
    }
    
    /**
     * Inserts the correct document description into the template.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getDescription"&gt;</code>
     * in the template file.
     *
     * @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 of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @throws CmsException
     */
    public Object getDescription(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String requestedUri = cms.getRequestContext().getUri();
        String description = cms.readProperty(requestedUri, C_PROPERTY_DESCRIPTION);
        if(description == null) {
            description = "";
        }
        return description;
    }

    /**
     * Inserts the value of the given property in the template.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getProperty"&gt;</code>
     * in the template file.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent The name of the property.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @throws CmsException
     */
    public Object getProperty(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String requestedUri = cms.getRequestContext().getUri();

⌨️ 快捷键说明

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