KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > explorer > CmsNewResourceFolder


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsNewResourceFolder.java,v $
3  * Date : $Date: 2006/03/27 14:52:30 $
4  * Version: $Revision: 1.22 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.explorer;
33
34 import org.opencms.file.CmsResource;
35 import org.opencms.file.types.CmsResourceTypeFolder;
36 import org.opencms.file.types.CmsResourceTypeXmlPage;
37 import org.opencms.jsp.CmsJspActionElement;
38 import org.opencms.main.OpenCms;
39 import org.opencms.util.CmsRequestUtil;
40 import org.opencms.util.CmsUriSplitter;
41 import org.opencms.workplace.CmsWorkplaceSettings;
42 import org.opencms.workplace.commons.CmsPropertyAdvanced;
43
44 import java.io.IOException JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.HashMap JavaDoc;
47 import java.util.List JavaDoc;
48 import java.util.Map JavaDoc;
49
50 import javax.servlet.ServletException JavaDoc;
51 import javax.servlet.http.HttpServletRequest JavaDoc;
52 import javax.servlet.http.HttpServletResponse JavaDoc;
53 import javax.servlet.jsp.JspException JavaDoc;
54 import javax.servlet.jsp.PageContext JavaDoc;
55
56 /**
57  * The new resource folder dialog handles the creation of a folder.<p>
58  *
59  * The following files use this class:
60  * <ul>
61  * <li>/commons/newresource_folder.jsp
62  * </ul>
63  * <p>
64  *
65  * @author Andreas Zahner
66  *
67  * @version $Revision: 1.22 $
68  *
69  * @since 6.0.0
70  */

71 public class CmsNewResourceFolder extends CmsNewResource {
72
73     /** Request parameter name for the create index file flag. */
74     public static final String JavaDoc PARAM_CREATEINDEX = "createindex";
75
76     private String JavaDoc m_paramCreateIndex;
77
78     /**
79      * Public constructor with JSP action element.<p>
80      *
81      * @param jsp an initialized JSP action element
82      */

83     public CmsNewResourceFolder(CmsJspActionElement jsp) {
84
85         super(jsp);
86     }
87
88     /**
89      * Public constructor with JSP variables.<p>
90      *
91      * @param context the JSP page context
92      * @param req the JSP request
93      * @param res the JSP response
94      */

95     public CmsNewResourceFolder(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
96
97         this(new CmsJspActionElement(context, req, res));
98     }
99
100     /**
101      * Creates the folder using the specified resource name.<p>
102      *
103      * @throws JspException if inclusion of error dialog fails
104      */

105     public void actionCreateResource() throws JspException JavaDoc {
106
107         try {
108             // calculate the new resource Title property value
109
String JavaDoc title = computeNewTitleProperty();
110             // get the full resource name
111
String JavaDoc fullResourceName = computeFullResourceName();
112             // create the Title and Navigation properties if configured
113
List JavaDoc properties = createResourceProperties(
114                 fullResourceName,
115                 CmsResourceTypeFolder.getStaticTypeName(),
116                 title);
117             // create the folder
118
getCms().createResource(fullResourceName, CmsResourceTypeFolder.getStaticTypeId(), null, properties);
119             setParamResource(fullResourceName);
120             setResourceCreated(true);
121         } catch (Throwable JavaDoc e) {
122             // error creating folder, show error dialog
123
setParamMessage(Messages.get().getBundle(getLocale()).key(Messages.ERR_CREATE_FOLDER_0));
124             includeErrorpage(this, e);
125         }
126
127     }
128
129     /**
130      * Forwards to the property dialog if the resourceeditprops parameter is true.<p>
131      *
132      * If the parameter is not true, the dialog will be closed.<p>
133      *
134      * @throws IOException if forwarding to the property dialog fails
135      * @throws ServletException if forwarding to the property dialog fails
136      * @throws JspException if an inclusion fails
137      */

138     public void actionEditProperties() throws IOException JavaDoc, JspException JavaDoc, ServletException JavaDoc {
139
140         boolean editProps = Boolean.valueOf(getParamNewResourceEditProps()).booleanValue();
141         boolean createIndex = Boolean.valueOf(getParamCreateIndex()).booleanValue();
142         if (editProps) {
143             // edit properties of folder, forward to property dialog
144
Map JavaDoc params = new HashMap JavaDoc();
145             params.put(PARAM_RESOURCE, getParamResource());
146             if (createIndex) {
147                 // set dialogmode to wizard - create index page to indicate the creation of the index page
148
params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD_CREATEINDEX);
149             } else {
150                 // set dialogmode to wizard
151
params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD);
152             }
153             sendForward(CmsPropertyAdvanced.URI_PROPERTY_DIALOG_HANDLER, params);
154         } else if (createIndex) {
155             // create an index file in the new folder, redirect to new xmlpage dialog
156
String JavaDoc newFolder = getParamResource();
157             if (!newFolder.endsWith("/")) {
158                 newFolder += "/";
159             }
160             // set the current explorer resource to the new created folder
161
getSettings().setExplorerResource(newFolder);
162             String JavaDoc newUri = PATH_DIALOGS
163                 + OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypeXmlPage.getStaticTypeName()).getNewResourceUri();
164             CmsUriSplitter splitter = new CmsUriSplitter(newUri);
165             Map JavaDoc params = CmsRequestUtil.createParameterMap(splitter.getQuery());
166             params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD_CREATEINDEX);
167             sendForward(splitter.getPrefix(), params);
168         } else {
169             // edit properties and create index file not checked, close the dialog and update tree
170
List JavaDoc folderList = new ArrayList JavaDoc(1);
171             folderList.add(CmsResource.getParentFolder(getParamResource()));
172             getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
173             actionCloseDialog();
174         }
175     }
176
177     /**
178      * Returns the create index file parameter value.<p>
179      *
180      * @return the create index file parameter value
181      */

182     public String JavaDoc getParamCreateIndex() {
183
184         return m_paramCreateIndex;
185     }
186
187     /**
188      * Sets the create index file parameter value.<p>
189      *
190      * @param createIndex the create index file parameter value
191      */

192     public void setParamCreateIndex(String JavaDoc createIndex) {
193
194         m_paramCreateIndex = createIndex;
195     }
196
197     /**
198      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
199      */

200     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
201
202         // fill the parameter values in the get/set methods
203
fillParamValues(request);
204         // set the dialog type
205
setParamDialogtype(DIALOG_TYPE);
206         // set the action for the JSP switch
207
if (DIALOG_OK.equals(getParamAction())) {
208             setAction(ACTION_OK);
209         } else if (DIALOG_CANCEL.equals(getParamAction())) {
210             setAction(ACTION_CANCEL);
211         } else {
212             setAction(ACTION_DEFAULT);
213             // build title for new resource dialog
214
setParamTitle(key(Messages.GUI_NEWRESOURCE_FOLDER_0));
215         }
216     }
217
218 }
219
Popular Tags