KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > editors > fckeditor > CmsFCKEditorFileBrowser


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/editors/fckeditor/CmsFCKEditorFileBrowser.java,v $
3  * Date : $Date: 2006/10/25 09:55:59 $
4  * Version: $Revision: 1.4 $
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.editors.fckeditor;
33
34 import org.opencms.db.CmsDbSqlException;
35 import org.opencms.file.CmsFile;
36 import org.opencms.file.CmsProperty;
37 import org.opencms.file.CmsPropertyDefinition;
38 import org.opencms.file.CmsResource;
39 import org.opencms.file.CmsResourceFilter;
40 import org.opencms.file.CmsVfsResourceAlreadyExistsException;
41 import org.opencms.file.types.CmsResourceTypeFolder;
42 import org.opencms.file.types.CmsResourceTypeImage;
43 import org.opencms.flex.CmsFlexController;
44 import org.opencms.i18n.CmsEncoder;
45 import org.opencms.jsp.CmsJspActionElement;
46 import org.opencms.main.CmsException;
47 import org.opencms.main.CmsIllegalArgumentException;
48 import org.opencms.main.OpenCms;
49 import org.opencms.security.CmsPermissionViolationException;
50 import org.opencms.util.CmsRequestUtil;
51 import org.opencms.util.CmsStringUtil;
52 import org.opencms.workplace.CmsDialog;
53 import org.opencms.workplace.CmsWorkplaceSettings;
54 import org.opencms.xml.CmsXmlUtils;
55
56 import java.util.ArrayList JavaDoc;
57 import java.util.Iterator JavaDoc;
58 import java.util.List JavaDoc;
59
60 import javax.servlet.http.HttpServletRequest JavaDoc;
61 import javax.servlet.http.HttpServletResponse JavaDoc;
62 import javax.servlet.jsp.PageContext JavaDoc;
63
64 import org.apache.commons.fileupload.FileItem;
65
66 import org.dom4j.Document;
67 import org.dom4j.DocumentHelper;
68 import org.dom4j.Element;
69
70 /**
71  * Implements the OpenCms Connector for integration of the FCKeditor file browser.<p>
72  *
73  * Supports browsing the OpenCms virtual file system (VFS), creating folders and uploading files to the VFS.<br>
74  * Details about the connector implementation of the FCKeditor file browser can be
75  * found at http://wiki.fckeditor.net/Developer%27s_Guide/Participating/Server_Side_Integration.<p>
76  *
77  * @author Andreas Zahner
78  *
79  * @version $Revision: 1.4 $
80  *
81  * @since 6.1.7
82  */

83 public class CmsFCKEditorFileBrowser extends CmsDialog {
84
85     /** Value for the action: create folder. */
86     public static final int ACTION_CREATEFOLDER = 502;
87
88     /** Value for the action: upload file. */
89     public static final int ACTION_FILEUPLOAD = 503;
90
91     /** Value for the action: get folders. */
92     public static final int ACTION_GETFOLDERS = 500;
93
94     /** Value for the action: get folders and files. */
95     public static final int ACTION_GETFOLDERS_FILES = 501;
96
97     /** Attribute name for the command attribute. */
98     public static final String JavaDoc ATTR_COMMAND = "command";
99
100     /** Attribute name for the name attribute. */
101     public static final String JavaDoc ATTR_NAME = "name";
102
103     /** Attribute name for the number attribute. */
104     public static final String JavaDoc ATTR_NUMBER = "number";
105
106     /** Attribute name for the path attribute. */
107     public static final String JavaDoc ATTR_PATH = "path";
108
109     /** Attribute name for the resourceType attribute. */
110     public static final String JavaDoc ATTR_RESOURCETYPE = "resourceType";
111
112     /** Attribute name for the size attribute. */
113     public static final String JavaDoc ATTR_SIZE = "size";
114
115     /** Attribute name for the url attribute. */
116     public static final String JavaDoc ATTR_URL = "url";
117
118     /** Name for the create folder command. */
119     public static final String JavaDoc COMMAND_CREATEFOLDER = "CreateFolder";
120
121     /** Name for the file upload command. */
122     public static final String JavaDoc COMMAND_FILEUPLOAD = "FileUpload";
123
124     /** Name for the get folders command. */
125     public static final String JavaDoc COMMAND_GETFOLDERS = "GetFolders";
126
127     /** Name for the get folders and files command. */
128     public static final String JavaDoc COMMAND_GETFOLDERS_FILES = "GetFoldersAndFiles";
129
130     /** Content type setting HTML for the response. */
131     public static final String JavaDoc CONTENTTYPE_HTML = "text/html";
132
133     /** Content type setting XML for the response. */
134     public static final String JavaDoc CONTENTTYPE_XML = "text/xml";
135
136     /** The dialog type. */
137     public static final String JavaDoc DIALOG_TYPE = "FCKeditor_file_browser";
138
139     /** Error code for creating folders: folder already exists. */
140     public static final String JavaDoc ERROR_CREATEFOLDER_EXISTS = "101";
141
142     /** Error code for creating folders: invalid folder name. */
143     public static final String JavaDoc ERROR_CREATEFOLDER_INVALIDNAME = "102";
144
145     /** Error code for creating folders: no permissions. */
146     public static final String JavaDoc ERROR_CREATEFOLDER_NOPERMISSIONS = "103";
147
148     /** Error code for creating folders: all ok. */
149     public static final String JavaDoc ERROR_CREATEFOLDER_OK = "0";
150
151     /** Error code for creating folders: unknown error. */
152     public static final String JavaDoc ERROR_CREATEFOLDER_UNKNOWNERROR = "110";
153
154     /** Error code for uploading files: invalid file. */
155     public static final String JavaDoc ERROR_UPLOAD_INVALID = "202";
156
157     /** Error code for uploading files: all ok. */
158     public static final String JavaDoc ERROR_UPLOAD_OK = "0";
159
160     /** Node name for the Connector node. */
161     public static final String JavaDoc NODE_CONNECTOR = "Connector";
162
163     /** Node name for the CurrentFolder node. */
164     public static final String JavaDoc NODE_CURRENTFOLDER = "CurrentFolder";
165
166     /** Node name for the Error node. */
167     public static final String JavaDoc NODE_ERROR = "Error";
168
169     /** Node name for the File node. */
170     public static final String JavaDoc NODE_FILE = "File";
171
172     /** Node name for the Files node. */
173     public static final String JavaDoc NODE_FILES = "Files";
174
175     /** Node name for the Folder node. */
176     public static final String JavaDoc NODE_FOLDER = "Folder";
177
178     /** Node name for the Folders node. */
179     public static final String JavaDoc NODE_FOLDERS = "Folders";
180
181     /** Request parameter name for the command. */
182     public static final String JavaDoc PARAM_COMMAND = "Command";
183
184     /** Request parameter name for the current folder. */
185     public static final String JavaDoc PARAM_CURRENTFOLDER = "CurrentFolder";
186
187     /** Request parameter name for the new folder name. */
188     public static final String JavaDoc PARAM_NEWFOLDERNAME = "NewFolderName";
189
190     /** Request parameter name for the server path. */
191     public static final String JavaDoc PARAM_SERVERPATH = "ServerPath";
192
193     /** Request parameter name for the type. */
194     public static final String JavaDoc PARAM_TYPE = "Type";
195
196     /** Name for the browser resource type "File". */
197     public static final String JavaDoc TYPE_FILE = "File";
198
199     /** Name for the browser resource type "Flash". */
200     public static final String JavaDoc TYPE_FLASH = "Flash";
201
202     /** Name for the browser resource type "Image". */
203     public static final String JavaDoc TYPE_IMAGE = "Image";
204
205     /** Name for the browser resource type "Media". */
206     public static final String JavaDoc TYPE_MEDIA = "Media";
207
208     /** The XML document that is returned in the response. */
209     private Document m_document;
210
211     /** The list of multi part file items (if available). */
212     private List JavaDoc m_multiPartFileItems;
213
214     /** The Command parameter. */
215     private String JavaDoc m_paramCommand;
216
217     /** The CurrentFolder parameter. */
218     private String JavaDoc m_paramCurrentFolder;
219
220     /** The NewFolderName parameter. */
221     private String JavaDoc m_paramNewFolderName;
222
223     /** The ServerPath parameter. */
224     private String JavaDoc m_paramServerPath;
225
226     /** The Type parameter. */
227     private String JavaDoc m_paramType;
228
229     /**
230      * Public constructor with JSP action element.<p>
231      *
232      * @param jsp an initialized JSP action element
233      */

234     public CmsFCKEditorFileBrowser(CmsJspActionElement jsp) {
235
236         super(jsp);
237     }
238
239     /**
240      * Public constructor with JSP variables.<p>
241      *
242      * @param context the JSP page context
243      * @param req the JSP request
244      * @param res the JSP response
245      */

246     public CmsFCKEditorFileBrowser(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
247
248         this(new CmsJspActionElement(context, req, res));
249     }
250
251     /**
252      * Creates the output for the file browser depending on the executed command.<p>
253      *
254      * @return the output for the file browser depending on the executed command
255      */

256     public String JavaDoc displayDialog() {
257
258         switch (getAction()) {
259             case ACTION_CREATEFOLDER:
260                 return createFolder();
261             case ACTION_FILEUPLOAD:
262                 return uploadFile();
263             case ACTION_GETFOLDERS:
264                 return getFolders(false);
265             case ACTION_GETFOLDERS_FILES:
266             default:
267                 return getFolders(true);
268         }
269     }
270
271     /**
272      * Fills all class parameter values from the data provided in the current request.<p>
273      *
274      * For this class, the parameters are filled manually from the request, because the needed parameter
275      * names for the file browser are in mixed case and not lower case.<p>
276      *
277      * @param request the current JSP request
278      */

279     public void fillParamValues(HttpServletRequest JavaDoc request) {
280
281         // ensure a multipart request is parsed only once (for "forward" scenarios with reports)
282
if (null == request.getAttribute(REQUEST_ATTRIBUTE_MULTIPART)) {
283             // check if this is a multipart request
284
m_multiPartFileItems = CmsRequestUtil.readMultipartFileItems(request);
285             if (m_multiPartFileItems != null) {
286                 // this was indeed a multipart form request
287
CmsRequestUtil.readParameterMapFromMultiPart(
288                     getCms().getRequestContext().getEncoding(),
289                     m_multiPartFileItems);
290                 request.setAttribute(REQUEST_ATTRIBUTE_MULTIPART, Boolean.TRUE);
291             }
292         }
293
294         // manually fill the required request parameters in the members
295
setParamCommand(decodeParamValue(PARAM_COMMAND, request.getParameter(PARAM_COMMAND)));
296         setParamCurrentFolder(decodeParamValue(PARAM_CURRENTFOLDER, request.getParameter(PARAM_CURRENTFOLDER)));
297         setParamNewFolderName(decodeParamValue(PARAM_NEWFOLDERNAME, request.getParameter(PARAM_NEWFOLDERNAME)));
298         setParamServerPath(decodeParamValue(PARAM_SERVERPATH, request.getParameter(PARAM_SERVERPATH)));
299         setParamType(decodeParamValue(PARAM_TYPE, request.getParameter(PARAM_TYPE)));
300     }
301
302     /**
303      * Returns the Command parameter.<p>
304      *
305      * @return the Command parameter
306      */

307     public String JavaDoc getParamCommand() {
308
309         return m_paramCommand;
310     }
311
312     /**
313      * Returns the CurrentFolder parameter.<p>
314      *
315      * @return the CurrentFolder parameter
316      */

317     public String JavaDoc getParamCurrentFolder() {
318
319         return m_paramCurrentFolder;
320     }
321
322     /**
323      * Returns the NewFolderName parameter.<p>
324      *
325      * @return the NewFolderName parameter
326      */

327     public String JavaDoc getParamNewFolderName() {
328
329         return m_paramNewFolderName;
330     }
331
332     /**
333      * Returns the ServerPath parameter.<p>
334      *
335      * @return the ServerPath parameter
336      */

337     public String JavaDoc getParamServerPath() {
338
339         return m_paramServerPath;
340     }
341
342     /**
343      * Returns the Type parameter.<p>
344      *
345      * @return the Type parameter
346      */

347     public String JavaDoc getParamType() {
348
349         return m_paramType;
350     }
351
352     /**
353      * Sets the Command parameter.<p>
354      *
355      * @param paramCommand the Command parameter
356      */

357     public void setParamCommand(String JavaDoc paramCommand) {
358
359         m_paramCommand = paramCommand;
360     }
361
362     /**
363      * Sets the CurrentFolder parameter.<p>
364      *
365      * @param paramCurrentFolder the CurrentFolder parameter
366      */

367     public void setParamCurrentFolder(String JavaDoc paramCurrentFolder) {
368
369         if (CmsStringUtil.isEmpty(paramCurrentFolder)) {
370             m_paramCurrentFolder = "/";
371         } else {
372             m_paramCurrentFolder = paramCurrentFolder;
373         }
374     }
375
376     /**
377      * Sets the NewFolderName parameter.<p>
378      *
379      * @param paramNewFolderName the NewFolderName parameter
380      */

381     public void setParamNewFolderName(String JavaDoc paramNewFolderName) {
382
383         m_paramNewFolderName = paramNewFolderName;
384     }
385
386     /**
387      * Sets the ServerPath parameter.<p>
388      *
389      * @param paramServerPath the ServerPath parameter
390      */

391     public void setParamServerPath(String JavaDoc paramServerPath) {
392
393         if (CmsStringUtil.isEmpty(paramServerPath)) {
394             m_paramServerPath = OpenCms.getSystemInfo().getOpenCmsContext() + getParamCurrentFolder();
395         } else {
396             m_paramServerPath = OpenCms.getSystemInfo().getOpenCmsContext() + paramServerPath;
397         }
398     }
399
400     /**
401      * Sets the Type parameter.<p>
402      *
403      * @param paramType the Type parameter
404      */

405     public void setParamType(String JavaDoc paramType) {
406
407         if (CmsStringUtil.isEmpty(paramType)) {
408             m_paramType = "";
409         } else {
410             m_paramType = paramType;
411         }
412     }
413
414     /**
415      * Creates a folder in the file browser and returns the XML containing the error code.<p>
416      *
417      * @return the XML containing the error code for the folder creation
418      */

419     protected String JavaDoc createFolder() {
420
421         createXMLHead();
422         Element error = getDocument().getRootElement().addElement(NODE_ERROR);
423         try {
424             getCms().createResource(
425                 getParamCurrentFolder() + getParamNewFolderName(),
426                 CmsResourceTypeFolder.RESOURCE_TYPE_ID);
427             // no error occured, return error code 0
428
error.addAttribute(ATTR_NUMBER, ERROR_CREATEFOLDER_OK);
429         } catch (Exception JavaDoc e) {
430             // check cause of error to return a specific error code
431
if (e instanceof CmsVfsResourceAlreadyExistsException) {
432                 // resource already exists
433
error.addAttribute(ATTR_NUMBER, ERROR_CREATEFOLDER_EXISTS);
434             } else if (e instanceof CmsIllegalArgumentException) {
435                 // invalid folder name
436
error.addAttribute(ATTR_NUMBER, ERROR_CREATEFOLDER_INVALIDNAME);
437             } else if (e instanceof CmsPermissionViolationException) {
438                 // no permissions to create the folder
439
error.addAttribute(ATTR_NUMBER, ERROR_CREATEFOLDER_NOPERMISSIONS);
440             } else {
441                 // unknown error
442
error.addAttribute(ATTR_NUMBER, ERROR_CREATEFOLDER_UNKNOWNERROR);
443             }
444
445         }
446
447         try {
448             return CmsXmlUtils.marshal(getDocument(), CmsEncoder.ENCODING_UTF_8);
449         } catch (CmsException e) {
450             // should never happen
451
return "";
452         }
453     }
454
455     /**
456      * Creates the XML head that is used for every XML file browser response except the upload response.<p>
457      */

458     protected void createXMLHead() {
459
460         // add the connector node
461
Element connector = getDocument().addElement(NODE_CONNECTOR);
462         connector.addAttribute(ATTR_COMMAND, getParamCommand());
463         connector.addAttribute(ATTR_RESOURCETYPE, getParamType());
464         Element currFolder = connector.addElement(NODE_CURRENTFOLDER);
465         currFolder.addAttribute(ATTR_PATH, getParamCurrentFolder());
466         currFolder.addAttribute(ATTR_URL, getParamServerPath());
467
468     }
469
470     /**
471      * Returns the XML document instance that is used to build the response XML.<p>
472      *
473      * @return the XML document instance that is used to build the response XML
474      */

475     protected Document getDocument() {
476
477         if (m_document == null) {
478             m_document = DocumentHelper.createDocument();
479         }
480         return m_document;
481     }
482
483     /**
484      * Returns the XML to list folders and/or files in the file browser window.<p>
485      *
486      * @param includeFiles flag to indicate if files are included
487      * @return the XML to list folders and/or files in the file browser window
488      */

489     protected String JavaDoc getFolders(boolean includeFiles) {
490
491         createXMLHead();
492         Element folders = getDocument().getRootElement().addElement(NODE_FOLDERS);
493         Element files = null;
494
495         // generate resource filter
496
CmsResourceFilter filter;
497         if (includeFiles) {
498             // create filter to get folders and files
499
filter = CmsResourceFilter.DEFAULT.addRequireVisible();
500             files = getDocument().getRootElement().addElement(NODE_FILES);
501         } else {
502             // create filter to get only folders
503
filter = CmsResourceFilter.DEFAULT_FOLDERS.addRequireVisible();
504         }
505
506         try {
507             List JavaDoc resources = getCms().readResources(getParamCurrentFolder(), filter, false);
508             Iterator JavaDoc i = resources.iterator();
509             while (i.hasNext()) {
510                 CmsResource res = (CmsResource)i.next();
511                 if (res.isFolder()) {
512                     // resource is a folder, create folder node
513
Element folder = folders.addElement(NODE_FOLDER);
514                     String JavaDoc folderName = CmsResource.getName(res.getRootPath());
515                     folderName = CmsStringUtil.substitute(folderName, "/", "");
516                     folder.addAttribute(ATTR_NAME, folderName);
517                 } else {
518                     // resource is a file
519
boolean showFile = true;
520                     // check if required file type is an image and filter found resources if set
521
if (TYPE_IMAGE.equals(getParamType())) {
522                         showFile = (res.getTypeId() == CmsResourceTypeImage.getStaticTypeId());
523                     }
524                     if ((showFile) && (files != null)) {
525                         // create file node
526
Element file = files.addElement(NODE_FILE);
527                         file.addAttribute(ATTR_NAME, CmsResource.getName(res.getRootPath()));
528                         file.addAttribute(ATTR_SIZE, "" + (res.getLength() / 1024));
529                     }
530                 }
531
532             }
533             return CmsXmlUtils.marshal(getDocument(), CmsEncoder.ENCODING_UTF_8);
534         } catch (CmsException e) {
535             // error getting resource list, return empty String
536
return "";
537         }
538     }
539
540     /**
541      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
542      */

543     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
544
545         // fill the parameter values in the get/set methods and check for multipart file items
546
fillParamValues(request);
547
548         // set the dialog type
549
setParamDialogtype(DIALOG_TYPE);
550         // set the action for the JSP switch
551
if (COMMAND_FILEUPLOAD.equals(getParamCommand())) {
552             // upload file
553
setAction(ACTION_FILEUPLOAD);
554         } else if (COMMAND_CREATEFOLDER.equals(getParamCommand())) {
555             // create folder
556
setAction(ACTION_CREATEFOLDER);
557         } else if (COMMAND_GETFOLDERS.equals(getParamCommand())) {
558             // get folders
559
setAction(ACTION_GETFOLDERS);
560         } else {
561             // default: get files and folders
562
setAction(ACTION_GETFOLDERS_FILES);
563         }
564
565         // get the top response
566
CmsFlexController controller = CmsFlexController.getController(getJsp().getRequest());
567         HttpServletResponse JavaDoc res = controller.getTopResponse();
568         // set the response headers depending on the command to execute
569
CmsRequestUtil.setNoCacheHeaders(res);
570         String JavaDoc contentType = CONTENTTYPE_XML;
571         if (getAction() == ACTION_FILEUPLOAD) {
572             contentType = CONTENTTYPE_HTML;
573         }
574         res.setContentType(contentType);
575     }
576
577     /**
578      * Uploads a file to the OpenCms VFS and returns the necessary JavaScript for the file browser.<p>
579      *
580      * @return the necessary JavaScript for the file browser
581      */

