KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/explorer/CmsNewResourceUpload.java,v $
3  * Date : $Date: 2006/09/22 15:17:06 $
4  * Version: $Revision: 1.23 $
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.db.CmsDbSqlException;
35 import org.opencms.db.CmsImportFolder;
36 import org.opencms.file.CmsFile;
37 import org.opencms.file.CmsProject;
38 import org.opencms.file.CmsProperty;
39 import org.opencms.file.CmsPropertyDefinition;
40 import org.opencms.file.CmsResource;
41 import org.opencms.file.CmsResourceFilter;
42 import org.opencms.file.types.I_CmsResourceType;
43 import org.opencms.jsp.CmsJspActionElement;
44 import org.opencms.main.OpenCms;
45 import org.opencms.util.CmsStringUtil;
46 import org.opencms.workplace.CmsWorkplace;
47 import org.opencms.workplace.CmsWorkplaceException;
48 import org.opencms.workplace.CmsWorkplaceSettings;
49 import org.opencms.workplace.commons.CmsChtype;
50
51 import java.util.ArrayList JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.List JavaDoc;
54 import java.util.Map JavaDoc;
55
56 import javax.servlet.http.HttpServletRequest JavaDoc;
57 import javax.servlet.http.HttpServletResponse JavaDoc;
58 import javax.servlet.http.HttpSession JavaDoc;
59 import javax.servlet.jsp.JspException JavaDoc;
60 import javax.servlet.jsp.PageContext JavaDoc;
61
62 import org.apache.commons.fileupload.FileItem;
63
64 /**
65  * The new resource upload dialog handles the upload of single files or zipped files.<p>
66  *
67  * The following files use this class:
68  * <ul>
69  * <li>/commons/newresource_upload.jsp
70  * </ul>
71  * <p>
72  *
73  * @author Andreas Zahner
74  *
75  * @version $Revision: 1.23 $
76  *
77  * @since 6.0.0
78  */

