KickJava   Java API By Example, From Geeks To Geeks.

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


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.Date JavaDoc;
44 import java.text.SimpleDateFormat JavaDoc;
45 import java.text.DecimalFormat JavaDoc;
46 import java.text.DecimalFormatSymbols JavaDoc;
47
48 import org.apache.turbine.util.RunData;
49
50 import org.apache.torque.util.Criteria;
51
52 import org.apache.velocity.context.Context;
53
54 /**
55  * Grabs a record from a database and makes
56  * the data available in the template.
57  *
58  * @author <a HREF="mailto:pandzic@volny.cz">Nenad Pandzic</a>
59  */

60 public class CreamUtil extends SecureScreen
61 {
62
63     private int defModuleType;
64     private String JavaDoc defModuleName=new String JavaDoc();
65
66     protected void initScreen()
67     {
68     }
69
70     /**
71      * Grab a record from the database based on the entry_id
72      * found in the form. Make the data available in the
73      * template.
74      */

75     public void doBuildTemplate(RunData data, Context context)
76     {
77         try
78         {
79             initScreen();
80             int entryId = data.getParameters().getInt("id");
81             
82             if (entryId>0)
83             {
84                 Criteria criteria = new Criteria();
85                 getDetail(entryId, criteria, context);
86
87                 context.put("mode", "update");
88             }
89
90             context.put("df", new SimpleDateFormat JavaDoc ("dd.MM.yyyy"));
91             context.put("dtf", new SimpleDateFormat JavaDoc ("dd.MM.yyyy hh:mm:ss"));
92             
93             DecimalFormatSymbols JavaDoc symb= new DecimalFormatSymbols JavaDoc();
94             symb.setDecimalSeparator('.');
95             
96             context.put("af", new DecimalFormat JavaDoc ("0.00", symb));
97             context.put("rf", new DecimalFormat JavaDoc ("0.000000", symb));
98             context.put("today", new Date JavaDoc());
99         }
100         catch (Exception JavaDoc e)
101         {
102             // log something ?
103
}
104     }
105
106     protected boolean getDetail(int myId, Criteria criteria, Context context)
107     {
108             return false;
109     }
110
111     protected void setModuleName(String JavaDoc name)
112     {
113             defModuleName=name;
114     }
115
116     protected void setModuleType(int modtype)
117     {
118             defModuleType=modtype;
119     }
120
121    
122 }
123
Popular Tags