582     protected String JavaDoc uploadFile() {
583
584         String JavaDoc errorCode = ERROR_UPLOAD_OK;
585         try {
586             // get the file item from the multipart request
587
Iterator JavaDoc i = m_multiPartFileItems.iterator();
588             FileItem fi = null;
589             while (i.hasNext()) {
590                 fi = (FileItem)i.next();
591                 if (fi.getName() != null) {
592                     // found the file object, leave iteration
593
break;
594                 } else {
595                     // this is no file object, check next item
596
continue;
597                 }
598             }
599
600             if (fi != null) {
601                 String JavaDoc fileName = fi.getName();
602                 long size = fi.getSize();
603                 long maxFileSizeBytes = OpenCms.getWorkplaceManager().getFileBytesMaxUploadSize(getCms());
604                 // check file size
605
if (maxFileSizeBytes > 0 && size > maxFileSizeBytes) {
606                     // file size is larger than maximum allowed file size, throw an error
607
throw new Exception JavaDoc();
608                 }
609                 byte[] content = fi.get();
610                 fi.delete();
611
612                 // single file upload
613
String JavaDoc newResname = CmsResource.getName(fileName.replace('\\', '/'));
614                 // determine Title property value to set on new resource
615
String JavaDoc title = newResname;
616                 if (title.lastIndexOf('.') != -1) {
617                     title = title.substring(0, title.lastIndexOf('.'));
618                 }
619                 List JavaDoc properties = new ArrayList JavaDoc(1);
620                 CmsProperty titleProp = new CmsProperty();
621                 titleProp.setName(CmsPropertyDefinition.PROPERTY_TITLE);
622                 if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
623                     titleProp.setStructureValue(title);
624                 } else {
625                     titleProp.setResourceValue(title);
626                 }
627                 properties.add(titleProp);
628
629                 // determine the resource type id from the given information
630
int resTypeId = OpenCms.getResourceManager().getDefaultTypeForName(newResname).getTypeId();
631
632                 // calculate absolute path of uploaded resource
633
newResname = getParamCurrentFolder() + newResname;
634
635                 if (!getCms().existsResource(newResname, CmsResourceFilter.IGNORE_EXPIRATION)) {
636                     try {
637                         // create the resource
638
getCms().createResource(newResname, resTypeId, content, properties);
639                     } catch (CmsDbSqlException sqlExc) {
640                         // SQL error, probably the file is too large for the database settings, delete file
641
getCms().lockResource(newResname);
642                         getCms().deleteResource(newResname, CmsResource.DELETE_PRESERVE_SIBLINGS);
643                         throw sqlExc;
644                     }
645                 } else {
646                     // resource exists, overwrite existing resource
647
checkLock(newResname);
648                     CmsFile file = getCms().readFile(newResname, CmsResourceFilter.IGNORE_EXPIRATION);
649                     byte[] contents = file.getContents();
650                     try {
651                         getCms().replaceResource(newResname, resTypeId, content, null);
652                     } catch (CmsDbSqlException sqlExc) {
653                         // SQL error, probably the file is too large for the database settings, restore content
654
file.setContents(contents);
655                         getCms().writeFile(file);
656                         throw sqlExc;
657                     }
658                 }
659             } else {
660                 // no upload file found
661
throw new Exception JavaDoc();
662             }
663         } catch (Throwable JavaDoc e) {
664             // something went wrong, change error code
665
errorCode = ERROR_UPLOAD_INVALID;
666         }
667
668         // create JavaScript to return to file browser
669
StringBuffer JavaDoc result = new StringBuffer JavaDoc(256);
670         result.append("<html><head><script type=\"text/javascript\">\n");
671         result.append("window.parent.frames[\"frmUpload\"].OnUploadCompleted(");
672         result.append(errorCode);
673         result.append(");\n");
674         result.append("</script></head></html>");
675         return result.toString();
676     }
677
678 }
Popular Tags