79 public class CmsNewResourceUpload extends CmsNewResource {
80
81     /** The value for the resource upload applet action. */
82     public static final int ACTION_APPLET = 140;
83
84     /** The value for the resource name form action. */
85     public static final int ACTION_NEWFORM2 = 120;
86
87     /** The value for the resource upload applet action: error occured. */
88     public static final int ACTION_SHOWERROR = 150;
89
90     /** The value for the resource name form submission action. */
91     public static final int ACTION_SUBMITFORM2 = 130;
92
93     /** The name for the resource form submission action. */
94     public static final String JavaDoc DIALOG_SHOWERROR = "showerror";
95
96     /** The name for the resource form submission action. */
97     public static final String JavaDoc DIALOG_SUBMITFORM2 = "submitform2";
98
99     /** Request parameter name for the new resource file name. */
100     public static final String JavaDoc PARAM_NEWRESOURCENAME = "newresourcename";
101
102     /** Request parameter name for the redirect url. */
103     public static final String JavaDoc PARAM_REDIRECTURL = "redirecturl";
104
105     /** Request parameter name for the redirect target frame name. */
106     public static final String JavaDoc PARAM_TARGETFRAME = "targetframe";
107
108     /** Request parameter name for the upload file unzip flag. */
109     public static final String JavaDoc PARAM_UNZIPFILE = "unzipfile";
110
111     /** Request parameter name for the upload file name. */
112     public static final String JavaDoc PARAM_UPLOADERROR = "uploaderror";
113
114     /** Request parameter name for the upload file name. */
115     public static final String JavaDoc PARAM_UPLOADFILE = "uploadfile";
116
117     /** Request parameter name for the upload folder name. */
118     public static final String JavaDoc PARAM_UPLOADFOLDER = "uploadfolder";
119
120     private String JavaDoc m_paramNewResourceName;
121     private String JavaDoc m_paramRedirectUrl;
122     private String JavaDoc m_paramTargetFrame;
123     private String JavaDoc m_paramUnzipFile;
124     private String JavaDoc m_paramUploadError;
125     private String JavaDoc m_paramUploadFile;
126     private String JavaDoc m_paramUploadFolder;
127
128     /**
129      * Public constructor with JSP action element.<p>
130      *
131      * @param jsp an initialized JSP action element
132      */

133     public CmsNewResourceUpload(CmsJspActionElement jsp) {
134
135         super(jsp);
136     }
137
138     /**
139      * Public constructor with JSP variables.<p>
140      *
141      * @param context the JSP page context
142      * @param req the JSP request
143      * @param res the JSP response
144      */

145     public CmsNewResourceUpload(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
146
147         this(new CmsJspActionElement(context, req, res));
148     }
149
150     /**
151      * Used to close the current JSP dialog.<p>
152      *
153      * This method overwrites the close dialog method in the super class,
154      * because in case a new file was uploaded and the cancel button pressed,
155      * the uploaded file has to be deleted.<p>
156      *
157      * It tries to include the URI stored in the workplace settings.
158      * This URI is determined by the frame name, which has to be set
159      * in the framename parameter.<p>
160      *
161      * @throws JspException if including an element fails
162      */

163     public void actionCloseDialog() throws JspException JavaDoc {
164
165         if (getAction() == ACTION_CANCEL) {
166             try {
167                 CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
168                 if (res.getState() == CmsResource.STATE_NEW) {
169                     // only delete new resource
170
getCms().deleteResource(getParamResource(), CmsResource.DELETE_PRESERVE_SIBLINGS);
171                 }
172                 if (res.getState() == CmsResource.STATE_CHANGED) {
173                     // resource is changed, restore content of resource from online project
174
CmsProject currentProject = getCms().getRequestContext().currentProject();
175                     byte[] onlineContents = null;
176                     try {
177                         // switch to online project and get online file contents
178
getCms().getRequestContext().setCurrentProject(
179                             getCms().readProject(CmsProject.ONLINE_PROJECT_ID));
180                         CmsFile onlineFile = getCms().readFile(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
181                         onlineContents = onlineFile.getContents();
182                         
183                     } finally {
184                         // switch back to current project
185
getCms().getRequestContext().setCurrentProject(currentProject);
186                     }
187                     if (onlineContents != null) {
188                         // write online contents back to offline file
189
CmsFile modFile = getCms().readFile(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
190                         modFile.setContents(onlineContents);
191                         getCms().writeFile(modFile);
192                     }
193                 }
194             } catch (RuntimeException JavaDoc e) {
195                 // assume file was not present
196
} catch (Exception JavaDoc e) {
197                 // assume file was not present
198
}
199         }
200         super.actionCloseDialog();
201     }
202
203     /**
204      * Updates the file type and renames the file if desired.<p>
205      *
206      * @throws JspException if inclusion of error dialog fails
207      */

208     public void actionUpdateFile() throws JspException JavaDoc {
209
210         try {
211             CmsResource res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
212             I_CmsResourceType oldType = OpenCms.getResourceManager().getResourceType(res.getTypeId());
213             if (!oldType.getTypeName().equals(getParamNewResourceType())) {
214                 // change the type of the uploaded resource
215
int newType = OpenCms.getResourceManager().getResourceType(getParamNewResourceType()).getTypeId();
216                 getCms().chtype(getParamResource(), newType);
217             }
218             if ((getParamNewResourceName() != null) && !getParamResource().endsWith(getParamNewResourceName())) {
219                 String JavaDoc newResourceName = CmsResource.getFolderPath(getParamResource()) + getParamNewResourceName();
220                 // rename the resource
221
getCms().renameResource(getParamResource(), newResourceName);
222                 setParamResource(newResourceName);
223             }
224         } catch (Throwable JavaDoc e) {
225             // error updating file, show error dialog
226
setParamMessage(Messages.get().getBundle(getLocale()).key(Messages.ERR_UPLOAD_FILE_0));
227             includeErrorpage(this, e);
228         }
229     }
230
231     /**
232      * Uploads the specified file and unzips it, if selected.<p>
233      *
234      * @throws JspException if inclusion of error dialog fails
235      */

236     public void actionUpload() throws JspException JavaDoc {
237
238         // determine the type of upload
239
boolean unzipFile = Boolean.valueOf(getParamUnzipFile()).booleanValue();
240         // Suffix for error messages (e.g. when exceeding the maximum file upload size)
241

242         try {
243             // get the file item from the multipart request
244
Iterator JavaDoc i = getMultiPartFileItems().iterator();
245             FileItem fi = null;
246             while (i.hasNext()) {
247                 fi = (FileItem)i.next();
248                 if (fi.getName() != null) {
249                     // found the file object, leave iteration
250
break;
251                 } else {
252                     // this is no file object, check next item
253
continue;
254                 }
255             }
256
257             if (fi != null) {
258                 String JavaDoc fileName = fi.getName();
259                 long size = fi.getSize();
260                 long maxFileSizeBytes = OpenCms.getWorkplaceManager().getFileBytesMaxUploadSize(getCms());
261                 // check file size
262
if ((maxFileSizeBytes > 0) && (size > maxFileSizeBytes)) {
263                     // file size is larger than maximum allowed file size, throw an error
264
throw new CmsWorkplaceException(Messages.get().container(
265                         Messages.ERR_UPLOAD_FILE_SIZE_TOO_HIGH_1,
266                         new Long JavaDoc(maxFileSizeBytes / 1024)));
267                 }
268                 byte[] content = fi.get();
269                 fi.delete();
270
271                 if (unzipFile) {
272                     // zip file upload
273
String JavaDoc currentFolder = getParamUploadFolder();
274                     if (CmsStringUtil.isEmpty(currentFolder)) {
275                         // no upload folder parameter found, get current folder
276
currentFolder = getParamCurrentFolder();
277                     }
278                     if (CmsStringUtil.isEmpty(currentFolder) || !currentFolder.startsWith("/")) {
279                         // no folder information found, guess upload folder
280
currentFolder = computeCurrentFolder();
281                     }
282                     // import the zip contents
283
new CmsImportFolder(content, currentFolder, getCms(), false);
284
285                 } else {
286                     // single file upload
287
String JavaDoc newResname = CmsResource.getName(fileName.replace('\\', '/'));
288                     // determine Title property value to set on new resource
289
String JavaDoc title = newResname;
290                     if (title.lastIndexOf('.') != -1) {
291                         title = title.substring(0, title.lastIndexOf('.'));
292                     }
293                     List JavaDoc properties = new ArrayList JavaDoc(1);
294                     CmsProperty titleProp = new CmsProperty();
295                     titleProp.setName(CmsPropertyDefinition.PROPERTY_TITLE);
296                     if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
297                         titleProp.setStructureValue(title);
298                     } else {
299                         titleProp.setResourceValue(title);
300                     }
301                     properties.add(titleProp);
302                     newResname = getCms().getRequestContext().getFileTranslator().translateResource(newResname);
303                     setParamNewResourceName(newResname);
304                     setParamResource(newResname);
305                     setParamResource(computeFullResourceName());
306                     // determine the resource type id from the given information
307
int resTypeId = OpenCms.getResourceManager().getDefaultTypeForName(newResname).getTypeId();
308                     if (! getCms().existsResource(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION)) {
309                         try {
310                             // create the resource
311
getCms().createResource(getParamResource(), resTypeId, content, properties);
312                         } catch (CmsDbSqlException sqlExc) {
313                             // SQL error, probably the file is too large for the database settings, delete file
314
getCms().lockResource(getParamResource());
315                             getCms().deleteResource(getParamResource(), CmsResource.DELETE_PRESERVE_SIBLINGS);
316                             throw sqlExc;
317                         }
318                     } else {
319                         checkLock(getParamResource());
320                         CmsFile file = getCms().readFile(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
321                         byte[] contents = file.getContents();
322                         try {
323                             getCms().replaceResource(getParamResource(), resTypeId, content, null);
324                         } catch (CmsDbSqlException sqlExc) {
325                             // SQL error, probably the file is too large for the database settings, restore content
326
file.setContents(contents);
327                             getCms().writeFile(file);
328                             throw sqlExc;
329                         }
330                     }
331                 }
332             } else {
333                 throw new CmsWorkplaceException(Messages.get().container(Messages.ERR_UPLOAD_FILE_NOT_FOUND_0));
334             }
335         } catch (Throwable JavaDoc e) {
336             // error uploading file, show error dialog
337
setParamMessage(Messages.get().getBundle(getLocale()).key(Messages.ERR_UPLOAD_FILE_0));
338             setAction(ACTION_SHOWERROR);
339             includeErrorpage(this, e);
340         }
341     }
342
343     /**
344      * Builds the list of possible types for the uploaded file.<p>
345      *
346      * @return the list of possible files for the uploaded resource
347      */

348     public String JavaDoc buildTypeList() {
349
350         return CmsChtype.buildTypeList(this, false);
351     }
352
353     /**
354      * Creates the HTML code of the file upload applet with all required parameters.<p>
355      *
356      * @return string containing the applet HTML code
357      */

358     public String JavaDoc createAppletCode() {
359
360         StringBuffer JavaDoc applet = new StringBuffer JavaDoc(2048);
361
362         // collect some required server data first
363
String JavaDoc scheme = getJsp().getRequest().getScheme();
364         String JavaDoc host = getJsp().getRequest().getServerName();
365         String JavaDoc path = OpenCms.getSystemInfo().getContextPath() + OpenCms.getSystemInfo().getServletPath();
366         int port = getJsp().getRequest().getServerPort();
367         String JavaDoc webapp = scheme + "://" + host + ":" + port + OpenCms.getSystemInfo().getContextPath();
368
369         // get all file extensions
370
String JavaDoc fileExtensions = "";
371         Map JavaDoc extensions = OpenCms.getResourceManager().getExtensionMapping();
372         Iterator JavaDoc keys = extensions.entrySet().iterator();
373         while (keys.hasNext()) {
374             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)keys.next();
375             String JavaDoc key = (String JavaDoc)entry.getKey();
376             String JavaDoc value = (String JavaDoc)entry.getValue();
377             fileExtensions += key + "=" + value + ",";
378         }
379         fileExtensions = fileExtensions.substring(0, fileExtensions.length() - 1);
380
381         // get the file size upload limitation value (value is in bytes for the applet)
382
long maxFileSize = OpenCms.getWorkplaceManager().getFileBytesMaxUploadSize(getCms());
383
384         // get the current folder
385
String JavaDoc currentFolder = getParamCurrentFolder();
386
387         // get the current session id
388
HttpSession JavaDoc session = getJsp().getRequest().getSession(false);
389         // we assume we always have a session here, otherwise an unhandled NPE will occur
390
String JavaDoc sessionId = session.getId();
391
392         // define the required colors.
393
// currently this is hard coded here
394
String JavaDoc colors = "bgColor=#C0C0C0,outerBorderRightBottom=#333333,outerBorderLeftTop=#C0C0C0";
395         colors += ",innerBorderRightBottom=#777777,innerBorderLeftTop=#F0F0F0";
396         colors += ",bgHeadline=#000066,colorHeadline=#FFFFFF";
397         colors += ",colorText=#000000,progessBar=#E10050";
398
399         // create the upload applet html code
400
applet.append("<applet code=\"org.opencms.applet.upload.FileUploadApplet.class\" archive=\"");
401         applet.append(webapp);
402         applet.append("/resources/components/upload_applet/upload.jar\" width=\"500\" height=\"100\">\n");
403         applet.append("<param name=\"opencms\" value=\"");
404         applet.append(scheme);
405         applet.append("://");
406         applet.append(host);
407         applet.append(":");
408         applet.append(port);
409         applet.append(getSkinUri());
410         applet.append("filetypes/\">\n");
411         applet.append("<param name=\"target\" value=\"");
412         applet.append(scheme);
413         applet.append("://");
414         applet.append(host);
415         applet.append(":");
416         applet.append(port);
417         applet.append(path);
418         applet.append("/system/workplace/commons/newresource_upload.jsp\">\n");
419         applet.append("<param name=\"redirect\" value=\"");
420         applet.append(scheme);
421         applet.append("://");
422         applet.append(host);
423         applet.append(":");
424         applet.append(port);
425         applet.append(path);
426         // check if the redirect url is given by request parameter. if not use the default
427
if (CmsStringUtil.isEmpty(getParamRedirectUrl())) {
428             applet.append(CmsWorkplace.FILE_EXPLORER_FILELIST);
429         } else {
430             applet.append(getParamRedirectUrl());
431         }
432         // append some parameters to prevent caching of URL by Applet
433
applet.append("?time=" + System.currentTimeMillis());
434         applet.append("\">\n");
435         applet.append("<param name=\"targetframe\" value=\"");
436         applet.append(getParamTargetFrame());
437         applet.append("\">\n");
438         applet.append("<param name=error value=\"");
439         applet.append(scheme);
440         applet.append("://");
441         applet.append(host);
442         applet.append(":");
443         applet.append(port);
444         applet.append(path);
445         applet.append("/system/workplace/action/explorer_files_new_upload.html\">\n");
446         applet.append("<param name=\"sessionId\" value=\"");
447         applet.append(sessionId);
448         applet.append("\">\n");
449         applet.append("<param name=\"filelist\" value=\"");
450         applet.append(currentFolder);
451         applet.append("\">\n");
452         applet.append("<param name=\"colors\" value=\"");
453         applet.append(colors);
454         applet.append("\">\n");
455         applet.append("<param name=\"fileExtensions\" value=\"");
456         applet.append(fileExtensions);
457         applet.append("\">\n\n");
458         applet.append("<param name=\"maxsize\" value=\"");
459         applet.append(maxFileSize);
460         applet.append("\">\n");
461         applet.append("<param name=\"actionOutputSelect\" value=\"");
462         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_SELECT_0));
463         applet.append("\">\n");
464         applet.append("<param name=\"actionOutputCount\"value=\"");
465         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_COUNT_0));
466         applet.append("\">\n");
467         applet.append("<param name=\"actionOutputCreate\" value=\"");
468         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_CREATE_0));
469         applet.append("\">\n");
470         applet.append("<param name=\"actionOutputUpload\" value=\"");
471         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_UPLOAD_0));
472         applet.append("\">\n");
473         applet.append("<param name=\"messageOutputUpload\" value=\"");
474         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_UPLOAD_0));
475         applet.append("\">\n");
476         applet.append("<param name=\"messageOutputErrorZip\" value=\"");
477         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_ERROR_ZIP_0));
478         applet.append("\">\n");
479         applet.append("<param name=\"messageOutputErrorSize\" value=\"");
480         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_ERROR_SIZE_0));
481         applet.append("\">\n");
482         applet.append("<param name=\"messageNoPreview\" value=\"");
483         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_NOPREVIEW_0));
484         applet.append("\">\n");
485         applet.append("<param name=\"messageOutputAdding\" value=\"");
486         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_ADDING_0));
487         applet.append(" \">\n");
488         applet.append("<param name=\"errorTitle\" value=\"");
489         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ERROR_TITLE_0));
490         applet.append(" \">\n");
491         applet.append("<param name=\"errorLine1\" value=\"");
492         applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ERROR_LINE1_0));
493         applet.append(" \">\n");
494         applet.append("</applet>\n");
495
496         return applet.toString();
497
498     }
499
500     /**
501      * Returns the new resource name of the uploaded file.<p>
502      *
503      * @return the new resource name of the uploaded file
504      */

