📄 cmsnewresourcexmlpage.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsNewResourceXmlPage.java,v $
* Date : $Date: 2006/03/27 14:52:30 $
* Version: $Revision: 1.23 $
*
* 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.explorer;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsFolder;
import org.opencms.file.CmsObject;
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.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.commons.CmsPropertyAdvanced;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
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;
/**
* The new resource page dialog handles the creation of an xml page.<p>
*
* The following files use this class:
* <ul>
* <li>/commons/newresource_xmlpage.jsp
* </ul>
* <p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.23 $
*
* @since 6.0.0
*/
public class CmsNewResourceXmlPage extends CmsNewResource {
/** Request parameter name for the selected body. */
public static final String PARAM_BODYFILE = "bodyfile";
/** Request parameter name for the suffix check. */
public static final String PARAM_SUFFIXCHECK = "suffixcheck";
/** Request parameter name for the selected template. */
public static final String PARAM_TEMPLATE = "template";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsNewResourceXmlPage.class);
private String m_paramBodyFile;
private String m_paramDialogMode;
private String m_paramSuffixCheck;
private String m_paramTemplate;
/**
* Public constructor with JSP action element.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsNewResourceXmlPage(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 CmsNewResourceXmlPage(PageContext context, HttpServletRequest req, HttpServletResponse res) {
this(new CmsJspActionElement(context, req, res));
}
/**
* Returns a sorted Map of all available body files of the OpenCms modules.<p>
*
* @param cms the current cms object
* @param currWpPath the current path in the OpenCms workplace
* @return a sorted map with the body file title as key and absolute path to the body file as value
* @throws CmsException if reading a folder or file fails
*/
public static TreeMap getBodies(CmsObject cms, String currWpPath) throws CmsException {
return getElements(cms, CmsWorkplace.VFS_DIR_DEFAULTBODIES, currWpPath, true);
}
/**
* Returns a sorted Map of all available body files of the OpenCms modules.<p>
*
* @param cms the current cms object
* @param currWpPath the current path in the OpenCms workplace
* @param emptyMap flag indicating if it is OK to return a filtered empty Map
* @return a sorted map with the body file title as key and absolute path to the body file as value
* @throws CmsException if reading a folder or file fails
*/
public static TreeMap getBodies(CmsObject cms, String currWpPath, boolean emptyMap) throws CmsException {
return getElements(cms, CmsWorkplace.VFS_DIR_DEFAULTBODIES, currWpPath, emptyMap);
}
/**
* Returns a sorted Map of all available templates of the OpenCms modules.<p>
*
* @param cms the current cms object
* @param currWpPath the current path in the OpenCms workplace
* @return a sorted map with the template title as key and absolute path to the template as value
* @throws CmsException if reading a folder or file fails
*/
public static TreeMap getTemplates(CmsObject cms, String currWpPath) throws CmsException {
return getElements(cms, CmsWorkplace.VFS_DIR_TEMPLATES, currWpPath, true);
}
/**
* Returns a sorted Map of all available templates of the OpenCms modules.<p>
*
* @param cms the current cms object
* @param currWpPath the current path in the OpenCms workplace
* @param emptyMap flag indicating if it is OK to return a filtered empty Map
* @return a sorted map with the template title as key and absolute path to the template as value
* @throws CmsException if reading a folder or file fails
*/
public static TreeMap getTemplates(CmsObject cms, String currWpPath, boolean emptyMap) throws CmsException {
return getElements(cms, CmsWorkplace.VFS_DIR_TEMPLATES, currWpPath, emptyMap);
}
/**
* Returns a sorted Map of all available elements in the specified subfolder of the OpenCms modules.<p>
*
* @param cms the current cms object
* @param elementFolder the module subfolder to serach for elements
* @param currWpPath the current path in the OpenCms workplace
* @param emptyMap flag indicating if it is OK to return a filtered empty Map
* @return a sorted map with the element title as key and absolute path to the element as value
* @throws CmsException if reading a folder or file fails
*/
protected static TreeMap getElements(CmsObject cms, String elementFolder, String currWpPath, boolean emptyMap)
throws CmsException {
TreeMap elements = new TreeMap();
TreeMap allElements = new TreeMap();
if (CmsStringUtil.isNotEmpty(currWpPath)) {
// add site root to current workplace path
currWpPath = cms.getRequestContext().addSiteRoot(currWpPath);
}
// get all visible template elements in the module folders
List modules = cms.getSubFolders(CmsWorkplace.VFS_PATH_MODULES, CmsResourceFilter.IGNORE_EXPIRATION);
for (int i = 0; i < modules.size(); i++) {
List moduleTemplateFiles = new ArrayList();
String folder = cms.getSitePath((CmsFolder)modules.get(i));
try {
moduleTemplateFiles = cms.getFilesInFolder(
folder + elementFolder,
CmsResourceFilter.DEFAULT.addRequireVisible());
} catch (CmsException e) {
// folder not available, list will be empty
if (LOG.isDebugEnabled()) {
LOG.debug(e.getMessage(), e);
}
}
for (int j = 0; j < moduleTemplateFiles.size(); j++) {
// get the current template file
CmsFile templateFile = (CmsFile)moduleTemplateFiles.get(j);
String title = null;
String folderProp = null;
try {
title = cms.readPropertyObject(
cms.getSitePath(templateFile),
CmsPropertyDefinition.PROPERTY_TITLE,
false).getValue();
folderProp = cms.readPropertyObject(
templateFile,
CmsPropertyDefinition.PROPERTY_FOLDERS_AVAILABLE,
false).getValue();
} catch (CmsException e) {
// property not available, will be null
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
boolean isInFolder = false;
// check template folders property value
if (CmsStringUtil.isNotEmpty(currWpPath) && CmsStringUtil.isNotEmpty(folderProp)) {
// property value set on template, check if current workplace path fits
List folders = CmsStringUtil.splitAsList(folderProp, DELIM_PROPERTYVALUES);
for (int k = 0; k < folders.size(); k++) {
String checkFolder = (String)folders.get(k);
if (currWpPath.startsWith(checkFolder)) {
isInFolder = true;
break;
}
}
} else {
isInFolder = true;
}
if (title == null) {
// no title property found, display the file name
title = templateFile.getName();
}
String path = cms.getSitePath(templateFile);
if (isInFolder) {
// element is valid, add it to result
elements.put(title, path);
}
// also put element to overall result
allElements.put(title, path);
}
}
if (!emptyMap && elements.size() < 1) {
// empty Map should not be returned, return all collected elements
return allElements;
}
// return the filtered elements sorted by title
return elements;
}
/**
* 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 was created before, after this dialog the tree view has to be refreshed.<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 (isCreateIndexMode()) {
// set the current explorer resource to the new created folder
String updateFolder = CmsResource.getParentFolder(getSettings().getExplorerResource());
getSettings().setExplorerResource(updateFolder);
List folderList = new ArrayList(1);
if (updateFolder != null) {
folderList.add(updateFolder);
}
getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
}
super.actionCloseDialog();
}
/**
* Creates the xml page using the specified resource name.<p>
*
* @throws JspException if inclusion of error dialog fails
*/
public void actionCreateResource() throws JspException {
try {
// calculate the new resource Title property value
String title = computeNewTitleProperty();
// create the full resource name
String fullResourceName = computeFullResourceName();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -