cmseditprojectdialog.java
来自「找了很久才找到到源代码」· Java 代码 · 共 573 行 · 第 1/2 页
JAVA
573 行
/*
* File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsEditProjectDialog.java,v $
* Date : $Date: 2007-08-13 16:30:14 $
* Version: $Revision: 1.19 $
*
* 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.tools.projects;
import org.opencms.file.CmsGroup;
import org.opencms.file.CmsProject;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsOrganizationalUnit;
import org.opencms.security.CmsRole;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.util.CmsFileUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import org.opencms.widgets.CmsCheckboxWidget;
import org.opencms.widgets.CmsDisplayWidget;
import org.opencms.widgets.CmsGroupWidget;
import org.opencms.widgets.CmsInputWidget;
import org.opencms.widgets.CmsOrgUnitWidget;
import org.opencms.widgets.CmsTextareaWidget;
import org.opencms.widgets.CmsVfsFileWidget;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWidgetDialog;
import org.opencms.workplace.CmsWidgetDialogParameter;
import org.opencms.workplace.CmsWorkplaceSettings;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
/**
* Dialog to edit new and existing project in the administration view.<p>
*
* @author Michael Moossen
*
* @version $Revision: 1.19 $
*
* @since 6.0.0
*/
public class CmsEditProjectDialog extends CmsWidgetDialog {
/** localized messages Keys prefix. */
public static final String KEY_PREFIX = "project";
/** Defines which pages are valid for this dialog. */
public static final String[] PAGES = {"page1"};
/** Request parameter name for the project id. */
public static final String PARAM_PROJECTID = "projectid";
/** Request parameter name for the project name. */
public static final String PARAM_PROJECTNAME = "projectname";
/** The project object that is edited on this dialog. */
protected CmsProject m_project;
/** Stores the value of the request parameter for the project id. */
private String m_paramProjectid;
/** Auxiliary Property for better representation of the bean VFS resources. */
private List m_resources;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsEditProjectDialog(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Public constructor with JSP variables.<p>
*
* @param context the JSP page context
* @param req the JSP request
* @param res the JSP response
*/
public CmsEditProjectDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Commits the edited project to the database.<p>
*/
public void actionCommit() {
List errors = new ArrayList();
try {
// if new create it first
if (m_project.getUuid() == null) {
CmsProject newProject = getCms().createProject(
m_project.getName(),
m_project.getDescription(),
getUserGroup(),
getManagerGroup(),
m_project.getType());
m_project = newProject;
} else {
getCms().writeProject(m_project);
}
// write the edited project resources
CmsProject currentProject = getCms().getRequestContext().currentProject();
// change the current project
getCms().getRequestContext().setCurrentProject(m_project);
// store the current site root
String currentSite = getCms().getRequestContext().getSiteRoot();
// copy the resources to the current project
try {
// switch to the root site
getCms().getRequestContext().setSiteRoot("");
// remove deleted resources
Iterator itDel = getCms().readProjectResources(m_project).iterator();
while (itDel.hasNext()) {
String resName = itDel.next().toString();
if (!getResources().contains(resName)) {
getCms().removeResourceFromProject(resName);
}
}
// read project resources again!
List currentResNames = getCms().readProjectResources(m_project);
// copy missing resources
Iterator itAdd = getResources().iterator();
while (itAdd.hasNext()) {
String resName = itAdd.next().toString();
if (!currentResNames.contains(resName)) {
getCms().copyResourceToProject(resName);
}
}
} finally {
// switch back to current site and project
getCms().getRequestContext().setSiteRoot(currentSite);
getCms().getRequestContext().setCurrentProject(currentProject);
}
// refresh the list
Map objects = (Map)getSettings().getListObject();
if (objects != null) {
objects.remove(CmsProjectsList.class.getName());
}
} catch (Throwable t) {
errors.add(t);
}
// set the list of errors to display when saving failed
setCommitErrors(errors);
}
/**
* Returns the description of the parent ou.<p>
*
* @return the description of the parent ou
*/
public String getAssignedOu() {
try {
CmsOrganizationalUnit ou;
if (!isNewProject()) {
ou = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_project.getOuFqn());
} else {
ou = (CmsOrganizationalUnit)OpenCms.getRoleManager().getOrgUnitsForRole(
getCms(),
CmsRole.PROJECT_MANAGER,
true).get(0);
}
return ou.getDisplayName(getLocale());
} catch (CmsException e) {
return null;
}
}
/**
* Returns the manager Group name.<p>
*
* @return the manager Group name
*/
public String getManagerGroup() {
try {
return getCms().readGroup(m_project.getManagerGroupId()).getName();
} catch (Throwable e) {
return "";
}
}
/**
* Returns the simple name of the project.<p>
*
* @return the simple name of the project
*/
public String getName() {
String name = m_project.getSimpleName();
if (CmsStringUtil.isEmptyOrWhitespaceOnly(name) || name.equals("/")) {
name = "";
}
return name;
}
/**
* Returns the fully qualified name of the organizational unit.<p>
*
* @return the fully qualified name of the organizational unit
*/
public String getOufqn() {
return m_project.getOuFqn();
}
/**
* Returns the project id parameter value.<p>
*
* @return the project id parameter value
*/
public String getParamProjectid() {
return m_paramProjectid;
}
/**
* Returns the list of VFS resources that belong to this project.<p>
*
* @return the list of VFS resources that belong to this project
*/
public List getResources() {
if (m_resources == null) {
return new ArrayList();
}
return m_resources;
}
/**
* Returns the user Group name.<p>
*
* @return the user Group name
*/
public String getUserGroup() {
try {
return getCms().readGroup(m_project.getGroupId()).getName();
} catch (Throwable e) {
return "";
}
}
/**
* Just a setter method needed for the widget dialog.<p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?