505     public String JavaDoc getParamNewResourceName() {
506
507         return m_paramNewResourceName;
508     }
509
510     /**
511      * Returns the paramRedirectUrl.<p>
512      *
513      * @return the paramRedirectUrl
514      */

515     public String JavaDoc getParamRedirectUrl() {
516
517         return m_paramRedirectUrl;
518     }
519
520     /**
521      * Returns the paramTargetFrame.<p>
522      *
523      * @return the paramTargetFrame
524      */

525     public String JavaDoc getParamTargetFrame() {
526
527         if (CmsStringUtil.isEmpty(m_paramTargetFrame)) {
528             return "explorer_files";
529         }
530
531         return m_paramTargetFrame;
532     }
533
534     /**
535      * Returns true if the upload file should be unzipped, otherwise false.<p>
536      *
537      * @return true if the upload file should be unzipped, otherwise false
538      */

539     public String JavaDoc getParamUnzipFile() {
540
541         return m_paramUnzipFile;
542     }
543
544     /**
545      * Returns the upload error message for the error dialog.<p>
546      *
547      * @return the upload error message for the error dialog
548      */

549     public String JavaDoc getParamUploadError() {
550
551         return m_paramUploadError;
552     }
553
554     /**
555      * Returns the upload file name.<p>
556      *
557      * @return the upload file name
558      */

