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: UploadHTMLAction.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.10 2004/12/31 18:27:44 colinmacleod
045: * Added MaskFactory to constructor of MaskAction.
046: *
047: * Revision 1.9 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.8 2004/11/12 18:19:15 colinmacleod
052: * Change action and form classes to extend MaskAction, MaskForm respectively.
053: *
054: * Revision 1.7 2004/11/03 15:31:51 colinmacleod
055: * Change method interfaces to remove log.
056: *
057: * Revision 1.6 2004/08/01 11:45:19 colinmacleod
058: * Restructured search engine into separate subproject.
059: *
060: * Revision 1.5 2004/07/13 19:47:29 colinmacleod
061: * Moved project to POJOs from EJBs.
062: * Applied PicoContainer to services layer (replacing session EJBs).
063: * Applied Hibernate to persistence layer (replacing entity EJBs).
064: *
065: * Revision 1.4 2004/03/21 21:16:29 colinmacleod
066: * Shortened name to ivata op.
067: *
068: * Revision 1.3 2004/02/10 19:57:24 colinmacleod
069: * Changed email address.
070: *
071: * Revision 1.2 2004/02/01 22:07:31 colinmacleod
072: * Added full names to author tags
073: *
074: * Revision 1.1.1.1 2004/01/27 20:58:42 colinmacleod
075: * Moved ivata openportal to SourceForge..
076: *
077: * Revision 1.3 2003/10/28 13:16:14 jano
078: * commiting library,
079: * still fixing compile and building openGroupware project
080: *
081: * Revision 1.2 2003/10/15 14:16:53 colin
082: * fixing for XDoclet
083: *
084: * Revision 1.2 2003/07/08 07:55:56 peter
085: * fixed logic for already uploaded images
086: * Revision 1.1 2003/07/08 06:31:33 peter
087: * added to cvs
088: * -----------------------------------------------------------------------------
089: */
090: package com.ivata.groupware.business.library.struts;
091:
092: import java.io.BufferedReader;
093: import java.io.FileNotFoundException;
094: import java.io.IOException;
095: import java.io.InputStream;
096: import java.io.InputStreamReader;
097: import java.util.Iterator;
098: import java.util.List;
099: import java.util.Map;
100: import java.util.Set;
101: import java.util.Vector;
102:
103: import javax.servlet.http.HttpServletRequest;
104: import javax.servlet.http.HttpServletResponse;
105: import javax.servlet.http.HttpSession;
106:
107: import org.apache.struts.action.ActionErrors;
108: import org.apache.struts.action.ActionForm;
109: import org.apache.struts.action.ActionMapping;
110:
111: import com.ivata.groupware.web.format.SanitizerFormat;
112: import com.ivata.mask.MaskFactory;
113: import com.ivata.mask.util.SystemException;
114: import com.ivata.mask.web.struts.MaskAction;
115: import com.ivata.mask.web.struts.MaskAuthenticator;
116:
117: /**
118: * <p>Invoked when the user uploads a HTML file to a library
119: * document.</p>
120: *
121: * @since 2003-07-02
122: * @author Peter Illes
123: * @version $Revision: 1.3 $
124: *
125: */
126: public class UploadHTMLAction extends MaskAction {
127: /**
128: * <p>
129: * Constructor. Called by <strong>PicoContainer.</strong>.
130: * </p>
131: *
132: * @param maskFactory This factory is needed to access the masks and groups
133: * of masks.
134: * @param authenticator used to confirm whether or not the
135: * user should be allowed to continue, in the <code>execute</code> method.
136: */
137: public UploadHTMLAction(MaskFactory maskFactory,
138: MaskAuthenticator authenticator) {
139: super (maskFactory, authenticator);
140: }
141:
142: /**
143: * <p>Called from the other <code>execute</code> method, this can
144: * be overridden by each subclass to provide the <em>ivata</em>-specific
145: * processing required.</p>
146: *
147: * @param mapping The ActionMapping used to select this instance.
148: * @param log valid logging object to write messages to.
149: * @param errors valid errors object to append errors to. If there are
150: * any errors, the action will return to the input.
151: * @param form optional ActionForm bean for this request (if any)
152: * @param request non-HTTP request we are processing
153: * @param response The non-HTTP response we are creating
154: * @param session returned from the <code>request</code> parameter.
155: * @param userName valid, non-null user name from session.
156: * @param settings valid, non-null settings from session.
157: * @exception SystemException if there is any problem which
158: * prevents processing. It will result in the webapp being forwarded
159: * to
160: * the standard error page.
161: * @return this method returns the string used to identify the correct
162: * <em>Struts</em> <code>ActionForward</code> which should follow this
163: * page, or <code>null</code> if it should return to the input.
164: */
165: public String execute(ActionMapping mapping, ActionErrors errors,
166: ActionForm form, HttpServletRequest request,
167: HttpServletResponse response, HttpSession session)
168: throws SystemException {
169: return null;
170: }
171:
172: /**
173: * <p>This method is called if the ok or apply buttons are
174: * pressed.</p>
175: *
176: * @param mapping The ActionMapping used to select this instance.
177: * @param log valid logging object to write messages to.
178: * @param errors valid errors object to append errors to. If there are
179: * any errors, the action will return to the input.
180: * @param form optional ActionForm bean for this request (if any)
181: * @param request non-HTTP request we are processing
182: * @param response The non-HTTP response we are creating
183: * @param session returned from the <code>request</code> parameter.
184: * @param userName valid, non-null user name from session.
185: * @param settings valid, non-null settings from session.
186: * @param ok <code>true</code> if the ok button was pressed, otherwise
187: * <code>false</code> if the apply button was pressed.
188: * @exception SystemException if there is any problem which
189: * prevents processing. It will result in the webapp being forwarded
190: * to
191: * the standard error page.
192: * @return this method returns the string used to identify the correct
193: * <em>Struts</em> <code>ActionForward</code> which should follow this
194: * page, or <code>null</code> if it should return to the input.
195: */
196: public String onConfirm(ActionMapping mapping, ActionErrors errors,
197: ActionForm form, HttpServletRequest request,
198: HttpServletResponse response, HttpSession session,
199: final String defaultForward) throws SystemException {
200: UploadHTMLForm uploadForm = (UploadHTMLForm) form;
201: String returnForward = "utilClosePopUp";
202:
203: try {
204: InputStream stream = uploadForm.getFile().getInputStream();
205: BufferedReader in = new BufferedReader(
206: new InputStreamReader(stream));
207: StringBuffer messageBuffer = new StringBuffer();
208: char[] chbuf = new char[1024];
209: int count;
210:
211: while ((count = in.read(chbuf)) != -1) {
212: messageBuffer.append(chbuf, 0, count);
213: }
214:
215: SanitizerFormat sanitizer = new SanitizerFormat();
216: sanitizer.setOnlyBodyContents(true);
217: sanitizer.setSourceName("user input");
218: // TODO Map parseResult = sanitizer.format(messageBuffer.toString());
219: Map parseResult = null;
220:
221: List pages = (List) parseResult.get("pages");
222:
223: if (!pages.isEmpty()) {
224: ItemForm itemForm = (ItemForm) session
225: .getAttribute("libraryItemForm");
226: //TODO itemForm.getItem().setPages(new Vector(pages));
227: session.setAttribute("libraryItemForm", itemForm);
228:
229: Set images = (Set) parseResult.get("images");
230: Vector itemAttachments = null;
231:
232: // the attachmnets are either in upload (new item) or in drive
233: /*TODO if (itemForm.getItem().getId() == null) {
234: itemAttachments = itemForm.getUploadingFileList();
235: } else {
236: itemAttachments = itemForm.getFileList();
237: }
238: */
239: Vector newImages = new Vector();
240:
241: // look for images not attached yet
242: for (Iterator i = images.iterator(); i.hasNext();) {
243: String currentImage = (String) i.next();
244: boolean newImage = true;
245:
246: /*TODO for (Iterator j = itemAttachments.iterator(); j.hasNext();) {
247: if (currentImage.endsWith(
248: ((FileDO) j.next()).getFileName())) {
249: newImage = false;
250:
251: break;
252: }
253: }
254: */
255: if (newImage) {
256: newImages.add(currentImage);
257: }
258: }
259:
260: // when there are ne images, go to image upload
261: if (!newImages.isEmpty()) {
262: UploadImagesForm uploadImagesForm = new UploadImagesForm();
263: uploadImagesForm.setImageFileName(newImages);
264: request.setAttribute("libraryUploadImagesForm",
265: uploadImagesForm);
266: returnForward = "libraryImageUpload";
267: } else {
268: request.setAttribute("openerPage",
269: "/library/submit.action");
270: }
271: }
272: } catch (FileNotFoundException efnf) {
273: throw new SystemException(efnf);
274: } catch (IOException eio) {
275: throw new SystemException(eio);
276: }
277:
278: return returnForward;
279: }
280: }
|