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

📄 cmsjsptagcontentload.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagContentLoad.java,v $
 * Date   : $Date: 2006/03/27 14:52:19 $
 * Version: $Revision: 1.31 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.jsp;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.collectors.I_CmsResourceCollector;
import org.opencms.flex.CmsFlexController;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsMacroResolver;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.editors.I_CmsEditorActionHandler;
import org.opencms.xml.I_CmsXmlDocument;
import org.opencms.xml.content.CmsXmlContentFactory;

import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

/**
 * Used to access and display XML content item information from the VFS.<p>
 * 
 * @author  Alexander Kandzior 
 * 
 * @version $Revision: 1.31 $ 
 * 
 * @since 6.0.0 
 */
public class CmsJspTagContentLoad extends BodyTagSupport implements I_CmsXmlContentContainer {

    /** Serial version UID required for safe serialization. */
    private static final long serialVersionUID = 981176995635225294L;

    /** The CmsObject for the current user. */
    private CmsObject m_cms;

    /** The name of the collector to use for list building. */
    private String m_collector;

    /** The name of the content collector used. */
    private String m_collectorName;

    /** The parameters of the content collector uses. */
    private String m_collectorParam;

    /** The list of collected content items. */
    private List m_collectorResult;

    /** Reference to the last loaded content element. */
    private I_CmsXmlDocument m_content;

    /** The bean to store information required to make the result list browsable. */
    private CmsContentInfoBean m_contentInfoBean;

    /**
     * The locale to use for displaying the current content.<p>
     * 
     * Initially, this is equal to the locale set using <code>{@link #setLocale(String)}</code>. 
     * However, the content locale may change in case a loaded XML content does not have the selected locale available.
     * In this case the next default locale that is available in the content will be used as content locale.<p> 
     */
    private Locale m_contentLocale;

    /** The FlexController for the current request. */
    private CmsFlexController m_controller;

    /** The link for creation of a new element, specified by the selected collector. */
    private String m_directEditCreateLink;

    /** The "direct edit" options to use for the 2nd to the last element. */
    private String m_directEditFollowOptions;

    /** Indicates if the last element was ediable (including user permissions etc.). */
    private String m_directEditPermissions;

    /** The editable flag. */
    private boolean m_editable;

    /** Indicates if this is the first content iteration loop. */
    private boolean m_isFirstLoop;

    /** Refenence to the currently selected locale. */
    private Locale m_locale;

    /** The index of the current page that gets displayed. */
    private String m_pageIndex;

    /** The number of page links in the Google-like page navigation. */
    private String m_pageNavLength;

    /** The size of a page to be displayed. */
    private String m_pageSize;

    /** Paramter used for the collector. */
    private String m_param;

    /** Indicates if the collector results should be preloaded. */
    private boolean m_preload;

    /** The (optional) property to extend the parameter with. */
    private String m_property;

    /** The file name to load the current content value from. */
    private String m_resourceName;

    /**
     * Empty constructor, required for JSP tags.<p> 
     */
    public CmsJspTagContentLoad() {

        super();
    }

    /**
     * Constructor used when using <code>contentload</code> from scriptlet code.<p> 
     * 
     * @param container the parent content container (could be a preloader)
     * @param context the JSP page context
     * @param collectorName the collector name to use
     * @param collectorParam the collector param to use
     * @param locale the locale to use 
     * @param editable indicates if "direct edit" support is wanted
     * 
     * @throws JspException in case something goes wrong
     */
    public CmsJspTagContentLoad(
        I_CmsXmlContentContainer container,
        PageContext context,
        String collectorName,
        String collectorParam,
        Locale locale,
        boolean editable)
    throws JspException {

        setCollector(collectorName);
        setParam(collectorParam);
        m_locale = locale;
        m_contentLocale = locale;
        m_editable = editable;
        m_preload = false;

        setPageContext(context);
        init(container);
    }

    /**
     * Returns the resource name currently processed.<p> 
     * 
     * @param cms the current OpenCms user context
     * @param contentContainer the current content container
     * 
     * @return the resource name currently processed
     */
    protected static String getResourceName(CmsObject cms, I_CmsXmlContentContainer contentContainer) {

        if (contentContainer != null && contentContainer.getResourceName() != null) {
            return contentContainer.getResourceName();
        } else if (cms != null) {
            return cms.getRequestContext().getUri();
        } else {
            return null;
        }
    }

    /**
     * Limits the collector's result list to the size of a page to be displayed in a JSP.<p>
     * 
     * @param contentInfoBean the info bean of the collector
     * @param collectorResult the result list of the collector
     * 
     * @return a limited collector's result list
     */
    private static List limitCollectorResult(CmsContentInfoBean contentInfoBean, List collectorResult) {

        List result = null;
        int pageCount = -1;

        if (contentInfoBean.getPageSize() > 0) {

            pageCount = collectorResult.size() / contentInfoBean.getPageSize();
            if ((collectorResult.size() % contentInfoBean.getPageSize()) != 0) {
                pageCount++;
            }

            contentInfoBean.setPageCount(pageCount);

            int startIndex = (contentInfoBean.getPageIndex() - 1) * contentInfoBean.getPageSize();
            int endIndex = contentInfoBean.getPageIndex() * contentInfoBean.getPageSize();
            if (endIndex > collectorResult.size()) {
                endIndex = collectorResult.size();
            }

            result = collectorResult.subList(startIndex, endIndex);
        } else {

            result = collectorResult;
            if (collectorResult.size() > 0) {
                contentInfoBean.setPageCount(1);
            }
        }

        return result;
    }

    /**
     * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
     */
    public int doAfterBody() throws JspException {

        // close open direct edit first
        if (hasMoreContent()) {
            // another loop is required
            return EVAL_BODY_AGAIN;
        }
        // need to release manually, JSP container may not call release as required (happens with Tomcat)
        release();
        // no more files are available, so skip the body and finish the loop
        return SKIP_BODY;
    }

    /**
     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
     */
    public int doEndTag() {

        // need to release manually, JSP container may not call release as required (happens with Tomcat)
        release();
        return EVAL_PAGE;
    }

    /**
     * @see javax.servlet.jsp.tagext.Tag#doStartTag()
     */
    public int doStartTag() throws JspException, CmsIllegalArgumentException {

        // get a reference to the parent "content container" class (if available)
        Tag ancestor = findAncestorWithClass(this, I_CmsXmlContentContainer.class);
        I_CmsXmlContentContainer container = null;
        if (ancestor != null) {
            // parent content container available, use preloaded values from this container
            container = (I_CmsXmlContentContainer)ancestor;
            // check if container really is a preloader
            if (!container.isPreloader()) {
                // don't use ancestor if not a preloader
                ancestor = null;
            }
        }

        // initialize the content load tag
        init(container);

        hasMoreContent();

        return EVAL_BODY_INCLUDE;
    }

    /**
     * Returns the collector.<p>
     *
     * @return the collector
     */
    public String getCollector() {

        return m_collector;
    }

    /**
     * @see org.opencms.jsp.I_CmsXmlContentContainer#getCollectorName()
     */
    public String getCollectorName() {

        return m_collectorName;
    }

    /**
     * @see org.opencms.jsp.I_CmsXmlContentContainer#getCollectorParam()
     */
    public String getCollectorParam() {

        return m_collectorParam;
    }

    /**
     * @see org.opencms.jsp.I_CmsXmlContentContainer#getCollectorResult()
     */
    public List getCollectorResult() {

        return m_collectorResult;
    }

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

        return String.valueOf(m_editable);
    }

    /**
     * Returns the locale.<p>
     *
     * @return the locale
     */
    public String getLocale() {

        return (m_locale != null) ? m_locale.toString() : "";
    }

    /**
     * Returns the index of the page to be displayed.<p>
     * 
     * @return the index of the page to be displayed
     */
    public String getPageIndex() {

        return m_pageIndex;
    }

    /**
     * Returns the number of page links in the Google-like page navigation.<p>
     * 
     * @return the number of page links in the Google-like page navigation
     */
    public String getPageNavLength() {

        return m_pageNavLength;
    }

    /**
     * Returns the size of a single page to be displayed.<p>
     * 
     * @return the size of a single page to be displayed
     */
    public String getPageSize() {

        return m_pageSize;
    }

    /**
     * Returns the collector parameter.<p>
     *
     * @return the collector parameter
     */
    public String getParam() {

        return m_param;
    }

    /**
     * Returns <code>"true"</code> if this content load tag should only preload the values from the collector.<p>
     * 
     * @return <code>"true"</code> if this content load tag should only preload the values from the collector
     */
    public String getPreload() {

        return String.valueOf(m_preload);
    }

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

        return m_property;
    }

    /**
     * @see org.opencms.jsp.I_CmsXmlContentContainer#getResourceName()
     */
    public String getResourceName() {

        return m_resourceName;
    }

    /**
     * @see org.opencms.jsp.I_CmsXmlContentContainer#getXmlDocument()
     */
    public I_CmsXmlDocument getXmlDocument() {

⌨️ 快捷键说明

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