KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
44 import java.util.Date JavaDoc;
45 import java.util.Calendar JavaDoc;
46
47 import org.apache.turbine.util.RunData;
48
49 import org.apache.torque.util.Criteria;
50 import org.campware.cream.om.NewsletterPeer;
51 import org.campware.cream.om.ProductPeer;
52
53 /**
54  * To read comments for this class, please see
55  * the ancestor class
56  */

57 public class NewsletterList extends CreamList
58 {
59
60     protected void initScreen()
61     {
62         setModuleType(DOCUMENT);
63         setModuleName("NEWSLETTER");
64         setIdName(NewsletterPeer.NEWSLETTER_ID);
65         setDefOrderColumn(NewsletterPeer.ISSUED_DATE);
66     }
67
68     protected String JavaDoc getSortColumn(int sortNo)
69     {
70         if (sortNo==1){
71             return NewsletterPeer.NEWSLETTER_CODE;
72         } else if (sortNo==2){
73             return NewsletterPeer.SUBJECT;
74         } else if (sortNo==3){
75             return ProductPeer.PRODUCT_DISPLAY;
76         } else if (sortNo==4){
77             return NewsletterPeer.ISSUED_DATE;
78         }
79         
80         return "";
81     }
82
83     protected void setFilter(int filterNo, Criteria listCriteria, RunData data)
84     {
85         int nowDay, nowMonth, nowYear;
86         
87         Calendar JavaDoc rightNow = Calendar.getInstance();
88         nowMonth= rightNow.get(Calendar.MONTH);
89         nowYear= rightNow.get(Calendar.YEAR);
90
91         rightNow.set(nowYear, nowMonth, 1);
92         Date JavaDoc fDayThisMonth= rightNow.getTime();
93         rightNow.set(nowYear, nowMonth + 1, 1);
94         Date JavaDoc fDayNextMonth= rightNow.getTime();
95         rightNow.set(nowYear, nowMonth - 1, 1);
96         Date JavaDoc fDayLastMonth= rightNow.getTime();
97         rightNow.set(nowYear, 1, 1);
98         Date JavaDoc fDayThisYear= rightNow.getTime();
99         rightNow.set(nowYear + 1, 1, 1);
100         Date JavaDoc fDayNextYear= rightNow.getTime();
101         rightNow.set(nowYear - 1, 1, 1);
102         Date JavaDoc fDayLastYear= rightNow.getTime();
103
104         try
105         {
106             if (filterNo==1001){
107                 listCriteria.add(NewsletterPeer.ISSUED_DATE, new Date JavaDoc(), Criteria.EQUAL);
108             } else if (filterNo==1002){
109                 Criteria.Criterion b1 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayThisMonth, Criteria.GREATER_EQUAL);
110                 Criteria.Criterion b2 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayNextMonth, Criteria.LESS_THAN);
111                 listCriteria.add( b1.and( b2));
112             } else if (filterNo==1003){
113                 Criteria.Criterion b1 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayLastMonth, Criteria.GREATER_EQUAL);
114                 Criteria.Criterion b2 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayThisMonth, Criteria.LESS_THAN);
115                 listCriteria.add( b1.and( b2));
116             } else if (filterNo==1004){
117                 Criteria.Criterion b1 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayThisYear, Criteria.GREATER_EQUAL);
118                 Criteria.Criterion b2 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayNextYear, Criteria.LESS_THAN);
119                 listCriteria.add( b1.and( b2));
120             } else if (filterNo==1005){
121                 Criteria.Criterion b1 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayLastYear, Criteria.GREATER_EQUAL);
122                 Criteria.Criterion b2 = listCriteria.getNewCriterion(NewsletterPeer.ISSUED_DATE, fDayThisYear, Criteria.LESS_THAN);
123                 listCriteria.add( b1.and( b2));
124             } else if (filterNo==1006){
125                 listCriteria.add(NewsletterPeer.STATUS, new Integer JavaDoc(10), Criteria.EQUAL);
126             } else if (filterNo==1007){
127                 listCriteria.add(NewsletterPeer.STATUS, new Integer JavaDoc(30), Criteria.EQUAL);
128             } else if (filterNo==1008){
129                 listCriteria.add(NewsletterPeer.STATUS, new Integer JavaDoc(50), Criteria.EQUAL);
130             } else if (filterNo==1009){
131                 listCriteria.add(NewsletterPeer.CREATED_BY, (Object JavaDoc) data.getUser().getName(), Criteria.EQUAL);
132             }
133         }
134         catch (Exception JavaDoc e)
135         {
136         }
137     }
138
139     protected void setFind(String JavaDoc findStr, Criteria listCriteria)
140     {
141         try
142         {
143             listCriteria.add(NewsletterPeer.NEWSLETTER_CODE, (Object JavaDoc)findStr, Criteria.LIKE);
144         }
145         catch (Exception JavaDoc e)
146         {
147         }
148     }
149
150     protected List JavaDoc getEntries(Criteria criteria)
151     {
152         try
153         {
154             criteria.addJoin(ProductPeer.PRODUCT_ID, NewsletterPeer.PRODUCT_ID);
155             return NewsletterPeer.doSelect(criteria);
156         }
157         catch (Exception JavaDoc e)
158         {
159             return null;
160         }
161     }
162
163 }
164
Popular Tags