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

📄 cmsuserwidget.java

📁 cms是开源的框架
💻 JAVA
字号:
/*
 * File   : $Source$
 * Date   : $Date$
 * Version: $Revision$
 *
 * 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.widgets;

import org.opencms.file.CmsObject;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;

/**
 * Provides a OpenCms User selection widget, for use on a widget dialog.<p>
 *
 * @author Michael Moossen
 * 
 * @version $Revision$ 
 * 
 * @since 6.0.0 
 */
public class CmsUserWidget extends A_CmsWidget {

    /** Configuration parameter to set the flags of the users to display, optional. */
    public static final String CONFIGURATION_FLAGS = "flags";

    /** Configuration parameter to set the group of users to display, optional. */
    public static final String CONFIGURATION_GROUP = "group";

    /** Configuration parameter to set the user type to select in the popup user selection dialog. */
    public static final String CONFIGURATION_USERTYPE = "usertype";

    /** The the flags used in the popup window. */
    private Integer m_flags;

    /** The the group used in the popup window. */
    private String m_groupName;

    /** The user type used in the popup window. */
    private Integer m_userType;

    /**
     * Creates a new user selection widget.<p>
     */
    public CmsUserWidget() {

        // empty constructor is required for class registration
        this("");
    }

    /**
     * Creates a new user selection widget with the parameters to configure the popup window behaviour.<p>
     * 
     * @param flags the group flags to restrict the group selection, can be <code>null</code>
     * @param userType the type of the users to display, can be <code>null</code>
     * @param groupName the group to restrict the user selection, can be <code>null</code>
     */
    public CmsUserWidget(Integer flags, Integer userType, String groupName) {

        m_flags = flags;
        m_userType = userType;
        m_groupName = groupName;
    }

    /**
     * Creates a new user selection widget with the given configuration.<p>
     * 
     * @param configuration the configuration to use
     */
    public CmsUserWidget(String configuration) {

        super(configuration);
    }

    /**
     * @see org.opencms.widgets.A_CmsWidget#getConfiguration()
     */
    public String getConfiguration() {

        StringBuffer result = new StringBuffer(8);

        // append flags to configuration
        if (m_flags != null) {
            if (result.length() > 0) {
                result.append("|");
            }
            result.append(CONFIGURATION_FLAGS);
            result.append("=");
            result.append(m_flags);
        }
        // append user type to configuration
        if (m_userType != null) {
            if (result.length() > 0) {
                result.append("|");
            }
            result.append(CONFIGURATION_USERTYPE);
            result.append("=");
            result.append(m_userType.intValue());
        }
        // append group to configuration
        if (m_groupName != null) {
            if (result.length() > 0) {
                result.append("|");
            }
            result.append(CONFIGURATION_GROUP);
            result.append("=");
            result.append(m_groupName);
        }

        return result.toString();
    }

    /**
     * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
     */
    public String getDialogIncludes(CmsObject cms, I_CmsWidgetDialog widgetDialog) {

        StringBuffer result = new StringBuffer(16);
        result.append(getJSIncludeFile(CmsWorkplace.getSkinUri() + "components/widgets/userselector.js"));
        return result.toString();
    }

    /**
     * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
     */
    public String getDialogWidget(CmsObject cms, I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {

        String id = param.getId();
        StringBuffer result = new StringBuffer(128);

        result.append("<td class=\"xmlTd\">");
        result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\"><tr><td style=\"width: 100%;\">");
        result.append("<input style=\"width: 99%;\" class=\"xmlInput");
        if (param.hasError()) {
            result.append(" xmlInputError");
        }
        result.append("\" value=\"");
        result.append(param.getStringValue(cms));
        result.append("\" name=\"");
        result.append(id);
        result.append("\" id=\"");
        result.append(id);
        result.append("\"></td>");
        result.append(widgetDialog.dialogHorizontalSpacer(10));
        result.append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");

        StringBuffer buttonJs = new StringBuffer(8);
        buttonJs.append("javascript:openUserWin('");
        buttonJs.append(OpenCms.getSystemInfo().getOpenCmsContext());
        buttonJs.append("/system/workplace/commons/user_selection.jsp");
        buttonJs.append("','EDITOR',  '");
        buttonJs.append(id);
        buttonJs.append("', document, '");
        if (m_flags != null) {
            buttonJs.append(m_flags);
        } else {
            buttonJs.append("null");
        }
        buttonJs.append("', '");
        if (m_groupName != null) {
            buttonJs.append(m_groupName);
        } else {
            buttonJs.append("null");
        }
        buttonJs.append("', '");
        if (m_userType != null) {
            buttonJs.append(m_userType.intValue());
        } else {
            buttonJs.append("null");
        }
        buttonJs.append("'");
        buttonJs.append(");");

        result.append(widgetDialog.button(
            buttonJs.toString(),
            null,
            "user",
            org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_SEARCH_0,
            widgetDialog.getButtonStyle()));
        result.append("</tr></table>");
        result.append("</td></tr></table>");

        result.append("</td>");

        return result.toString();
    }

    /**
     * Returns the flags, or <code>null</code> if all.<p>
     *
     * @return the flags, or <code>null</code> if all
     */
    public Integer getFlags() {

        return m_flags;
    }

    /**
     * Returns the group name, or <code>null</code> if all.<p>
     *
     * @return the group name, or <code>null</code> if all
     */
    public String getGroupName() {

        return m_groupName;
    }

    /**
     * Returns the user Type, or <code>null</code> if all.<p>
     *
     * @return the user Type, or <code>null</code> if all
     */
    public Integer getUserType() {

        return m_userType;
    }

    /**
     * @see org.opencms.widgets.I_CmsWidget#newInstance()
     */
    public I_CmsWidget newInstance() {

        return new CmsUserWidget(getConfiguration());
    }

    /**
     * @see org.opencms.widgets.A_CmsWidget#setConfiguration(java.lang.String)
     */
    public void setConfiguration(String configuration) {

        m_groupName = null;
        m_userType = null;
        m_flags = null;
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(configuration)) {
            int flagsIndex = configuration.indexOf(CONFIGURATION_FLAGS);
            if (flagsIndex != -1) {
                // user is given
                String flags = configuration.substring(CONFIGURATION_FLAGS.length() + 1);
                if (flags.indexOf('|') != -1) {
                    // cut eventual following configuration values
                    flags = flags.substring(0, flags.indexOf('|'));
                }
                try {
                    m_flags = Integer.valueOf(flags);
                } catch (Throwable t) {
                    // invalid flags
                }
            }
            int typeIndex = configuration.indexOf(CONFIGURATION_USERTYPE);
            if (typeIndex != -1) {
                // user type is given
                String type = configuration.substring(CONFIGURATION_USERTYPE.length() + 1);
                if (type.indexOf('|') != -1) {
                    // cut eventual following configuration values
                    type = type.substring(0, type.indexOf('|'));
                }
                try {
                    m_userType = Integer.valueOf(type);
                } catch (Throwable t) {
                    // invalid flags
                }
            }
            int groupIndex = configuration.indexOf(CONFIGURATION_GROUP);
            if (groupIndex != -1) {
                // group is given
                String group = configuration.substring(CONFIGURATION_GROUP.length() + 1);
                if (group.indexOf('|') != -1) {
                    // cut eventual following configuration values
                    group = group.substring(0, group.indexOf('|'));
                }
                m_groupName = group;
            }
        }
        super.setConfiguration(configuration);
    }
}

⌨️ 快捷键说明

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