KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > modules > screens > InboxAttachmentData


1 package org.campware.cream.modules.screens;
2
3 /* ====================================================================
4  * Copyright (C) 2003-2005 Media Development Loan Fund
5  *
6  * * contact: contact@campware.org - http://www.campware.org
7  * Campware encourages further development. Please let us know.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
27  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  * ====================================================================
36  *
37  * This software consists of voluntary contributions made by many
38  * individuals on behalf of the Apache Software Foundation. For more
39  * information on the Apache Software Foundation, please see
40  * <http://www.apache.org/>.
41  */

42
43
44 import java.io.*;
45
46 import javax.mail.internet.*;
47 import javax.mail.BodyPart JavaDoc;
48
49 import javax.servlet.ServletOutputStream JavaDoc;
50 import org.apache.torque.util.Criteria;
51
52 import org.campware.cream.modules.scheduledjobs.Pop3Job;
53 import org.campware.cream.modules.util.Base64;
54 import org.campware.cream.om.InboxAttachment;
55 import org.campware.cream.om.InboxAttachmentPeer;
56
57 //Turbine stuff.
58
import org.apache.turbine.modules.Screen;
59 import org.apache.turbine.util.RunData;
60
61 // ECS Classes
62
import org.apache.commons.logging.Log;
63 import org.apache.commons.logging.LogFactory;
64 import org.apache.ecs.ConcreteElement;
65 /**
66  * To read comments for this class, please see
67  * the ancestor class
68  */

69 public class InboxAttachmentData extends Screen
70 {
71
72     /** Logging */
73     private static Log log = LogFactory.getLog(InboxAttachmentData.class);
74
75     
76     /**
77          * Build the Screen. This method actually makes a call to the
78          * doOutput() method in order to generate the Screen content.
79          *
80          * @param data Turbine information.
81          * @return A ConcreteElement.
82          * @exception Exception, a generic exception.
83          */

84         protected final ConcreteElement doBuild(RunData data)
85             throws Exception JavaDoc
86         {
87
88             int entry_id = data.getParameters().getInt("inboxattachmentid");
89             
90             if (entry_id>0)
91             {
92                 Criteria criteria = new Criteria();
93                 criteria.add(InboxAttachmentPeer.INBOX_ATTACHMENT_ID, entry_id);
94
95                 try{
96                     
97                 InboxAttachment entry = (InboxAttachment) InboxAttachmentPeer.doSelect(criteria).get(0);
98
99                 String JavaDoc tempContType= entry.getContentType().trim();
100                 String JavaDoc fileName= entry.getFileName().trim();
101
102                 data.getResponse().setContentType(entry.getContentType());
103                 log.debug(fileName);
104                 data.getResponse().setHeader("Content-disposition", "attachment; filename=\""+ fileName +"\"");
105                 data.declareDirectResponse();
106
107                 data.getResponse().getOutputStream().write(Base64.decode(entry.getContent()));
108
109               }
110               catch (Exception JavaDoc e)
111               {
112               }
113             }
114             
115             return null;
116         }
117
118         /**
119          * The layout must be set to null.
120          *
121          * @param data Turbine information.
122          * @return A null String.
123          */

124         public final String JavaDoc getLayout(RunData data)
125         {
126             return null;
127         }
128     
129
130 }
131
Popular Tags