Source Code Cross Referenced for UploadImagesAction.java in  » Groupware » ivatagroupware » com » ivata » groupware » business » library » struts » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » ivatagroupware » com.ivata.groupware.business.library.struts 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata groupware may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: UploadImagesAction.java,v $
031:         * Revision 1.3  2005/04/10 20:31:58  colinmacleod
032:         * Added new themes.
033:         * Changed id type to String.
034:         * Changed i tag to em and b tag to strong.
035:         * Improved PicoContainerFactory with NanoContainer scripts.
036:         *
037:         * Revision 1.2  2005/04/09 17:19:46  colinmacleod
038:         * Changed copyright text to GPL v2 explicitly.
039:         *
040:         * Revision 1.1.1.1  2005/03/10 17:52:01  colinmacleod
041:         * Restructured ivata op around Hibernate/PicoContainer.
042:         * Renamed ivata groupware.
043:         *
044:         * Revision 1.9  2004/12/31 18:27:44  colinmacleod
045:         * Added MaskFactory to constructor of MaskAction.
046:         *
047:         * Revision 1.8  2004/12/23 21:01:29  colinmacleod
048:         * Updated Struts to v1.2.4.
049:         * Changed base classes to use ivata masks.
050:         *
051:         * Revision 1.7  2004/11/12 18:19:15  colinmacleod
052:         * Change action and form classes to extend MaskAction, MaskForm respectively.
053:         *
054:         * Revision 1.6  2004/11/03 15:31:51  colinmacleod
055:         * Change method interfaces to remove log.
056:         *
057:         * Revision 1.5  2004/07/13 19:47:29  colinmacleod
058:         * Moved project to POJOs from EJBs.
059:         * Applied PicoContainer to services layer (replacing session EJBs).
060:         * Applied Hibernate to persistence layer (replacing entity EJBs).
061:         *
062:         * Revision 1.4  2004/03/21 21:16:29  colinmacleod
063:         * Shortened name to ivata op.
064:         *
065:         * Revision 1.3  2004/02/10 19:57:24  colinmacleod
066:         * Changed email address.
067:         *
068:         * Revision 1.2  2004/02/01 22:07:31  colinmacleod
069:         * Added full names to author tags
070:         *
071:         * Revision 1.1.1.1  2004/01/27 20:58:42  colinmacleod
072:         * Moved ivata openportal to SourceForge..
073:         *
074:         * Revision 1.4  2003/11/13 16:11:08  jano
075:         * commitng everything to CVS
076:         * can deploy and application is ruuning, can login into
077:         *
078:         * Revision 1.3  2003/10/28 13:16:14  jano
079:         * commiting library,
080:         * still fixing compile and building openGroupware project
081:         *
082:         * Revision 1.2  2003/10/15 14:16:53  colin
083:         * fixing for XDoclet
084:         *
085:         * Revision 1.2  2003/07/16 14:47:04  jano
086:         * quotaHandling for uploading images during Uploading HTML
087:         * Revision 1.1  2003/07/08 06:31:33  peter
088:         * added to cvs
089:         * -----------------------------------------------------------------------------
090:         */
091:        package com.ivata.groupware.business.library.struts;
092:
093:        import javax.servlet.http.HttpServletRequest;
094:        import javax.servlet.http.HttpServletResponse;
095:        import javax.servlet.http.HttpSession;
096:
097:        import org.apache.struts.action.ActionErrors;
098:        import org.apache.struts.action.ActionForm;
099:        import org.apache.struts.action.ActionMapping;
100:
101:        import com.ivata.mask.MaskFactory;
102:        import com.ivata.mask.util.SystemException;
103:        import com.ivata.mask.web.struts.MaskAction;
104:        import com.ivata.mask.web.struts.MaskAuthenticator;
105:
106:        /**
107:         * <p>Library image upload action. It's used when there are some local
108:         * images
109:         * in the uploaded HTML for library document.</p>
110:         *
111:         * @since 2003-07-04
112:         * @author Peter Illes
113:         * @version $Revision: 1.3 $
114:         */
115:        public class UploadImagesAction extends MaskAction {
116:            /**
117:             * <p>
118:             * Constructor. Called by <strong>PicoContainer.</strong>.
119:             * </p>
120:             *
121:             * @param maskFactory This factory is needed to access the masks and groups
122:             * of masks.
123:             * @param authenticator used to confirm whether or not the
124:             * user should be allowed to continue, in the <code>execute</code> method.
125:             */
126:            public UploadImagesAction(MaskFactory maskFactory,
127:                    MaskAuthenticator authenticator) {
128:                super (maskFactory, authenticator);
129:            }
130:
131:            /**
132:             * <p>Called from the other <code>execute</code> method, this can
133:             * be overridden by each subclass to provide the <em>ivata</em>-specific
134:             * processing required.</p>
135:             *
136:             * @param mapping The ActionMapping used to select this instance.
137:             * @param log valid logging object to write messages to.
138:             * @param errors valid errors object to append errors to. If there are
139:             * any errors, the action will return to the input.
140:             * @param form optional ActionForm bean for this request (if any)
141:             * @param request non-HTTP request we are processing
142:             * @param response The non-HTTP response we are creating
143:             * @param session  returned from the <code>request</code> parameter.
144:             * @param userName valid, non-null user name from session.
145:             * @param settings valid, non-null settings from session.
146:             * @exception SystemException if there is any problem which
147:             * prevents processing. It will result in the webapp being forwarded
148:             * to
149:             * the standard error page.
150:             * @return this method returns the string used to identify the correct
151:             * <em>Struts</em> <code>ActionForward</code> which should follow this
152:             * page, or <code>null</code> if it should return to the input.
153:             */
154:            public String execute(final ActionMapping mapping,
155:                    final ActionErrors errors, final ActionForm form,
156:                    final HttpServletRequest request,
157:                    final HttpServletResponse response,
158:                    final HttpSession session) throws SystemException {
159:                return null;
160:            }
161:
162:            /**
163:             * <p>This method is called if the ok or apply buttons are
164:             * pressed.</p>
165:             *
166:             * @param mapping The ActionMapping used to select this instance.
167:             * @param log valid logging object to write messages to.
168:             * @param errors valid errors object to append errors to. If there are
169:             * any errors, the action will return to the input.
170:             * @param form optional ActionForm bean for this request (if any)
171:             * @param request non-HTTP request we are processing
172:             * @param response The non-HTTP response we are creating
173:             * @param session  returned from the <code>request</code> parameter.
174:             * @param userName valid, non-null user name from session.
175:             * @param settings valid, non-null settings from session.
176:             * @param ok <code>true</code> if the ok button was pressed, otherwise
177:             * <code>false</code> if the apply button was pressed.
178:             * @exception SystemException if there is any problem which
179:             * prevents processing. It will result in the webapp being forwarded
180:             * to
181:             * the standard error page.
182:             * @return this method returns the string used to identify the correct
183:             * <em>Struts</em> <code>ActionForward</code> which should follow this
184:             * page, or <code>null</code> if it should return to the input.
185:             */
186:            public String onConfirm(final ActionMapping mapping,
187:                    final ActionErrors errors, final ActionForm form,
188:                    final HttpServletRequest request,
189:                    final HttpServletResponse response,
190:                    final HttpSession session, final String defaultForward)
191:                    throws SystemException {
192:                UploadImagesForm uploadForm = (UploadImagesForm) form;
193:
194:                /* TODO        DriveRemote drive = getDriveFromSession(session);
195:                 UsageRemote usage = getUsageFromSession(session);
196:
197:                 Map images = uploadForm.getImages();
198:
199:                 // only worth to do something when there's at least one file uploaded
200:                 if (!images.isEmpty()) {
201:                 Vector fileNameList = new Vector();
202:
203:                 try {
204:                 int finalSize = 0;
205:
206:                 // count fileSize together and check if we can upload
207:                 for (Iterator i = images.keySet().iterator(); i.hasNext();) {
208:                 String currentKey = (String) i.next();
209:
210:                 FormFile formFile = (FormFile) images.get(currentKey);
211:
212:                 // ignore empty files and files already uploaded
213:                 if ((formFile != null) && (formFile.getFileSize() > 0) &&
214:                 !fileNameList.contains(formFile.getFileName())) {
215:                 finalSize += formFile.getFileSize();
216:                 }
217:                 }
218:
219:                 Integer canUpload = null;
220:
221:                 try {
222:                 canUpload = usage.canUpload(new Integer(finalSize / 1024),
223:                 (String) session.getAttribute("userName"));
224:                 } catch (java.rmi.RemoteException e) {
225:                 throw new RuntimeException(e);
226:                 }
227:
228:                 ResourceBundle adminBundle = ResourceBundle.getBundle("com.ivata.groupware.business.ApplicationResources",
229:                 (Locale) request.getSession().getAttribute(Globals.LOCALE_KEY));
230:
231:                 if (canUpload.equals(
232:                 com.ivata.groupware.admin.usage.UsageConstants.CAN_UPLOAD_NEARLY_RUN_OUT_OF_QUOTA) ||
233:                 canUpload.equals(
234:                 com.ivata.groupware.admin.usage.UsageConstants.OK)) {
235:                 for (Iterator i = images.keySet().iterator(); i.hasNext();) {
236:                 String currentKey = (String) i.next();
237:
238:                 FormFile formFile = (FormFile) images.get(currentKey);
239:
240:                 // ignore empty files and files already uploaded
241:                 if ((formFile != null) && (formFile.getFileSize() > 0) &&
242:                 !fileNameList.contains(formFile.getFileName())) {
243:                 InputStream inStream = formFile.getInputStream();
244:
245:                 // reading the content, writing it to an output stream
246:                 ByteArrayOutputStream outStream = new ByteArrayOutputStream();
247:                 int oneByte = 0;
248:
249:                 while ((oneByte = inStream.read()) != -1) {
250:                 outStream.write(oneByte);
251:                 }
252:
253:                 // storing the content to the fileContentDO
254:                 SerializedByteArray fileContent = new SerializedByteArray(outStream.toByteArray());
255:                 FileContentDO fileContentDO = new FileContentDO(fileContent,
256:                 formFile.getContentType());
257:
258:                 // store the file server-side, get the updated list
259:                 drive.uploadFile(fileContentDO,
260:                 formFile.getFileName(),
261:                 uploadForm.getComment(currentKey), userName);
262:
263:                 fileNameList.add(formFile.getFileName());
264:                 }
265:
266:                 if (canUpload.equals(
267:                 com.ivata.groupware.admin.usage.UsageConstants.CAN_UPLOAD_NEARLY_RUN_OUT_OF_QUOTA)) {
268:                 request.setAttribute("javaScript",
269:                 "alert(\"" +
270:                 adminBundle.getString(
271:                 "errors.upload.quota.runOut.nearly") +
272:                 "\");");
273:                 }
274:                 }
275:                 } else if (canUpload.equals(
276:                 com.ivata.groupware.admin.usage.UsageConstants.NOT_FREE_SPACE_FOR_UPLOAD)) {
277:                 request.setAttribute("javaScript",
278:                 "alert(\"" +
279:                 adminBundle.getString("errors.upload.quota.runOut") +
280:                 "\");");
281:                 }
282:
283:                 // if there were some uploads, move them to drive upload directory
284:                 if (!fileNameList.isEmpty()) {
285:                 drive.moveUploads(fileNameList, "drive", userName);
286:                 }
287:                 } catch (java.rmi.RemoteException e) {
288:                 throw new SystemException(e);
289:                 } catch (FileNotFoundException e) {
290:                 throw new SystemException(e);
291:                 } catch (IOException e) {
292:                 throw new SystemException(e);
293:                 }
294:                 }
295:
296:                 request.setAttribute("openerPage", "/library/submit.action");
297:                 */
298:                return "utilClosePopUp";
299:            }
300:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.