cmsnewresourcexmlpage.java

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

JAVA
490
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsNewResourceXmlPage.java,v $
 * Date   : $Date: 2007-08-13 16:29:40 $
 * Version: $Revision: 1.25 $
 *
 * 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.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.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 java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

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.25 $ 
 * 
 * @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_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();

⌨️ 快捷键说明

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