📄 cmswpmain.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsWpMain.java,v $
* Date : $Date: 2003/04/09 06:42:03 $
* Version: $Revision: 1.51 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* 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 OpenCms, please see the
* OpenCms 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 com.opencms.workplace;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsGroup;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsProject;
import com.opencms.file.CmsRequestContext;
import com.opencms.file.CmsUser;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsXmlTemplateFile;
import com.opencms.util.Encoder;
import java.util.Hashtable;
import java.util.Vector;
/**
* Template class for displaying OpenCms workplace main screen.
* <P>
* Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
*
* @author Alexander Lucas
* @author Michael Emmerich
* @version $Revision: 1.51 $ $Date: 2003/04/09 06:42:03 $
* @see com.opencms.workplace.CmsXmlWpTemplateFile
*/
public class CmsWpMain extends CmsWorkplaceDefault {
public CmsWpMain() {
super();
m_SelectedPrjIndex = 0;
m_ProjectIds = null;
m_ProjectNames = null;
}
/**
* Gets the content of a defined section in a given template file and its subtemplates
* with the given parameters.
*
* @see #getContent(CmsObject, String, String, Hashtable, String)
* @param cms CmsObject Object for accessing system resources.
* @param templateFile Filename of the template file.
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
*/
public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlTemplate] getting content of element " + ((elementName == null) ? "<root>" : elementName));
A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlTemplate] template file is: " + templateFile);
A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlTemplate] selected template section is: " + ((templateSelector == null) ? "<default>" : templateSelector));
}
I_CmsSession session = cms.getRequestContext().getSession(true);
CmsRequestContext reqCont = cms.getRequestContext();
String newGroup = (String) parameters.get("group");
String newProject = (String) parameters.get("project");
String newView = (String) parameters.get(C_PARA_VIEW);
CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
// Check if the user requested a group change
if (newGroup != null && !("".equals(newGroup))) {
if (!(newGroup.equals(reqCont.currentGroup().getName()))) {
reqCont.setCurrentGroup(newGroup);
}
}
// Check if the user requested a project change
if (newProject != null && !("".equals(newProject))) {
if (!(Integer.parseInt(newProject) == reqCont.currentProject().getId())) {
reqCont.setCurrentProject(Integer.parseInt(newProject));
}
}
// Check if the user requested a new view
if (newView != null && !("".equals(newView))) {
session = cms.getRequestContext().getSession(true);
session.putValue(C_PARA_VIEW, newView);
}
// set the publishProject Button to enable if user has the right to publish the project
if (templateFile.equalsIgnoreCase(CmsXmlTemplateFile.C_TEMPLATEPATH + "head")) {
if ((cms.isAdmin() || cms.isManagerOfProject()) && (!reqCont.currentProject().isOnlineProject())) {
xmlTemplateDocument.setData("publish", xmlTemplateDocument.getProcessedDataValue("PUBLISH_ENABLED", this));
}
else {
xmlTemplateDocument.setData("publish", xmlTemplateDocument.getProcessedDataValue("PUBLISH_DISABLED", this));
}
}
// set the sync button to enabled if no entries for synchronisation in registry
if (templateFile.equalsIgnoreCase(CmsXmlTemplateFile.C_TEMPLATEPATH + "head")) {
String syncpath = null;
syncpath = cms.getRegistry().getSystemValue(CmsSyncFolder.C_SYNCHRONISATION_PROJECT);
if (syncpath == null) {
xmlTemplateDocument.setData(CmsSyncFolder.C_SYNC_BUTTON, xmlTemplateDocument.getProcessedDataValue(CmsSyncFolder.C_SYNC_BUTTON_DISABLED, this));
}
else {
xmlTemplateDocument.setData(CmsSyncFolder.C_SYNC_BUTTON, xmlTemplateDocument.getProcessedDataValue(CmsSyncFolder.C_SYNC_BUTTON_ENABLED, this));
}
}
// send message, if this is the foot
if (templateFile.equalsIgnoreCase(CmsXmlTemplateFile.C_TEMPLATEPATH + "foot")) {
String message = (String) cms.getRequestContext().getSession(true).getValue(I_CmsConstants.C_SESSION_BROADCASTMESSAGE);
if (message != null) {
cms.getRequestContext().getSession(true).removeValue(I_CmsConstants.C_SESSION_BROADCASTMESSAGE);
xmlTemplateDocument.setData("message", "alert(unescape('BROADCASTMESSAGE: " + Encoder.escape(message, cms.getRequestContext().getEncoding()) + "'));");
}
}
// test if the "help"- button has to be displayed for the user's
// current language in case we process the head template
if (templateFile.equalsIgnoreCase(CmsXmlTemplateFile.C_TEMPLATEPATH + "head")) {
String userLanguage = CmsXmlLanguageFile.getCurrentUserLanguage(cms);
xmlTemplateDocument.setData("LOCALE", "" + userLanguage);
try {
cms.readFolder(C_VFS_PATH_HELP + userLanguage);
// the localized help- folder exists
xmlTemplateDocument.setData("HELP", xmlTemplateDocument.getProcessedDataValue("HELP_ENABLED", this));
}
catch (CmsException e) {
// the localized help- folder does not exist
try {
xmlTemplateDocument.setData("HELP", xmlTemplateDocument.getProcessedDataValue("HELP_DISABLED", this));
} catch (Exception ex) {
// probably the "head" template is old, ignore this error so the workplace can still be used
}
}
}
this.fetchProjects(cms, xmlTemplateDocument);
// Now load the template file and start the processing
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
}
/**
* Gets all groups of the currently logged in user.
* <P>
* The given vectors <code>names</code> and <code>values</code> will
* be filled with the appropriate information to be used for building
* a select box.
* <P>
* Both <code>names</code> and <code>values</code> will contain
* the group names after returning from this method.
* <P>
*
* @param cms CmsObject Object for accessing system resources.
* @param lang reference to the currently valid language file
* @param names Vector to be filled with the appropriate values in this method.
* @param values Vector to be filled with the appropriate values in this method.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the user's current group in the vectors.
* @throws CmsException
*/
public Integer getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Hashtable parameters) throws CmsException {
// Get a vector of all of the user's groups by asking the request context
CmsRequestContext reqCont = cms.getRequestContext();
CmsGroup currentGroup = reqCont.currentGroup();
Vector allGroups = cms.getGroupsOfUser(reqCont.currentUser().getName());
// Now loop through all groups and fill the result vectors
int numGroups = allGroups.size();
int currentGroupNum = 0;
for (int i = 0; i < numGroups; i++) {
CmsGroup loopGroup = (CmsGroup) allGroups.elementAt(i);
String loopGroupName = loopGroup.getName();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -