📄 cmspropertyadvanced.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsPropertyAdvanced.java,v $
* Date : $Date: 2006/03/27 14:52:18 $
* Version: $Revision: 1.28 $
*
* 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.commons;
import org.opencms.file.CmsProject;
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.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.util.CmsRequestUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUriSplitter;
import org.opencms.workplace.CmsDialogSelector;
import org.opencms.workplace.CmsTabDialog;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.I_CmsDialogHandler;
import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.RandomAccess;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
/**
* Provides methods for the properties dialog.<p>
*
* The following files use this class:
* <ul>
* <li>/commons/property_advanced.jsp
* </ul>
* <p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.28 $
*
* @since 6.0.0
*/
public class CmsPropertyAdvanced extends CmsTabDialog implements I_CmsDialogHandler {
/** Value for the action: save defined property. */
public static final int ACTION_SAVE_DEFINE = 400;
/** Value for the action: save edited properties. */
public static final int ACTION_SAVE_EDIT = 300;
/** Value for the action: show define property form. */
public static final int ACTION_SHOW_DEFINE = 200;
/** Value for the action: show edit properties form. */
public static final int ACTION_SHOW_EDIT = 100;
/** Constant for the "Define" button in the build button method. */
public static final int BUTTON_DEFINE = 201;
/** Constant for the "Finish" button in the build button method. */
public static final int BUTTON_FINISH = 202;
/** Request parameter value for the action: save defined property. */
public static final String DIALOG_SAVE_DEFINE = "savedefine";
/** Request parameter value for the action: save edited properties. */
public static final String DIALOG_SAVE_EDIT = "saveedit";
/** Request parameter value for the action: show information form. */
public static final String DIALOG_SHOW_DEFAULT = "default";
/** Request parameter value for the action: show define property form. */
public static final String DIALOG_SHOW_DEFINE = "define";
/** Request parameter value for the action: show edit properties form. */
public static final String DIALOG_SHOW_EDIT = "edit";
/** The dialog type. */
public static final String DIALOG_TYPE = "property";
/** Value for the dialog mode: new resource wizard. */
public static final String MODE_WIZARD = "wizard";
/** Value for the dialog mode: new resource wizard with creation of index page for new folder. */
public static final String MODE_WIZARD_CREATEINDEX = "wizardcreateindex";
/** Value for the dialog mode: new resource wizard with index page created in new folder. */
public static final String MODE_WIZARD_INDEXCREATED = "wizardindexcreated";
/** Key name for the resource panel. */
public static final String PANEL_RESOURCE = "panel.properties.resource";
/** Key name for the structure panel. */
public static final String PANEL_STRUCTURE = "panel.properties.structure";
/** Request parameter name for the new property definition. */
public static final String PARAM_DIALOGMODE = "dialogmode";
/** Request parameter name for the new property definition. */
public static final String PARAM_NEWPROPERTY = "newproperty";
/** Prefix for the hidden fields. */
public static final String PREFIX_HIDDEN = "valhidden";
/** Prefix for the hidden resource value. */
public static final String PREFIX_RESOURCE = "valresource";
/** Prefix for the hidden structure value. */
public static final String PREFIX_STRUCTURE = "valstructure";
/** Prefix for the use property checkboxes. */
public static final String PREFIX_USEPROPERTY = "useprop";
/** Prefix for the input values. */
public static final String PREFIX_VALUE = "valprop";
/** Name for the shared (resource) property tab. */
public static final String TAB_RESOURCE = "tabres";
/** Name for the individual (structure) property tab. */
public static final String TAB_STRUCTURE = "tabstr";
/** The URI to the customized property dialog. */
public static final String URI_PROPERTY_CUSTOM_DIALOG = PATH_DIALOGS + "property_custom.jsp";
/** The URI to the standard property dialog. */
public static final String URI_PROPERTY_DIALOG = PATH_DIALOGS + "property_advanced.jsp";
/** The URI to the property dialog handler. */
public static final String URI_PROPERTY_DIALOG_HANDLER = PATH_DIALOGS + "property.jsp";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsPropertyAdvanced.class);
/** Helper object storing the current editable state of the resource. */
private Boolean m_isEditable;
/** Helper to determine if the edited resource is a folder. */
private boolean m_isFolder;
/** Helper stores the mode this dialog is in, because it can be called from "new" wizard. */
private String m_paramDialogMode;
/** Request parameter members. */
private String m_paramNewproperty;
private String m_paramUseTempfileProject;
/** Stores the values of properties in a String array. */
private List m_propertyValues;
/** Helper to determine if the user switched the tab views of the dialog. */
private boolean m_tabSwitched;
/**
* Default constructor needed for dialog handler implementation.<p>
*
* Do not use this constructor on JSP pages.<p>
*/
public CmsPropertyAdvanced() {
super(null);
}
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsPropertyAdvanced(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 CmsPropertyAdvanced(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Transforms a list of CmsProperty objects with structure and resource values into a map with
* CmsProperty object values keyed by property keys.<p>
*
* @param list a list of CmsProperty objects
* @return a map with CmsPropery object values keyed by property keys
*/
public static Map getPropertyMap(List list) {
Map result = null;
String key = null;
CmsProperty property = null;
if (list == null || list.size() == 0) {
return Collections.EMPTY_MAP;
}
result = new HashMap();
// choose the fastest method to iterate the list
if (list instanceof RandomAccess) {
for (int i = 0, n = list.size(); i < n; i++) {
property = (CmsProperty)list.get(i);
key = property.getName();
result.put(key, property);
}
} else {
Iterator i = list.iterator();
while (i.hasNext()) {
property = (CmsProperty)i.next();
key = property.getName();
result.put(key, property);
}
}
return result;
}
/**
* Used to close the current JSP dialog.<p>
*
* This method overwrites the close dialog method in the super class,
* because in case a new folder is created, after this dialog a new xml page might be created.<p>
*
* It tries to include the URI stored in the workplace settings.
* This URI is determined by the frame name, which has to be set
* in the framename parameter.<p>
*
* @throws JspException if including an element fails
*/
public void actionCloseDialog() throws JspException {
if (getAction() == ACTION_SAVE_EDIT && MODE_WIZARD_CREATEINDEX.equals(getParamDialogmode())) {
// special case: a new xmlpage resource will be created in wizard mode after closing the dialog
String newFolder = getParamResource();
if (!newFolder.endsWith("/")) {
newFolder += "/";
}
// set the current explorer resource to the new created folder
getSettings().setExplorerResource(newFolder);
String newUri = PATH_DIALOGS
+ OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypeXmlPage.getStaticTypeName()).getNewResourceUri();
try {
// forward to new xmlpage dialog
CmsUriSplitter splitter = new CmsUriSplitter(newUri);
Map params = CmsRequestUtil.createParameterMap(splitter.getQuery());
params.put(PARAM_DIALOGMODE, MODE_WIZARD_CREATEINDEX);
sendForward(splitter.getPrefix(), params);
return;
} catch (IOException e) {
LOG.error(Messages.get().getBundle().key(Messages.ERR_REDIRECT_XMLPAGE_DIALOG_1, PATH_DIALOGS + newUri));
} catch (ServletException e) {
LOG.error(Messages.get().getBundle().key(Messages.ERR_REDIRECT_XMLPAGE_DIALOG_1, PATH_DIALOGS + newUri));
}
} else if (getAction() == ACTION_SAVE_EDIT && MODE_WIZARD.equals(getParamDialogmode())) {
// set request attribute to reload the folder tree after creating a folder in wizard mode
try {
CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
if (res.isFolder()) {
List folderList = new ArrayList(1);
folderList.add(CmsResource.getParentFolder(getParamResource()));
getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
}
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
} else if (MODE_WIZARD_INDEXCREATED.equals(getParamDialogmode())) {
// set request attribute to reload the folder tree after creating an xml page in a new created folder in wizard mode
getSettings().setExplorerResource(
CmsResource.getParentFolder(CmsResource.getParentFolder(getParamResource())));
List folderList = new ArrayList(1);
folderList.add(CmsResource.getParentFolder(CmsResource.getParentFolder(getParamResource())));
getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
}
super.actionCloseDialog();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -