cmsjsptagcontentload.java

来自「找了很久才找到到源代码」· Java 代码 · 共 918 行 · 第 1/3 页

JAVA
918
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/jsp/CmsJspTagContentLoad.java,v $
 * Date   : $Date: 2007-08-13 16:29:55 $
 * Version: $Revision: 1.37 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 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.collectors.I_CmsResourceCollector;
import org.opencms.flex.CmsFlexController;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.util.CmsJspContentLoadBean;
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.directedit.CmsDirectEditButtonSelection;
import org.opencms.workplace.editors.directedit.CmsDirectEditMode;
import org.opencms.workplace.editors.directedit.CmsDirectEditParams;
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.Tag;

/**
 * Implementation of the <code>&lt;cms:contentload/&gt;</code> tag, 
 * used to access and display XML content item information from the VFS.<p>
 * 
 * Since version 7.0.2 it is also possible to store the results of the content load in the JSP context
 * using a {@link CmsJspContentLoadBean}. Using this bean the loaded XML content objects can be accessed
 * directly using the JSP EL and the JSTL. To use this feature, you need to add the <code>var</code> (and optionally
 * the <code>scope</code>) parameter to the content load tag. For example, if a parameter like 
 * <code>var="myVarName"</code> is provided, then the result of the content load is stored in the JSP 
 * context variable <code>myVarName</code> with an instance of a {@link CmsJspContentLoadBean}.<p>
 * 
 * @author  Alexander Kandzior 
 * 
 * @version $Revision: 1.37 $ 
 * 
 * @since 6.0.0 
 */
public class CmsJspTagContentLoad extends CmsJspScopedVarBodyTagSuport implements I_CmsXmlContentContainer {

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

    /** The CmsObject for the current user. */
    private transient 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 transient 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 "direct edit" button selection to use for the 2nd to the last element. */
    private CmsDirectEditButtonSelection m_directEditFollowButtons;

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

    /** The editable mode. */
    private CmsDirectEditMode m_directEditMode;

    /** Indicates if the last element was direct editable. */
    private boolean m_directEditOpen;

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

    /** Reference 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;

    /** Parameter 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 {

        this(container, context, collectorName, collectorParam, null, null, locale, editable);
    }

    /**
     * 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 pageIndex the display page index (may contain macros)
     * @param pageSize the display page size (may contain macros)
     * @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,
        String pageIndex,
        String pageSize,
        Locale locale,
        boolean editable)
    throws JspException {

        this(
            container,
            context,
            collectorName,
            collectorParam,
            pageIndex,
            pageSize,
            locale,
            CmsDirectEditMode.valueOf(editable));
    }

    /**
     * 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 pageIndex the display page index (may contain macros)
     * @param pageSize the display page size (may contain macros)
     * @param locale the locale to use 
     * @param editMode indicates which "direct edit" mode is wanted
     * 
     * @throws JspException in case something goes wrong
     */
    public CmsJspTagContentLoad(
        I_CmsXmlContentContainer container,
        PageContext context,
        String collectorName,
        String collectorParam,
        String pageIndex,
        String pageSize,
        Locale locale,
        CmsDirectEditMode editMode)
    throws JspException {

        setCollector(collectorName);
        setParam(collectorParam);
        setPageIndex(pageIndex);
        setPageSize(pageSize);
        m_locale = locale;
        m_contentLocale = locale;
        m_directEditMode = editMode;
        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();
            }

⌨️ 快捷键说明

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