001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsPreEditorActionDefinitionXmlContent.java,v $
003: * Date : $Date: 2008-02-27 12:05:23 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.editors;
033:
034: import org.opencms.file.CmsResource;
035: import org.opencms.file.types.I_CmsResourceType;
036: import org.opencms.main.OpenCms;
037: import org.opencms.util.CmsStringUtil;
038: import org.opencms.workplace.CmsDialog;
039: import org.opencms.workplace.explorer.CmsNewResource;
040: import org.opencms.workplace.explorer.CmsNewResourceXmlContent;
041: import org.opencms.workplace.explorer.CmsNewResourceXmlContentModel;
042:
043: import java.util.HashMap;
044: import java.util.Map;
045:
046: /**
047: * Pre editor action for XML content resource types, checks if model files are available for the XML content
048: * to create in direct edit mode and shows the selection before opening the editor.<p>
049: *
050: * @author Andreas Zahner
051: *
052: * @version $Revision: 1.4 $
053: *
054: * @since 6.5.4
055: */
056: public class CmsPreEditorActionDefinitionXmlContent extends
057: A_CmsPreEditorActionDefinition {
058:
059: /**
060: * Constructor, without parameters.<p>
061: */
062: public CmsPreEditorActionDefinitionXmlContent() {
063:
064: // empty constructor, needed for initialization
065: }
066:
067: /**
068: * @see org.opencms.workplace.editors.I_CmsPreEditorActionDefinition#doPreAction(org.opencms.file.CmsResource, org.opencms.workplace.CmsDialog, java.lang.String)
069: */
070: public boolean doPreAction(CmsResource resource, CmsDialog dialog,
071: String originalParams) throws Exception {
072:
073: String newlink = dialog.getJsp().getRequest().getParameter(
074: CmsXmlContentEditor.PARAM_NEWLINK);
075: if (CmsStringUtil.isNotEmpty(newlink)) {
076: // pre editor action not executed yet and new link is provided, now check model files for resource type
077: I_CmsResourceType type = OpenCms.getResourceManager()
078: .getResourceType(resource.getTypeId());
079: String folderPath = dialog.getSettings()
080: .getExplorerResource();
081: // get the name of the currently edited resource
082: String resName = dialog.getJsp().getRequest().getParameter(
083: CmsDialog.PARAM_RESOURCE);
084: if (CmsStringUtil.isNotEmpty(resName)) {
085: // get the folder path from the currently edited resource
086: folderPath = CmsResource.getFolderPath(resName);
087: }
088: if (CmsNewResourceXmlContent.getModelFiles(dialog.getCms(),
089: folderPath, type.getTypeName()).size() > 0) {
090: // model files present, display model file selection dialog before opening editor
091: Map params = new HashMap(4);
092: // put the original request parameters to a new parameter value
093: params.put(CmsDialog.PARAM_ORIGINALPARAMS,
094: originalParams);
095: // set action for dialog to open
096: params.put(CmsDialog.PARAM_ACTION,
097: CmsNewResourceXmlContent.DIALOG_CHOOSEMODEL);
098: // set the title for the dialog
099: params.put(CmsDialog.PARAM_TITLE, dialog.getJsp()
100: .getRequest().getParameter("editortitle"));
101: // set the resource type to create for the dialog
102: params.put(CmsNewResource.PARAM_NEWRESOURCETYPE, type
103: .getTypeName());
104: // set the back link URL to return to if pressing the cancel button
105: String paramBackLink = dialog.getJsp().getRequest()
106: .getParameter(CmsEditor.PARAM_BACKLINK);
107: if (CmsStringUtil.isNotEmpty(paramBackLink)) {
108: params.put(CmsEditor.PARAM_BACKLINK, paramBackLink);
109: }
110: // set the resource name
111: if (CmsStringUtil.isNotEmpty(resName)) {
112: params.put(CmsDialog.PARAM_RESOURCE, resName);
113: }
114: // forward to model file selection dialog
115: dialog
116: .sendForward(
117: CmsNewResourceXmlContentModel.VFS_PATH_MODELDIALOG,
118: params);
119: return true;
120: }
121: }
122: return false;
123: }
124:
125: }
|