cmsframeset.java

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

JAVA
542
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsFrameset.java,v $
 * Date   : $Date: 2007-08-29 13:30:25 $
 * Version: $Revision: 1.90 $
 *
 * 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.workplace;

import org.opencms.configuration.CmsDefaultUserSettings;
import org.opencms.db.CmsUserSettings;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsResourceFilter;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.site.CmsSite;
import org.opencms.synchronize.CmsSynchronizeSettings;
import org.opencms.util.CmsRequestUtil;
import org.opencms.util.CmsStringUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

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

import org.apache.commons.logging.Log;

/**
 * Provides methods for building the main framesets of the OpenCms Workplace.<p> 
 * 
 * The following files use this class:
 * <ul>
 * <li>/views/top.html
 * <li>/views/top_foot.html
 * <li>/views/top_head.html
 * </ul>
 * <p> 
 * 
 * @author  Alexander Kandzior 
 * 
 * @version $Revision: 1.90 $ 
 * 
 * @since 6.0.0 
 */
public class CmsFrameset extends CmsWorkplace {

    /** Path to the JSP workplace frame loader file. */
    public static final String JSP_WORKPLACE_URI = CmsWorkplace.VFS_PATH_VIEWS + "workplace.jsp";

    /** The request parameter for the selection of the frame. */
    public static final String PARAM_WP_FRAME = "wpFrame";

    /** The request parameter for the workplace start selection. */
    public static final String PARAM_WP_START = "wpStart";

    /** The request parameter for the workplace view selection. */
    public static final String PARAM_WP_VIEW = "wpView";

    /** The names of the supported frames. */
    private static final String[] FRAMES = {"top", "head", "body", "foot"};

    /** The names of the supported frames in a list. */
    public static final List FRAMES_LIST = Collections.unmodifiableList(Arrays.asList(FRAMES));

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

    /** Indicates if a reload of the main body frame is required. */
    private boolean m_reloadRequired;

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

        super(jsp);
    }

    /**
     * Returns the javascript code for the broadcast message alert in the foot of the workplace.<p>
     * 
     * @return javascript code showing an alert box when the foot load
     */
    public String getBroadcastMessage() {

        StringBuffer result = new StringBuffer(512);
        String message = getBroadcastMessageString();

        if (CmsStringUtil.isNotEmpty(message)) {
            // create a javascript alert for the message 
            result.append("\n<script type=\"text/javascript\">\n<!--\n");
            // the timeout gives the frameset enough time to load before the alert is shown
            result.append("function showMessage() {\n");
            result.append("\talert(decodeURIComponent(\"");
            // the user has pending messages, display them all
            result.append(CmsEncoder.escapeWBlanks(message, CmsEncoder.ENCODING_UTF_8));
            result.append("\"));\n}\n");
            result.append("setTimeout('showMessage();', 2000);");
            result.append("\n//-->\n</script>");
        }
        return result.toString();
    }

    /**
     * Returns the remote ip address of the current user.<p>
     * 
     * @return the remote ip address of the current user
     */
    public String getLoginAddress() {

        return getCms().getRequestContext().getRemoteAddress();
    }

    /**
     * Returns the last login time of the current user in localized format.<p>
     *
     * @return the last login time of the current user in localized format
     */
    public String getLoginTime() {

        return getMessages().getDateTime(getSettings().getUser().getLastlogin());
    }

    /**
     * Returns the html for the "preferences" button depending on the current users permissions and 
     * the default workplace settings.<p>
     * 
     * @return the html for the "preferences" button
     */
    public String getPreferencesButton() {

        int buttonStyle = getSettings().getUserSettings().getWorkplaceButtonStyle();
        if (!getCms().getRequestContext().currentUser().isManaged()) {
            return button(
                "../commons/preferences.jsp",
                "body",
                "preferences.png",
                Messages.GUI_BUTTON_PREFERENCES_0,
                buttonStyle);
        } else {
            return button(null, null, "preferences_in.png", Messages.GUI_BUTTON_PREFERENCES_0, buttonStyle);
        }
    }

    /**
     * Returns a html select box filled with the current users accessible projects.<p>
     * 
     * @param htmlAttributes attributes that will be inserted into the generated html 
     * @param htmlWidth additional style attributes containing width information
     * @return a html select box filled with the current users accessible projects
     */
    public String getProjectSelect(String htmlAttributes, String htmlWidth) {

        // get all project information
        List allProjects;
        try {
            allProjects = getCms().getAllAccessibleProjects();
        } catch (CmsException e) {
            // should usually never happen
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage());
            }
            allProjects = Collections.EMPTY_LIST;
        }

        boolean singleOu = true;
        String ouFqn = null;
        Iterator itProjects = allProjects.iterator();
        while (itProjects.hasNext()) {
            CmsProject prj = (CmsProject)itProjects.next();
            if (prj.isOnlineProject()) {
                // skip the online project
                continue;
            }
            if (ouFqn == null) {
                // set the first ou
                ouFqn = prj.getOuFqn();
            }
            if (!ouFqn.equals(prj.getOuFqn())) {
                // break if one different ou is found
                singleOu = false;
                break;
            }
        }

        List options = new ArrayList();
        List values = new ArrayList();
        int selectedIndex = -1;
        int ouDefaultProjIndex = -1;

        CmsOrganizationalUnit ou = null;
        try {
            ou = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), getCms().getRequestContext().getOuFqn());
        } catch (CmsException e) {
            // should never happen, ignore
        }

        // now loop through all projects and fill the result vectors
        for (int i = 0, n = allProjects.size(); i < n; i++) {
            CmsProject project = (CmsProject)allProjects.get(i);
            String projectId = project.getUuid().toString();
            String projectName = project.getSimpleName();
            if (!singleOu && !project.isOnlineProject()) {
                try {
                    projectName = projectName
                        + " - "
                        + OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), project.getOuFqn()).getDisplayName(
                            getLocale());
                } catch (CmsException e) {
                    projectName = projectName + " - " + project.getOuFqn();
                }
            }

            values.add(projectId);
            options.add(projectName);

            if (project.getUuid().equals(getSettings().getProject())) {
                // this is the user's current project
                selectedIndex = i;
            }
            if ((ou != null) && project.getUuid().equals(ou.getProjectId())) {
                ouDefaultProjIndex = i;
            }
        }
        if (selectedIndex == -1) {
            if (ouDefaultProjIndex == -1) {
                selectedIndex = 0;
            } else {
                selectedIndex = ouDefaultProjIndex;
            }
        }
        if (CmsStringUtil.isNotEmpty(htmlWidth)) {
            StringBuffer buf = new StringBuffer(htmlAttributes.length() + htmlWidth.length() + 2);
            buf.append(htmlAttributes);
            buf.append(" ");
            buf.append(htmlWidth);
            htmlAttributes = buf.toString();

⌨️ 快捷键说明

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