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

📄 cmsjsptaginclude.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }

    /**
     * Includes the selected target using the Flex cache.<p>
     * 
     * @param controller the current JSP controller
     * @param context the current JSP page context
     * @param target the target for the include, might be <code>null</code>
     * @param parameterMap a map of parameters for the include
     * @param req the current request
     * @param res the current response
     *
     * @throws JspException in case something goes wrong
     */
    private static void includeActionWithCache(
        CmsFlexController controller,
        PageContext context,
        String target,
        Map parameterMap,
        ServletRequest req,
        ServletResponse res) throws JspException {

        try {
            // write out a FLEX_CACHE_DELIMITER char on the page, this is used as a parsing delimeter later
            context.getOut().print(CmsFlexResponse.FLEX_CACHE_DELIMITER);
            // add the target to the include list (the list will be initialized if it is currently empty)
            controller.getCurrentResponse().addToIncludeList(target, parameterMap);
            // now use the Flex dispatcher to include the target (this will also work for targets in the OpenCms VFS)
            controller.getCurrentRequest().getRequestDispatcher(target).include(req, res);
        } catch (ServletException e) {
            // store original Exception in controller in order to display it later
            Throwable t = (e.getRootCause() != null) ? e.getRootCause() : e;
            t = controller.setThrowable(t, target);
            throw new JspException(t);
        } catch (IOException e) {
            // store original Exception in controller in order to display it later
            Throwable t = controller.setThrowable(e, target);
            throw new JspException(t);
        }
    }

    /**
     * This methods adds parameters to the current request.<p>
     * 
     * Parameters added here will be treated like parameters from the 
     * HttpRequest on included pages.<p>
     * 
     * Remember that the value for a parameter in a HttpRequest is a 
     * String array, not just a simple String. If a parameter added here does
     * not already exist in the HttpRequest, it will be added. If a parameter 
     * exists, another value will be added to the array of values. If the 
     * value already exists for the parameter, nothing will be added, since a 
     * value can appear only once per parameter.<p>
     * 
     * @param name the name to add
     * @param value the value to add
     * @see org.opencms.jsp.I_CmsJspTagParamParent#addParameter(String, String)
     */
    public void addParameter(String name, String value) {

        // No null values allowed in parameters
        if ((name == null) || (value == null)) {
            return;
        }

        // Check if internal map exists, create new one if not
        if (m_parameterMap == null) {
            m_parameterMap = new HashMap();
        }

        addParameter(m_parameterMap, name, value, false);
    }

    /**
     * @return <code>EVAL_PAGE</code>
     * 
     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
     * 
     * @throws JspException by interface default
     */
    public int doEndTag() throws JspException {

        ServletRequest req = pageContext.getRequest();
        ServletResponse res = pageContext.getResponse();

        if (CmsFlexController.isCmsRequest(req)) {
            // this will always be true if the page is called through OpenCms 
            CmsObject cms = CmsFlexController.getCmsObject(req);
            String target = null;

            // try to find out what to do
            if (m_target != null) {
                // option 1: target is set with "page" or "file" parameter
                target = m_target + getSuffix();
            } else if (m_property != null) {
                // option 2: target is set with "property" parameter
                try {
                    String prop = cms.readPropertyObject(cms.getRequestContext().getUri(), m_property, true).getValue();
                    if (prop != null) {
                        target = prop + getSuffix();
                    }
                } catch (Exception e) {
                    // target will be null
                }
            } else if (m_attribute != null) {
                // option 3: target is set in "attribute" parameter
                try {
                    String attr = (String)req.getAttribute(m_attribute);
                    if (attr != null) {
                        target = attr + getSuffix();
                    }
                } catch (Exception e) {
                    // target will be null
                }
            } else {
                // option 4: target might be set in body
                String body = null;
                if (getBodyContent() != null) {
                    body = getBodyContent().getString();
                    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(body)) {
                        // target IS set in body
                        target = body + getSuffix();
                    }
                    // else target is not set at all, default will be used 
                }
            }

            // now perform the include action
            includeTagAction(pageContext, target, m_element, null, m_editable, m_cacheable, m_parameterMap, req, res);

            // must call release here manually to make sure m_parameterMap is cleared
            release();
        }

        return EVAL_PAGE;
    }

    /**
     * Returns <code>{@link #EVAL_BODY_BUFFERED}</code>.<p>
     * 
     * @return <code>{@link #EVAL_BODY_BUFFERED}</code>
     * 
     * @see javax.servlet.jsp.tagext.Tag#doStartTag()
     */
    public int doStartTag() {

        return EVAL_BODY_BUFFERED;
    }

    /**
     * Returns the attribute.<p>
     * 
     * @return the attribute
     */
    public String getAttribute() {

        return m_attribute != null ? m_attribute : "";
    }

    /**
     * Returns the cacheable flag.<p>
     * 
     * @return the cacheable flag
     */
    public String getCacheable() {

        return String.valueOf(m_cacheable);
    }

    /**
     * Returns the editable flag.<p>
     * 
     * @return the editable flag
     */
    public String getEditable() {

        return String.valueOf(m_editable);
    }

    /**
     * Returns the element.<p>
     * 
     * @return the element
     */
    public String getElement() {

        return m_element;
    }

    /**
     * Returns the value of <code>{@link #getPage()}</code>.<p>
     * 
     * @return the value of <code>{@link #getPage()}</code>
     * @see #getPage()
     */
    public String getFile() {

        return getPage();
    }

    /**
     * Returns the include page target.<p>
     * 
     * @return the include page target
     */
    public String getPage() {

        return m_target != null ? m_target : "";
    }

    /**
     * Returns the property.<p>
     * 
     * @return the property
     */
    public String getProperty() {

        return m_property != null ? m_property : "";
    }

    /**
     * Returns the suffix.<p>
     * 
     * @return the suffix
     */
    public String getSuffix() {

        return m_suffix != null ? m_suffix : "";
    }

    /**
     * @see javax.servlet.jsp.tagext.Tag#release()
     */
    public void release() {

        super.release();
        m_target = null;
        m_suffix = null;
        m_property = null;
        m_element = null;
        m_parameterMap = null;
        m_editable = false;
        m_cacheable = true;
    }

    /**
     * Sets the attribute.<p>
     * 
     * @param attribute the attribute to set
     */
    public void setAttribute(String attribute) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(attribute)) {
            m_attribute = attribute;
        }
    }

    /**
     * Sets the cacheable flag.<p>
     *
     * Cachable is <code>true</code> by default.<p>
     * 
     * @param cacheable the flag to set
     */
    public void setCacheable(String cacheable) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(cacheable)) {
            m_cacheable = Boolean.valueOf(cacheable).booleanValue();
        }
    }

    /**
     * Sets the editable flag.<p>
     * 
     * Editable is <code>false</code> by default.<p>
     * 
     * @param editable the flag to set
     */
    public void setEditable(String editable) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(editable)) {
            m_editable = Boolean.valueOf(editable).booleanValue();
        }
    }

    /**
     * Sets the element.<p>
     * 
     * @param element the element to set
     */
    public void setElement(String element) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(element)) {
            m_element = element;
        }
    }

    /**
     * Sets the file, same as using <code>setPage()</code>.<p>
     * 
     * @param file the file to set
     * @see #setPage(String)
     */
    public void setFile(String file) {

        setPage(file);
    }

    /**
     * Sets the include page target.<p>
     * 
     * @param target the target to set
     */
    public void setPage(String target) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(target)) {
            m_target = target;
        }
    }

    /**
     * Sets the property.<p>
     * 
     * @param property the property to set
     */
    public void setProperty(String property) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(property)) {
            m_property = property;
        }
    }

    /**
     * Sets the suffix.<p>
     * 
     * @param suffix the suffix to set
     */
    public void setSuffix(String suffix) {

        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(suffix)) {
            m_suffix = suffix.toLowerCase();
        }
    }
}

⌨️ 快捷键说明

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