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

📄 a_cmsgallery.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/galleries/A_CmsGallery.java,v $
 * Date   : $Date: 2006/05/19 08:34:50 $
 * Version: $Revision: 1.25 $
 *
 * 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.workplace.galleries;

import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.file.types.CmsResourceTypeFolderExtended;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.loader.CmsLoaderException;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceManager;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.explorer.CmsNewResource;
import org.opencms.workplace.explorer.CmsNewResourceUpload;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;

/**
 * Provides constants, members and methods to generate a gallery popup window usable in editors or as widget.<p>
 * 
 * Extend this class for every gallery type (e.g. image gallery) to build.<p>
 * 
 * @author Andreas Zahner 
 * @author Armen Markarian 
 * 
 * @version $Revision: 1.25 $ 
 * 
 * @since 6.0.0 
 */
public abstract class A_CmsGallery extends CmsDialog implements Comparable {

    /** Value for the action: delete the gallery item. */
    public static final int ACTION_DELETE = 101;

    /** Value for the action: list gallery items. */
    public static final int ACTION_LIST = 102;

    /** Value for the action: search gallery items. */
    public static final int ACTION_SEARCH = 103;

    /** Value for the action: upload a new gallery item. */
    public static final int ACTION_UPLOAD = 104;

    /** The CSS filename used in the galleries. */
    public static final String CSS_FILENAME = "gallery.css";

    /** Request parameter value for the action: delete the gallery item. */
    public static final String DIALOG_DELETE = "delete";

    /** Request parameter value for the action: edit property value. */
    public static final String DIALOG_EDITPROPERTY = "editproperty";

    /** Request parameter value for the action: list gallery items. */
    public static final String DIALOG_LIST = "list";

    /** Request parameter value for the action: search gallery items. */
    public static final String DIALOG_SEARCH = "search";

    /** The dialog type. */
    public static final String DIALOG_TYPE = "gallery";

    /** Request parameter value for the action: upload a new gallery item. */
    public static final String DIALOG_UPLOAD = "upload";

    /** Request parameter value for the dialog mode: editor. */
    public static final String MODE_EDITOR = "editor";

    /** Request parameter value for the dialog mode: view. */
    public static final String MODE_VIEW = "view";

    /** Request parameter value for the dialog mode: widget. */
    public static final String MODE_WIDGET = "widget";

    /** The uri suffix for the gallery start page. */
    public static final String OPEN_URI_SUFFIX = "gallery_fs.jsp";

    /** Request parameter name for the dialog mode (widget or editor). */
    public static final String PARAM_DIALOGMODE = "dialogmode";

    /** Request parameter name for the input field id. */
    public static final String PARAM_FIELDID = "fieldid";

    /** Request parameter name for the gallery type. */
    public static final String PARAM_GALLERY_TYPENAME = "gallerytypename";

    /** Request parameter name for the gallery path. */
    public static final String PARAM_GALLERYPATH = "gallerypath";

    /** Request parameter name for the gallery list page. */
    public static final String PARAM_PAGE = "page";

    /** Request parameter name for the property value. */
    public static final String PARAM_PROPERTYVALUE = "propertyvalue";

    /** Request parameter name for the resourcepath. */
    public static final String PARAM_RESOURCEPATH = "resourcepath";

    /** Request parameter name for the search word. */
    public static final String PARAM_SEARCHWORD = "searchword";

    /** The galleries path in the workplace containing the JSPs. */
    public static final String PATH_GALLERIES = CmsWorkplace.VFS_PATH_WORKPLACE + "galleries/";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(A_CmsGallery.class);

    /** The currently displayed gallery resource. */
    private CmsResource m_currentResource;

    /** Thed gallery items to display. */
    private List m_galleryItems;

    /** The resource type id of this gallery instance. */
    private int m_galleryTypeId;

    /** The resource type name of this gallery instance. */
    private String m_galleryTypeName;

    /** The optional parameters for the gallery from the XML configuration. */
    private String m_galleryTypeParams;

    /** The dialog mode the gallery is running in. */
    private String m_paramDialogMode;

    /** The input field id that is required when in widget mode. */
    private String m_paramFieldId;

    /** The current gallery path. */
    private String m_paramGalleryPath;

    /** The page number to display. */
    private String m_paramPage;

    /** The value of the property (current propertydefinition: Title). */
    private String m_paramPropertyValue;

    /** The resource path parameter. */
    private String m_paramResourcePath;

    /** The search word parameter. */
    private String m_paramSearchWord;

    /** The gallery base resource type. */
    private CmsResourceTypeFolderExtended m_resourceType;

    /**
     * Public empty constructor, required for {@link A_CmsGallery#createInstance(String, CmsJspActionElement)}.<p>
     */
    public A_CmsGallery() {

        this(null);
    }

    /**
     * Public constructor with JSP action element.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public A_CmsGallery(CmsJspActionElement jsp) {

        super(jsp);
    }

    /**
     * Creates a new gallery instance.<p>
     * 
     * @param jsp an initialized JSP action element
     * 
     * @return a new gallery instance
     */
    public static A_CmsGallery createInstance(CmsJspActionElement jsp) {

        String galleryTypeName = null;
        if (jsp != null) {
            // must have a valid JSP in order to read from the request
            galleryTypeName = jsp.getRequest().getParameter(PARAM_GALLERY_TYPENAME);
        }
        return A_CmsGallery.createInstance(galleryTypeName, jsp);
    }

    /**
     * Creates a new gallery instance of the given gallery type name.<p>
     * 
     * @param galleryTypeName the gallery type name to create the instance for
     * @param jsp an initialized JSP action element
     * 
     * @return a new gallery instance of the given gallery type name
     */
    public static A_CmsGallery createInstance(String galleryTypeName, CmsJspActionElement jsp) {

        if (jsp != null) {
            // must have a valid JSP in order to read from the user session
            HttpSession session = jsp.getRequest().getSession();
            // lookup the workplace settings 
            CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
            if (CmsStringUtil.isEmpty(galleryTypeName)) {
                // look up the gallery type from the settings
                galleryTypeName = settings.getGalleryType();
            } else {
                // store the last used gallery type name
                settings.setGalleryType(galleryTypeName);
            }
        }
        // get the gallery class name for the type
        A_CmsGallery template = (A_CmsGallery)OpenCms.getWorkplaceManager().getGalleries().get(galleryTypeName);

        if (template == null) {
            // requested gallery type is not configured
            CmsMessageContainer message;
            if (jsp == null) {
                message = Messages.get().container(Messages.LOG_UNKNOWN_GALLERY_TYPE_REQ_1, galleryTypeName);
            } else {
                message = Messages.get().container(
                    Messages.LOG_UNKNOWN_GALLERY_TYPE_REQ_JSP_2,
                    galleryTypeName,
                    jsp.info("opencms.request.element.uri"));
            }
            LOG.error(message.key());
            throw new CmsRuntimeException(message);
        }

        try {
            // first get the class of the gallery
            Class galleryClass = Class.forName(template.getResourceType().getFolderClassName());
            // create a new instance and cast to a gallery
            A_CmsGallery galleryInstance = (A_CmsGallery)galleryClass.newInstance();
            // set the type name and id
            galleryInstance.m_galleryTypeName = galleryTypeName;
            galleryInstance.m_resourceType = template.getResourceType();
            galleryInstance.m_galleryTypeParams = template.getResourceType().getFolderClassParams();
            galleryInstance.m_galleryTypeId = template.getResourceType().getTypeId();
            // initialize the members
            galleryInstance.initWorkplaceMembers(jsp);
            // perform other intialization
            galleryInstance.init();
            // return the result
            return galleryInstance;
        } catch (Exception e) {
            // requested type is not configured          
            CmsMessageContainer message;
            if (jsp == null) {
                message = Messages.get().container(
                    Messages.LOG_CREATE_GALLERY_INSTANCE_FAILED_2,
                    template.getResourceType().getFolderClassName(),
                    galleryTypeName);
            } else {
                message = Messages.get().container(
                    Messages.LOG_CREATE_GALLERY_INSTANCE_FAILED_JSP_3,
                    template.getResourceType().getFolderClassName(),
                    galleryTypeName,
                    jsp.info("opencms.request.element.uri"));
            }
            LOG.error(message.key());
            throw new CmsRuntimeException(message);
        }
    }

    /**
     * Initializes the gallery dialog before redirecting.<p>
     * 
     * @param wp the workplace object
     */
    public static void initGallery(CmsDialog wp) {

        // 1. get "gallerytypename" by reading the folderpath
        String galleryTypeName = null;
        if (wp.useNewStyle()) {
            galleryTypeName = CmsResource.getName(CmsResource.getFolderPath(wp.getAdminTool().getHandler().getLink()));
        } else {
            galleryTypeName = CmsResource.getName(CmsResource.getFolderPath(wp.getJsp().getRequestContext().getUri()));
        }
        if (galleryTypeName.endsWith("/")) {
            galleryTypeName = galleryTypeName.substring(0, galleryTypeName.length() - 1);
        }
        if (!galleryTypeName.equals("commons")) {
            // 2. Set in user settings
            wp.getSettings().setGalleryType(galleryTypeName);
        }
    }

    /**
     * Generates an apply button for the gallery button bar.<p>
     * 
     * The default apply button calls the javascript function link(resourcePath, input.title.value, input.title.value).
     * Overwrite this method if necessary in the specified gallery class.<p>
     * 
     * @return an apply button for the gallery button bar
     */
    public String applyButton() {

        if (MODE_VIEW.equals(getParamDialogMode())) {
            // in view mode, show disabled button
            return button(null, null, "apply_in.png", Messages.GUI_BUTTON_PASTE_0, 0);
        } else {
            // in editor or widget mode, create enabled button
            String uri = getParamResourcePath();
            if (CmsStringUtil.isEmpty(getParamDialogMode())) {
                uri = getJsp().link(uri);
            }
            return button(
                "javascript:link('" + uri + "',document.form.title.value, document.form.title.value);",
                null,
                "apply.png",
                Messages.GUI_BUTTON_PASTE_0,
                0);
        }
    }

    /**
     * Builds the html String for the buttonbar frame.<p>
     * 
     * @return the html String for the buttonbar frame
     */
    public String buildGalleryButtonBar() {

        StringBuffer buttonBar = new StringBuffer();
        try {
            if (CmsStringUtil.isNotEmpty(getParamResourcePath())) {
                // we have a resource to display
                CmsResource res = getCms().readResource(getParamResourcePath());
                if (res != null) {
                    setCurrentResource(res);
                    // check if the current user has write/lock permissions to the resource
                    if (hasWritePermissions() && DIALOG_EDITPROPERTY.equals(getParamAction())) {
                        // write the changed title property value
                        writeTitleProperty(res);
                    }
                    String title = CmsEncoder.escapeXml(getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE));
                    buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" ");
                    buttonBar.append("style=\"align: left; width:100%; background-color: ThreeDFace; margin: 0; border-right: 1px solid ThreeDShadow\">");
                    buttonBar.append("<tr align=\"left\">");
                    buttonBar.append(buttonBarStartTab(0, 0));
                    // apply button
                    buttonBar.append(applyButton());
                    // publish button
                    buttonBar.append(publishButton());
                    // delete button
                    buttonBar.append(deleteButton());
                    buttonBar.append(buttonBarSeparator(5, 5));
                    buttonBar.append("<td class=\"nowrap\"><b>");
                    buttonBar.append(key(Messages.GUI_INPUT_TITLE_0));
                    buttonBar.append("</b>&nbsp;</td>");

⌨️ 快捷键说明

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