KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.torque.util.Criteria;
44
45 import org.apache.velocity.context.Context;
46
47 import org.campware.cream.om.OutboxEvent;
48 import org.campware.cream.om.OutboxEventPeer;
49 import org.campware.cream.om.InboxEvent;
50 import org.campware.cream.om.InboxEventPeer;
51 import org.campware.cream.om.CustomerPeer;
52 import org.campware.cream.om.ProductPeer;
53 import org.campware.cream.om.ProjectPeer;
54
55 /**
56  * To read comments for this class, please see
57  * the ancestor class
58  */

59 public class OutboxEventForm extends CreamForm
60 {
61     protected void initScreen()
62     {
63         setModuleType(DOCUMENT);
64         setModuleName("OUTBOX");
65         setIdName(OutboxEventPeer.OUTBOX_EVENT_ID);
66         setFormIdName("outboxeventid");
67     }
68
69     protected boolean getEntry(Criteria criteria, Context context)
70     {
71         try
72         {
73             OutboxEvent entry = (OutboxEvent) OutboxEventPeer.doSelect(criteria).get(0);
74             context.put("entry", entry);
75             
76             return true;
77         }
78         catch (Exception JavaDoc e)
79         {
80             return false;
81         }
82     }
83
84     protected boolean getNew(Context context)
85     {
86         try
87         {
88             OutboxEvent entry = new OutboxEvent();
89             context.put("entry", entry);
90             return true;
91         }
92         catch (Exception JavaDoc e)
93         {
94             return false;
95         }
96     }
97
98     protected boolean getNewRelated(int relid, Context context)
99     {
100         try
101         {
102             Criteria criteria = new Criteria();
103             criteria.add(InboxEventPeer.INBOX_EVENT_ID, relid);
104             InboxEvent relEntry = (InboxEvent) InboxEventPeer.doSelect(criteria).get(0);
105
106             OutboxEvent entry = new OutboxEvent();
107
108             entry.setCustomerId(relEntry.getCustomerId());
109             entry.setProductId(relEntry.getProductId());
110             entry.setProjectId(relEntry.getProjectId());
111
112             String JavaDoc oldSubject= relEntry.getSubject();
113             String JavaDoc oldSender= relEntry.getSenderEmail();
114             String JavaDoc oldReplyTo= relEntry.getSenderReplyTo();
115
116             if (oldReplyTo.length()>2){
117                 entry.setReceiverTo(oldReplyTo);
118             }else{
119                 entry.setReceiverTo(oldSender);
120             }
121             
122             if (oldSubject.startsWith("Re:")){
123                 entry.setSubject(oldSubject);
124             }else{
125                 entry.setSubject("Re: " + oldSubject);
126             }
127 // entry.setBody("\n\n\n----- Original Message -----\n" + relEntry.getBody());
128
entry.setBody("<br/><br/>------------------------------<br/><br/>" + relEntry.getBody());
129         
130             context.put("entry", entry);
131             
132             return true;
133         }
134         catch (Exception JavaDoc e)
135         {
136             return false;
137         }
138     }
139
140     protected boolean getLookups(Context context)
141     {
142         try
143         {
144             Criteria custcrit = new Criteria();
145             custcrit.add(CustomerPeer.CUSTOMER_ID, 999, Criteria.GREATER_THAN);
146             custcrit.addAscendingOrderByColumn(CustomerPeer.CUSTOMER_DISPLAY);
147             context.put("customers", CustomerPeer.doSelect(custcrit));
148
149             Criteria prodcrit = new Criteria();
150             prodcrit.add(ProductPeer.PRODUCT_ID, 999, Criteria.GREATER_THAN);
151             prodcrit.addAscendingOrderByColumn(ProductPeer.PRODUCT_DISPLAY);
152             context.put("products", ProductPeer.doSelect(prodcrit));
153
154             Criteria projcrit = new Criteria();
155             projcrit.add(ProjectPeer.PROJECT_ID, 999, Criteria.GREATER_THAN);
156             projcrit.addAscendingOrderByColumn(ProjectPeer.PROJECT_NAME);
157             context.put("projects", ProjectPeer.doSelect(projcrit));
158
159
160             return true;
161         }
162         catch (Exception JavaDoc e)
163         {
164             return false;
165         }
166     }
167
168 }
169
Popular Tags