559     public String JavaDoc getParamUploadFile() {
560
561         return m_paramUploadFile;
562     }
563
564     /**
565      * Returns the upload folder name.<p>
566      *
567      * @return the upload folder name
568      */

569     public String JavaDoc getParamUploadFolder() {
570
571         return m_paramUploadFolder;
572     }
573
574     /**
575      * Sets the new resource name of the uploaded file.<p>
576      *
577      * @param newResourceName the new resource name of the uploaded file
578      */

579     public void setParamNewResourceName(String JavaDoc newResourceName) {
580
581         m_paramNewResourceName = newResourceName;
582     }
583
584     /**
585      * Sets the paramRedirectUrl.<p>
586      *
587      * @param paramRedirectUrl the paramRedirectUrl to set
588      */

589     public void setParamRedirectUrl(String JavaDoc paramRedirectUrl) {
590
591         m_paramRedirectUrl = paramRedirectUrl;
592     }
593
594     /**
595      * Sets the paramTargetFrame.<p>
596      *
597      * @param paramTargetFrame the paramTargetFrame to set
598      */

599     public void setParamTargetFrame(String JavaDoc paramTargetFrame) {
600
601         m_paramTargetFrame = paramTargetFrame;
602     }
603
604     /**
605      * Sets if the upload file should be unzipped.<p>
606      *
607      * @param unzipFile true if the upload file should be unzipped
608      */

