KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > controller > handlers > FileUploadHandler


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: FileUploadHandler.java,v 1.3 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.controller.handlers;
21
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Enumeration JavaDoc;
26 import javax.servlet.ServletException JavaDoc;
27 import javax.servlet.http.HttpServletRequest JavaDoc;
28 import org.enhydra.barracuda.core.event.ControlEventContext;
29 import org.enhydra.barracuda.core.event.EventException;
30 import org.enhydra.barracuda.core.helper.servlet.DefaultServletRequestWrapper;
31 import org.enhydra.barracuda.contrib.dbroggisch.page.Page;
32 import org.enhydra.barracuda.contrib.dbroggisch.page.PageEventListener;
33
34 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.DBRApplicationGateway;
35 import org.enhydra.barracuda.contrib.dbroggisch.examples.controller.servlets.MyMultipartRequest;
36 import org.enhydra.barracuda.contrib.dbroggisch.examples.view.pages.*;
37
38
39 public class FileUploadHandler extends PageEventListener {
40
41     public void handleControlEvent(ControlEventContext context, Page p)
42             throws EventException, ServletException JavaDoc, IOException JavaDoc {
43         HttpServletRequest JavaDoc request = context.getRequest();
44         List JavaDoc realNames = new ArrayList JavaDoc();
45         FileUploadPage fuPage = (FileUploadPage)p;
46         fuPage.setState(ExampleBasePage.FILEUPLOAD);
47
48         if (DBRApplicationGateway.WRAPPER_INSTALLED &&
49             ((DefaultServletRequestWrapper)request).getCoreRequest() instanceof MyMultipartRequest) {
50             MyMultipartRequest mReq = (MyMultipartRequest)((DefaultServletRequestWrapper)request).getCoreRequest();
51             Enumeration JavaDoc fnames = mReq.getFileNames();
52
53             while(fnames.hasMoreElements()) {
54                 realNames.add(mReq.getFilesystemName((String JavaDoc)fnames.nextElement()));
55             }
56         }
57         fuPage.setNames(realNames);
58         context.getEvent().setHandled(true);
59     }
60
61 }
62
Popular Tags