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

📄 cmsxmltemplate.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        }
                    }
                }
            }
            else {
                if(!tagcontent.equals("")) {
                    query = query + "&cmsframe=" + frame;
                }
            }
            if(!query.equals("")) {
                query = "?" + query;
            }
        }
        else {
            if(!frame.equals("")) {
                query = "?cmsframe=" + frame;
            }
        }
        if(!query.equals("")) {
            query = query + param;
        }
        else {
            query = "?" + param.substring(param.indexOf("&") + 1);
        }
        if (query.trim().equals("?") || query.trim().equals("&") || query.trim().equals("?&") ||
            query.trim().equals("??")) {
            query="";
        }
        return query;
    }

    /**
     * Gets the target for a link.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getCmsFrame"&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.
     * @exception CmsException
     */
    public Object getFrameTarget(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String target = "";
        String cmsframe = (String)((Hashtable)userObject).get("cmsframe");
        cmsframe = (cmsframe == null ? "" : cmsframe);
        if(cmsframe.equals("plain")) {
            target = "";
        }else {
            if(tagcontent.equals("")) {
                target = "target=_top";
            }else {
                target = "target=" + tagcontent;
            }
        }
        return target;
    }

    /**
     * Gets the key that should be used to cache the results of
     * <EM>this</EM> template class.
     * <P>
     * Since our results may depend on the used template file,
     * the parameters and the requested body document, we must
     * build a complex key using this three arguments.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return key that can be used for caching
     */
    public Object getKey(CmsObject cms, String templateFile, Hashtable parameters, String templateSelector) {

        //Vector v = new Vector();
        CmsRequestContext reqContext = cms.getRequestContext();

        //v.addElement(reqContext.currentProject().getName());
        //v.addElement(reqContext.getUri());
        //v.addElement(templateFile);
        //v.addElement(parameters);
        //v.addElement(templateSelector);
        //return v;
        String result = "" + reqContext.currentProject().getId() + ":" + reqContext.currentUser().getName() + reqContext.getUri() + templateFile;
        Enumeration keys = parameters.keys();
        while(keys.hasMoreElements()) {
            String key = (String)keys.nextElement();
            result = result + key + parameters.get(key);
        }
        result = result + templateSelector;
        return result;
    }

    /**
     * Reads in the template file and starts the XML parser for the expected
     * content type.
     * <P>
     * Every extending class using not CmsXmlTemplateFile as content type,
     * but any derived type should override this method.
     *
     * @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.
     */
    public CmsXmlTemplateFile getOwnTemplateFile(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
        CmsXmlTemplateFile xmlTemplateDocument = new CmsXmlTemplateFile(cms, templateFile);
        return xmlTemplateDocument;
    }

    /**
     * @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.
     * @exception CmsException
     */
    public Object getPathUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String path = cms.getRequestContext().getUri();
        path = path.substring(0, path.lastIndexOf("/") + 1);
        path = cms.getRequestContext().getRequest().getServletUrl() + path;
        return path.getBytes();
    }

    /**
     * Inserts the correct servlet path 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.
     * @exception CmsException
     */
    public Object getQueryString(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        String query = "";
        if(cms.getMode() == cms.C_MODUS_EXPORT){
            Enumeration parameters = cms.getRequestContext().getRequest().getParameterNames();
            if(parameters == null){
                return query;
            }
            StringBuffer paramQuery = new StringBuffer();
            while(parameters.hasMoreElements()){
                String name = (String)parameters.nextElement();
                String value = (String)((Hashtable)userObject).get(name);
                if(value != null && !"".equals(value)){
                    paramQuery.append(name+"="+value+"&");
                }
            }
            if(paramQuery.length() > 0){
                query = paramQuery.substring(0,paramQuery.length()-1).toString();
            }
        }else{
            query = ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getQueryString();
        }
        if(query != null && !"".equals(query)) {
            query = "?" + query;
        }
        return query;
    }

    /**
     * Get the IP address of the current request.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getRequestIp"&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.
     * @exception CmsException
     */
    public String getRequestIp(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        return ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getRemoteAddr();
    }

    /**
     * Inserts the correct servlet path 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.
     * @exception CmsException
     * @deprecated instead of this method you should use the link tag.
     */
    public Object getServletPath(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        return cms.getRequestContext().getRequest().getServletUrl() + "/";
    }

    /**
     * Get the session id. If no session exists, a new one will be created.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getSessionId"&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.
     * @exception CmsException
     */
    public String getSessionId(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        return ((HttpServletRequest)cms.getRequestContext().getRequest().getOriginalRequest()).getSession(true).getId();
    }

    /**
     * Inserts the correct stylesheet into the layout template.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getStylesheet"&gt;</code>
     * in the template file.
     * <P>
     * When using this method follwing parameters should be defined
     * either in the page file or in the template file:
     * <ul>
     * <li><code>root.stylesheet-ie</code></li>
     * <li><code>root.stylesheet-ns</code></li>
     * </ul>
     * These parameters should contain the correct OpenCms path
     * for the Internet Explorer and Netscape Navigate
     * specific stylesheets.
     *
     * @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.
     * @exception CmsException
     */
    public String getStylesheet(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        CmsXmlTemplateFile tempTemplateFile = (CmsXmlTemplateFile)doc;

        // Get the XML parsed content of the frametemplate 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("frametemplate"));
        CmsXmlTemplate frameTemplateClassObject = (CmsXmlTemplate)tempObj;
        CmsXmlTemplateFile templateFile = frameTemplateClassObject.getOwnTemplateFile(cms, tempTemplateFile.getSubtemplateFilename("frametemplate"), 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");
        }

⌨️ 快捷键说明

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