KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsNewResource.java,v $
3  * Date : $Date: 2006/03/28 16:48:21 $
4  * Version: $Revision: 1.26 $
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.CmsProperty;
35 import org.opencms.file.CmsPropertyDefinition;
36 import org.opencms.file.CmsResource;
37 import org.opencms.file.CmsResourceFilter;
38 import org.opencms.file.types.I_CmsResourceType;
39 import org.opencms.i18n.CmsEncoder;
40 import org.opencms.jsp.CmsJspActionElement;
41 import org.opencms.jsp.CmsJspNavBuilder;
42 import org.opencms.jsp.CmsJspNavElement;
43 import org.opencms.main.CmsException;
44 import org.opencms.main.CmsIllegalArgumentException;
45 import org.opencms.main.CmsLog;
46 import org.opencms.main.CmsRuntimeException;
47 import org.opencms.main.OpenCms;
48 import org.opencms.security.CmsPermissionSet;
49 import org.opencms.security.CmsRole;
50 import org.opencms.util.CmsRequestUtil;
51 import org.opencms.util.CmsStringUtil;
52 import org.opencms.util.CmsUriSplitter;
53 import org.opencms.workplace.CmsDialog;
54 import org.opencms.workplace.CmsWorkplaceMessages;
55 import org.opencms.workplace.CmsWorkplaceSettings;
56 import org.opencms.workplace.commons.CmsPropertyAdvanced;
57
58 import java.io.IOException JavaDoc;
59 import java.lang.reflect.Constructor JavaDoc;
60 import java.util.ArrayList JavaDoc;
61 import java.util.Collections JavaDoc;
62 import java.util.HashMap JavaDoc;
63 import java.util.Iterator JavaDoc;
64 import java.util.List JavaDoc;
65 import java.util.Map JavaDoc;
66
67 import javax.servlet.ServletException JavaDoc;
68 import javax.servlet.http.HttpServletRequest JavaDoc;
69 import javax.servlet.http.HttpServletResponse JavaDoc;
70 import javax.servlet.jsp.JspException JavaDoc;
71 import javax.servlet.jsp.PageContext JavaDoc;
72
73 import org.apache.commons.logging.Log;
74
75 /**
76  * The new resource entry dialog which displays the possible "new actions" for the current user.<p>
77  *
78  * It handles the creation of "simple" resource types like plain or JSP resources.<p>
79  *
80  * The following files use this class:
81  * <ul>
82  * <li>/commons/newresource.jsp
83  * </ul>
84  * <p>
85  *
86  * @author Andreas Zahner
87  * @author Armen Markarian
88  *
89  * @version $Revision: 1.26 $
90  *
91  * @since 6.0.0
92  */

93 public class CmsNewResource extends CmsDialog {
94
95     /** The value for the resource name form action. */
96     public static final int ACTION_NEWFORM = 100;
97
98     /** The value for the resource name form submission action. */
99     public static final int ACTION_SUBMITFORM = 110;
100
101     /** Constant for the "Next" button in the build button methods. */
102     public static final int BUTTON_NEXT = 20;
103
104     /** Delimiter for property values, e.g. for available resource types or template sites. */
105     public static final char DELIM_PROPERTYVALUES = ',';
106
107     /** The name for the advanced resource form action. */
108     public static final String JavaDoc DIALOG_ADVANCED = "advanced";
109
110     /** The name for the resource form action. */
111     public static final String JavaDoc DIALOG_NEWFORM = "newform";
112
113     /** The name for the resource form submission action. */
114     public static final String JavaDoc DIALOG_SUBMITFORM = "submitform";
115
116     /** The dialog type. */
117     public static final String JavaDoc DIALOG_TYPE = "newresource";
118
119     /** Request parameter name for the append html suffix checkbox. */
120     public static final String JavaDoc PARAM_APPENDSUFFIXHTML = "appendsuffixhtml";
121
122     /** Request parameter name for the current folder name. */
123     public static final String JavaDoc PARAM_CURRENTFOLDER = "currentfolder";
124
125     /** Request parameter name for the new resource edit properties flag. */
126     public static final String JavaDoc PARAM_NEWRESOURCEEDITPROPS = "newresourceeditprops";
127
128     /** Request parameter name for the new resource type. */
129     public static final String JavaDoc PARAM_NEWRESOURCETYPE = "newresourcetype";
130
131     /** Request parameter name for the new resource uri. */
132     public static final String JavaDoc PARAM_NEWRESOURCEURI = "newresourceuri";
133
134     /** The property value for available resource to reset behaviour to default dialog. */
135     public static final String JavaDoc VALUE_DEFAULT = "default";
136
137     /** The log object for this class. */
138     private static final Log LOG = CmsLog.getLog(CmsNewResource.class);
139
140     private String JavaDoc m_availableResTypes;
141     private boolean m_limitedRestypes;
142     private String JavaDoc m_page;
143
144     private String JavaDoc m_paramAppendSuffixHtml;
145     private String JavaDoc m_paramCurrentFolder;
146     private String JavaDoc m_paramNewResourceEditProps;
147     private String JavaDoc m_paramNewResourceType;
148     private String JavaDoc m_paramNewResourceUri;
149     private String JavaDoc m_paramPage;
150
151     /** a boolean flag that indicates if the create resource operation was successfull or not. */
152     private boolean m_resourceCreated;
153
154     /**
155      * Public constructor with JSP action element.<p>
156      *
157      * @param jsp an initialized JSP action element
158      */

159     public CmsNewResource(CmsJspActionElement jsp) {
160
161         super(jsp);
162     }
163
164     /**
165      * Public constructor with JSP variables.<p>
166      *
167      * @param context the JSP page context
168      * @param req the JSP request
169      * @param res the JSP response
170      */

171     public CmsNewResource(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
172
173         this(new CmsJspActionElement(context, req, res));
174     }
175
176     /**
177      * A factory to return handlers to create new resources.<p>
178      *
179      * @param type the resource type name to get a new resource handler for, as specified in the explorer type settings
180      * @param defaultClassName a default handler class name, to be used if the handler class specified in the explorer type settings cannot be found
181      * @param context the JSP page context
182      * @param req the JSP request
183      * @param res the JSP response
184      * @return a new instance of the handler class
185      * @throws CmsRuntimeException if something goes wrong
186      */

187     public static Object JavaDoc getNewResourceHandler(
188         String JavaDoc type,
189         String JavaDoc defaultClassName,
190         PageContext JavaDoc context,
191         HttpServletRequest JavaDoc req,
192         HttpServletResponse JavaDoc res) throws CmsRuntimeException {
193
194         if (CmsStringUtil.isEmpty(type)) {
195             // it's not possible to hardwire the resource type name on the JSP for Xml content types
196
type = req.getParameter(PARAM_NEWRESOURCETYPE);
197         }
198
199         String JavaDoc className = null;
200         CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(type);
201
202         if (CmsStringUtil.isNotEmpty(settings.getNewResourceHandlerClassName())) {
203             className = settings.getNewResourceHandlerClassName();
204         } else {
205             className = defaultClassName;
206         }
207
208         Class JavaDoc clazz = null;
209         try {
210             clazz = Class.forName(className);
211         } catch (ClassNotFoundException JavaDoc e) {
212
213             if (LOG.isErrorEnabled()) {
214                 LOG.error(Messages.get().getBundle().key(Messages.ERR_NEW_RES_HANDLER_CLASS_NOT_FOUND_1, className), e);
215             }
216             throw new CmsIllegalArgumentException(Messages.get().container(
217                 Messages.ERR_NEW_RES_HANDLER_CLASS_NOT_FOUND_1,
218                 className));
219         }
220
221         Object JavaDoc handler = null;
222         try {
223             Constructor JavaDoc constructor = clazz.getConstructor(new Class JavaDoc[] {
224                 PageContext JavaDoc.class,
225                 HttpServletRequest JavaDoc.class,
226                 HttpServletResponse JavaDoc.class});
227             handler = constructor.newInstance(new Object JavaDoc[] {context, req, res});
228         } catch (Exception JavaDoc e) {
229
230             throw new CmsIllegalArgumentException(Messages.get().container(
231                 Messages.ERR_NEW_RES_CONSTRUCTOR_NOT_FOUND_1,
232                 className));
233         }
234
235         return handler;
236     }
237
238     /**
239      * Creates the resource using the specified resource name and the newresourcetype parameter.<p>
240      *
241      * @throws JspException if inclusion of error dialog fails
242      */

243     public void actionCreateResource() throws JspException JavaDoc {
244
245         try {
246             // calculate the new resource Title property value
247
String JavaDoc title = computeNewTitleProperty();
248             // create the full resource name
249
String JavaDoc fullResourceName = computeFullResourceName();
250             // create the Title and Navigation properties if configured
251
I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(getParamNewResourceType());
252             List JavaDoc properties = createResourceProperties(fullResourceName, resType.getTypeName(), title);
253             // create the resource
254
getCms().createResource(fullResourceName, resType.getTypeId(), null, properties);
255             setParamResource(fullResourceName);
256
257             setResourceCreated(true);
258         } catch (Throwable JavaDoc e) {
259             // error creating file, show error dialog
260
includeErrorpage(this, e);
261         }
262     }
263
264     /**
265      * Forwards to the property dialog if the resourceeditprops parameter is true.<p>
266      *
267      * If the parameter is not true, the dialog will be closed.<p>
268      *
269      * @throws IOException if forwarding to the property dialog fails
270      * @throws ServletException if forwarding to the property dialog fails
271      * @throws JspException if an inclusion fails
272      */

273     public void actionEditProperties() throws IOException JavaDoc, JspException JavaDoc, ServletException JavaDoc {
274
275         boolean editProps = Boolean.valueOf(getParamNewResourceEditProps()).booleanValue();
276         if (editProps) {
277             // edit properties checkbox checked, forward to property dialog
278
Map JavaDoc params = new HashMap JavaDoc();
279             params.put(PARAM_RESOURCE, getParamResource());
280             params.put(CmsPropertyAdvanced.PARAM_DIALOGMODE, CmsPropertyAdvanced.MODE_WIZARD);
281             sendForward(CmsPropertyAdvanced.URI_PROPERTY_DIALOG_HANDLER, params);
282         } else {
283             // edit properties not checked, close the dialog
284
actionCloseDialog();
285         }
286     }
287
288     /**
289      * Forwards to the next page of the new resource wizard after selecting the new resource type.<p>
290      *
291      * @throws IOException if forwarding fails
292      * @throws ServletException if forwarding fails
293      */

294     public void actionSelect() throws IOException JavaDoc, ServletException JavaDoc {
295
296         String JavaDoc nextUri = getParamNewResourceUri();
297         if (!nextUri.startsWith("/")) {
298             // no absolute path given, use default dialog path
299
nextUri = PATH_DIALOGS + nextUri;
300         }
301
302         setParamAction(DIALOG_NEWFORM);
303         CmsUriSplitter splitter = new CmsUriSplitter(nextUri);
304         Map JavaDoc params = CmsRequestUtil.createParameterMap(splitter.getQuery());
305         params.putAll(paramsAsParameterMap());
306         sendForward(splitter.getPrefix(), params);
307     }
308
309     /**
310      * Builds the html for the list of possible new resources.<p>
311      *
312      * @param attributes optional attributes for the radio input tags
313      * @return the html for the list of possible new resources
314      */

315     public String JavaDoc buildNewList(String JavaDoc attributes) {
316
317         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
318         result.append("<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">");
319
320         Iterator JavaDoc i;
321         if (m_limitedRestypes) {
322             // available resource types limited, create list iterator of given limited types
323
List JavaDoc newResTypes = CmsStringUtil.splitAsList(m_availableResTypes, DELIM_PROPERTYVALUES);
324             Iterator JavaDoc k = newResTypes.iterator();
325             List JavaDoc settings = new ArrayList JavaDoc(newResTypes.size());
326             while (k.hasNext()) {
327                 String JavaDoc resType = (String JavaDoc)k.next();
328                 // get settings for resource type
329
CmsExplorerTypeSettings set = OpenCms.getWorkplaceManager().getExplorerTypeSetting(resType);
330                 if (set != null) {
331                     // add found setting to available resource types
332
settings.add(set);
333                 }
334             }
335             // sort explorer type settings by their order
336
Collections.sort(settings);
337             i = settings.iterator();
338         } else {
339             // create list iterator from all configured resource types
340
i = OpenCms.getWorkplaceManager().getExplorerTypeSettings().iterator();
341         }
342
343         while (i.hasNext()) {
344             CmsExplorerTypeSettings settings = (CmsExplorerTypeSettings)i.next();
345
346             if (!m_limitedRestypes) {
347                 // check for the "new resource" page
348
if (m_page == null) {
349                     if (CmsStringUtil.isNotEmpty(settings.getNewResourcePage())) {
350                         continue;
351                     }
352                 } else if (!m_page.equals(settings.getNewResourcePage())) {
353                     continue;
354                 }
355             }
356
357             if (CmsStringUtil.isEmpty(settings.getNewResourceUri())) {
358                 // no new resource URI specified for the current settings, dont't show the type
359
continue;
360             }
361
362             // check permissions for the type
363
CmsPermissionSet permissions = settings.getAccess().getPermissions(getCms());
364             if (!permissions.requiresControlPermission()) {
365                 // the type has no permission for the current user to be created, don't show the type
366
continue;
367             }
368
369             result.append("<tr>\n");
370             result.append("\t<td><input type=\"radio\" name=\"");
371             result.append(PARAM_NEWRESOURCEURI);
372             result.append("\"");
373             result.append(" value=\"" + CmsEncoder.encode(settings.getNewResourceUri()) + "\"");
374             if (CmsStringUtil.isNotEmpty(attributes)) {
375                 result.append(" " + attributes);
376             }
377             result.append("></td>\n");
378             result.append("\t<td><img SRC=\""
379                 + getSkinUri()
380                 + "filetypes/"
381                 + settings.getIcon()
382                 + "\" border=\"0\" title=\""
383                 + key(settings.getKey())
384                 + "\"></td>\n");
385             result.append("\t<td>" + key(settings.getKey()) + "</td>\n");
386             result.append("</tr>\n");
387
388         }
389         result.append("</table>\n");
390
391         return result.toString();
392     }
393
394     /**
395      * Returns the value for the Title property from the given resource name.<p>
396      *
397      * Additionally translates the new resource name according to the file translation rules.<p>
398      *
399      * @return the value for the Title property from the given resource name
400      */

401     public String JavaDoc computeNewTitleProperty() {
402
403         String JavaDoc title = getParamResource();
404         int lastDot = title.lastIndexOf('.');
405         // check the mime type for the file extension
406
if ((lastDot > 0) && (lastDot < (title.length() - 1))) {
407             // remove suffix for Title and NavPos property
408
title = title.substring(0, lastDot);
409         }
410         // translate the resource name to a valid OpenCms VFS file name
411
String JavaDoc resName = CmsResource.getName(getParamResource().replace('\\', '/'));
412         setParamResource(getCms().getRequestContext().getFileTranslator().translateResource(resName));
413         return title;
414     }
415
416     /**
417      * Builds a button row with an optional "advanced", "next" and a "cancel" button.<p>
418      *
419      * @param advancedAttrs optional attributes for the advanced button
420      * @param nextAttrs optional attributes for the next button
421      * @param cancelAttrs optional attributes for the cancel button
422      * @return the button row
423      */

424     public String JavaDoc dialogButtonsAdvancedNextCancel(String JavaDoc advancedAttrs, String JavaDoc nextAttrs, String JavaDoc cancelAttrs) {
425
426         if (m_limitedRestypes && getCms().hasRole(CmsRole.VFS_MANAGER)) {
427             return dialogButtons(new int[] {BUTTON_ADVANCED, BUTTON_NEXT, BUTTON_CANCEL}, new String JavaDoc[] {
428                 advancedAttrs,
429                 nextAttrs,
430                 cancelAttrs});
431         } else {
432             return dialogButtons(new int[] {BUTTON_NEXT, BUTTON_CANCEL}, new String JavaDoc[] {nextAttrs, cancelAttrs});
433         }
434     }
435
436     /**
437      * Builds a button row with a "next" and a "cancel" button.<p>
438      *
439      * @param nextAttrs optional attributes for the next button
440      * @param cancelAttrs optional attributes for the cancel button
441      * @return the button row
442      */

443     public String JavaDoc dialogButtonsNextCancel(String JavaDoc nextAttrs, String JavaDoc cancelAttrs) {
444
445         return dialogButtons(new int[] {BUTTON_NEXT, BUTTON_CANCEL}, new String JavaDoc[] {nextAttrs, cancelAttrs});
446     }
447
448     /**
449      * Returns the parameter to check if a ".html" suffix should be added to the new resource name.<p>
450      *
451      * @return the parameter to check if a ".html" suffix should be added to the new resource name
452      */

453     public String JavaDoc getParamAppendSuffixHtml() {
454
455         return m_paramAppendSuffixHtml;
456     }
457
458     /**
459      * Returns the current folder set by the http request.<p>
460      *
461      * If the request parameter value is null/empty then returns the default computed folder.<p>
462      *
463      * @return the current folder set by the request param or the computed current folder
464      */

465     public String JavaDoc getParamCurrentFolder() {
466
467         if (CmsStringUtil.isEmpty(m_paramCurrentFolder)) {
468             return computeCurrentFolder();
469         }
470
471         return m_paramCurrentFolder;
472     }
473
474     /**
475      * Returns the new resource edit properties flag parameter.<p>
476      *
477      * @return the new resource edit properties flag parameter
478      */

479     public String JavaDoc getParamNewResourceEditProps() {
480
481         return m_paramNewResourceEditProps;
482     }
483
484     /**
485      * Returns the new resource type parameter.<p>
486      *
487      * @return the new resource type parameter
488      */

489     public String JavaDoc getParamNewResourceType() {
490
491         return m_paramNewResourceType;
492     }
493
494     /**
495      * Returns the new resource URI parameter.<p>
496      *
497      * @return the new resource URI parameter
498      */

499     public String JavaDoc getParamNewResourceUri() {
500
501         return m_paramNewResourceUri;
502     }
503
504     /**
505      * Returns the paramPage.<p>
506      *
507      * @return the paramPage
508      */

509     public String JavaDoc getParamPage() {
510
511         return m_paramPage;
512     }
513
514     /**
515      * Returns true if the resource is created successfully; otherwise false.<p>
516      *
517      * @return true if the resource is created successfully; otherwise false
518      */

519     public boolean isResourceCreated() {
520
521         return m_resourceCreated;
522     }
523
524     /**
525      * Sets the parameter to check if a ".html" suffix should be added to the new resource name.<p>
526      *
527      * @param paramAppendSuffixHtml the parameter to check if a ".html" suffix should be added to the new resource name
528      */

529     public void setParamAppendSuffixHtml(String JavaDoc paramAppendSuffixHtml) {
530
531         m_paramAppendSuffixHtml = paramAppendSuffixHtml;
532     }
533
534     /**
535      * Sets the current folder.<p>
536      *
537      * @param paramCurrentFolder the current folder to set
538      */

539     public void setParamCurrentFolder(String JavaDoc paramCurrentFolder) {
540
541         m_paramCurrentFolder = paramCurrentFolder;
542     }
543
544     /**
545      * Sets the new resource edit properties flag parameter.<p>
546      *
547      * @param newResourceEditProps the new resource edit properties flag parameter
548      */

549     public void setParamNewResourceEditProps(String JavaDoc newResourceEditProps) {
550
551         m_paramNewResourceEditProps = newResourceEditProps;
552     }
553
554     /**
555      * Sets the new resource type parameter.<p>
556      *
557      * @param newResourceType the new resource type parameter
558      */

559     public void setParamNewResourceType(String JavaDoc newResourceType) {
560
561         m_paramNewResourceType = newResourceType;
562     }
563
564     /**
565      * Sets the new resource URI parameter.<p>
566      *
567      * @param newResourceUri the new resource URI parameter
568      */

569     public void setParamNewResourceUri(String JavaDoc newResourceUri) {
570
571         m_paramNewResourceUri = newResourceUri;
572     }
573
574     /**
575      * Sets the paramPage.<p>
576      *
577      * @param paramPage the paramPage to set
578      */

579     public void setParamPage(String JavaDoc paramPage) {
580
581         m_paramPage = paramPage;
582     }
583
584     /**
585      * Sets the boolean flag successfullyCreated.<p>
586      *
587      * @param successfullyCreated a boolean flag that indicates if the create resource operation was successfull or not
588      */

589     public void setResourceCreated(boolean successfullyCreated) {
590
591         m_resourceCreated = successfullyCreated;
592     }
593
594     /**
595      * Appends a ".html" suffix to the given resource name if no suffix is present and the append suffix option is checked.<p>
596      *
597      * @param resourceName the resource name to check
598      * @param forceSuffix if true, the suffix is appended overriding the append suffix option
599      * @return the reource name with ".html" suffix if no suffix was present and the append suffix option is checked
600      */

601     protected String JavaDoc appendSuffixHtml(String JavaDoc resourceName, boolean forceSuffix) {
602
603         // append ".html" suffix to new file if not present
604
if ((forceSuffix || Boolean.valueOf(getParamAppendSuffixHtml()).booleanValue())
605             && resourceName.indexOf('.') < 0) {
606             resourceName += ".html";
607         }
608         return resourceName;
609     }
610
611     /**
612      * Returns the full path of the current workplace folder.<p>
613      *
614      * @return the full path of the current workplace folder
615      */

616     protected String JavaDoc computeCurrentFolder() {
617
618         String JavaDoc currentFolder = getSettings().getExplorerResource();
619         if (currentFolder == null) {
620             // set current folder to root folder
621
try {
622                 currentFolder = getCms().getSitePath(getCms().readFolder("/", CmsResourceFilter.IGNORE_EXPIRATION));
623             } catch (CmsException e) {
624                 // can usually be ignored
625
if (LOG.isInfoEnabled()) {
626                     LOG.info(e);
627                 }
628                 currentFolder = "/";
629             }
630         }
631         if (!currentFolder.endsWith("/")) {
632             // add folder separator to currentFolder
633
currentFolder += "/";
634         }
635         return currentFolder;
636     }
637
638     /**
639      * Appends the full path to the new resource name given in the resource parameter.<p>
640      *
641      * @return the full path of the new resource
642      */

643     protected String JavaDoc computeFullResourceName() {
644
645         // return the full resource name
646
// get the current folder
647
String JavaDoc currentFolder = getParamCurrentFolder();
648         if (CmsStringUtil.isEmpty(currentFolder)) {
649             currentFolder = computeCurrentFolder();
650         }
651         return currentFolder + getParamResource();
652     }
653
654     /**
655      * Creates a single property object and sets the value individual or shared depending on the OpenCms settings.<p>
656      *
657      * @param name the name of the property
658      * @param value the value to set
659      * @return an initialized property object
660      */

661     protected CmsProperty createPropertyObject(String JavaDoc name, String JavaDoc value) {
662
663         CmsProperty prop = new CmsProperty();
664         prop.setAutoCreatePropertyDefinition(true);
665         prop.setName(name);
666         if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
667             prop.setValue(value, CmsProperty.TYPE_INDIVIDUAL);
668         } else {
669             prop.setValue(value, CmsProperty.TYPE_SHARED);
670         }
671         return prop;
672     }
673
674     /**
675      * Returns the properties to create automatically with the new VFS resource.<p>
676      *
677      * If configured, the Title and Navigation properties are set on resource creation.<p>
678      *
679      * @param resourceName the full resource name
680      * @param resTypeName the name of the resource type
681      * @param title the Title String to use for the property values
682      * @return the List of initialized property objects
683      */

684     protected List JavaDoc createResourceProperties(String JavaDoc resourceName, String JavaDoc resTypeName, String JavaDoc title) {
685
686         // create property values
687
List JavaDoc properties = new ArrayList JavaDoc(3);
688         // get explorer type settings for the resource type
689
CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(resTypeName);
690         if (settings.isAutoSetTitle()) {
691             // add the Title property
692
properties.add(createPropertyObject(CmsPropertyDefinition.PROPERTY_TITLE, title));
693         }
694         if (settings.isAutoSetNavigation()) {
695             // add the NavText property
696
properties.add(createPropertyObject(CmsPropertyDefinition.PROPERTY_NAVTEXT, title));
697             // calculate the new navigation position for the resource
698
List JavaDoc navList = CmsJspNavBuilder.getNavigationForFolder(getCms(), resourceName);
699             float navPos = 1;
700             if (navList.size() > 0) {
701                 CmsJspNavElement nav = (CmsJspNavElement)navList.get(navList.size() - 1);
702                 navPos = nav.getNavPosition() + 1;
703             }
704             // add the NavPos property
705
properties.add(createPropertyObject(CmsPropertyDefinition.PROPERTY_NAVPOS, String.valueOf(navPos)));
706         }
707         return properties;
708     }
709
710     /**
711      * @see org.opencms.workplace.CmsDialog#dialogButtonsHtml(java.lang.StringBuffer, int, java.lang.String)
712      */

713     protected void dialogButtonsHtml(StringBuffer JavaDoc result, int button, String JavaDoc attribute) {
714
715         attribute = appendDelimiter(attribute);
716
717         switch (button) {
718             case BUTTON_NEXT:
719                 result.append("<input name=\"next\" type=\"submit\" value=\"");
720                 result.append(key(Messages.GUI_BUTTON_NEXTSCREEN_0));
721                 result.append("\" class=\"dialogbutton\"");
722                 result.append(attribute);
723                 result.append(">\n");
724                 break;
725             default:
726                 super.dialogButtonsHtml(result, button, attribute);
727         }
728     }
729
730     /**
731      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
732      */

733     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
734
735         // fill the parameter values in the get/set methods
736
fillParamValues(request);
737         // set the dialog type
738
setParamDialogtype(DIALOG_TYPE);
739
740         if (CmsStringUtil.isNotEmpty(getParamPage())) {
741             m_page = getParamPage();
742             setParamAction(null);
743             setParamNewResourceUri(null);
744             setParamPage(null);
745         }
746
747         // set the action for the JSP switch
748
if (DIALOG_OK.equals(getParamAction())) {
749             setAction(ACTION_OK);
750         } else if (DIALOG_SUBMITFORM.equals(getParamAction())) {
751             setAction(ACTION_SUBMITFORM);
752         } else if (DIALOG_NEWFORM.equals(getParamAction())) {
753             setAction(ACTION_NEWFORM);
754             String JavaDoc title = CmsWorkplaceMessages.getNewResourceTitle(this, getParamNewResourceType());
755             setParamTitle(title);
756         } else if (DIALOG_CANCEL.equals(getParamAction())) {
757             setAction(ACTION_CANCEL);
758         } else {
759             setAction(ACTION_DEFAULT);
760             // build title for new resource dialog
761
setParamTitle(key(Messages.GUI_NEWRESOURCE_0));
762
763             if (!DIALOG_ADVANCED.equals(getParamAction()) && CmsStringUtil.isEmpty(m_page)) {
764                 // check for presence of property limiting the new resource types to create
765
String JavaDoc newResTypesProperty = "";
766                 try {
767                     newResTypesProperty = getCms().readPropertyObject(
768                         getParamCurrentFolder(),
769                         CmsPropertyDefinition.PROPERTY_RESTYPES_AVAILABLE,
770                         true).getValue();
771                 } catch (CmsException e) {
772                     // ignore this exception, this is a minor issue
773
}
774                 if (CmsStringUtil.isNotEmpty(newResTypesProperty) && !newResTypesProperty.equals(VALUE_DEFAULT)) {
775                     m_limitedRestypes = true;
776                     m_availableResTypes = newResTypesProperty;
777                 }
778             }
779         }
780     }
781 }
Popular Tags