609     public void setParamUnzipFile(String JavaDoc unzipFile) {
610
611         m_paramUnzipFile = unzipFile;
612     }
613
614     /**
615      * Sets the upload error message for the error dialog.<p>
616      *
617      * @param uploadError the upload error message for the error dialog
618      */

619     public void setParamUploadError(String JavaDoc uploadError) {
620
621         m_paramUploadError = uploadError;
622     }
623
624     /**
625      * Sets the upload file name.<p>
626      *
627      * @param uploadFile the upload file name
628      */

629     public void setParamUploadFile(String JavaDoc uploadFile) {
630
631         m_paramUploadFile = uploadFile;
632     }
633
634     /**
635      * Sets the upload folder name.<p>
636      *
637      * @param uploadFolder the upload folder name
638      */

639     public void setParamUploadFolder(String JavaDoc uploadFolder) {
640
641         m_paramUploadFolder = uploadFolder;
642     }
643
644     /**
645      * Returns if the upload file should be unzipped.<p>
646      *
647      * @return true if the upload file should be unzipped, otherwise false
648      */

649     public boolean unzipUpload() {
650
651         return Boolean.valueOf(getParamUnzipFile()).booleanValue();
652     }
653
654     /**
655      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement)
656      */

657     protected void initWorkplaceMembers(CmsJspActionElement jsp) {
658
659         String JavaDoc siteRoot = jsp.getRequestContext().getSiteRoot();
660         // In case of the upload applet the site stored in the user preferences must NOT be made the current
661
// site even if we have a new session! Since the upload applet will create a new session for the upload itself,
662
// we must make sure to use the site of the request, NOT the site stored in the user preferences.
663
// The default logic will erase the request site in case of a new session.
664
// With this workaround the site from the request is made the current site as required.
665
super.initWorkplaceMembers(jsp);
666         if (!siteRoot.equals(getSettings().getSite())) {
667             getSettings().setSite(siteRoot);
668             jsp.getRequestContext().setSiteRoot(siteRoot);
669         }
670     }
671
672     /**
673      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
674      */

675     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
676
677         // fill the parameter values in the get/set methods
678
fillParamValues(request);
679         // set the dialog type
680
setParamDialogtype(DIALOG_TYPE);
681         // set the action for the JSP switch
682
if (DIALOG_OK.equals(getParamAction())) {
683             setAction(ACTION_OK);
684         } else if (DIALOG_SUBMITFORM.equals(getParamAction())) {
685             setAction(ACTION_SUBMITFORM);
686         } else if (DIALOG_SUBMITFORM2.equals(getParamAction())) {
687             setAction(ACTION_SUBMITFORM2);
688         } else if (DIALOG_CANCEL.equals(getParamAction())) {
689             setAction(ACTION_CANCEL);
690         } else {
691             if (getSettings().getUserSettings().useUploadApplet()) {
692                 setAction(ACTION_APPLET);
693             } else {
694                 setAction(ACTION_DEFAULT);
695             }
696             // build title for new resource dialog
697
setParamTitle(key(Messages.GUI_NEWRESOURCE_UPLOAD_0));
698         }
699     }
700
701 }
702
Popular Tags