KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > campware > cream > modules > actions > CreamPublicAction


1 package org.campware.cream.modules.actions;
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.ParsePosition JavaDoc;
46 import org.apache.velocity.context.Context;
47
48 import org.apache.turbine.modules.actions.VelocitySecureAction;
49 import org.apache.turbine.util.RunData;
50 import org.apache.turbine.util.security.AccessControlList;
51 import org.apache.turbine.Turbine;
52
53 /**
54  * Cream Secure action.
55  *
56  * Always performs a Security Check that you've defined before
57  * executing the doBuildtemplate().
58  * @author <a HREF="mailto:pandzic@volny.cz">Nenad Pandzic</a>
59  */

60 public class CreamPublicAction extends VelocitySecureAction
61 {
62     public static final int ENTITY=1001;
63     public static final int DOCUMENT=1002;
64     public static final int LOOKUP=1003;
65     public static final int SYSTEM=1004;
66     public static final int REPORT=1005;
67     public static final int UTIL=1006;
68
69     private int defModuleType;
70     private String JavaDoc defModuleName=new String JavaDoc();
71
72     protected void initScreen()
73     {
74     }
75     
76     /**
77      * Implement this to add information to the context.
78      *
79      * @param data Turbine information.
80      * @param context Context for web pages.
81      * @exception Exception, a generic exception.
82      */

83     public void doPerform( RunData data,Context context )
84         throws Exception JavaDoc
85     {
86         data.setMessage("Can't find the button!");
87     }
88
89     /**
90      * This currently only checks to make sure that user is allowed to
91      * view the storage area. If you create an action that requires more
92      * security then override this method.
93      *
94      * @param data Turbine information.
95      * @return True if the user is authorized to access the screen.
96      * @exception Exception, a generic exception.
97      */

98     protected boolean isAuthorized( RunData data ) throws Exception JavaDoc
99     {
100         initScreen();
101         return true;
102     }
103
104     protected Date JavaDoc parseDateTime(String JavaDoc d)
105         throws Exception JavaDoc
106     {
107 // return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).parse(d);
108
SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc ("dd.MM.yyyy hh:mm:ss");
109         ParsePosition JavaDoc pos = new ParsePosition JavaDoc(0);
110         return formatter.parse(d, pos);
111     }
112
113     protected Date JavaDoc parseDate(String JavaDoc d)
114         throws Exception JavaDoc
115     {
116 // return DateFormat.getDateInstance(DateFormat.SHORT).parse(d);
117
SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc ("dd.MM.yyyy");
118         ParsePosition JavaDoc pos = new ParsePosition JavaDoc(0);
119         try{
120             Date JavaDoc myDate= formatter.parse(d, pos);
121             return myDate;
122         }
123         catch (Exception JavaDoc e)
124         {
125             return null;
126         }
127             
128     }
129
130     protected String JavaDoc formatDate(Date JavaDoc d)
131     {
132         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc ("dd.MM.yyyy");
133         return formatter.format(d);
134     }
135     
136
137     protected String JavaDoc getTempCode()
138     {
139         Date JavaDoc currDate= new Date JavaDoc();
140
141         return Integer.toString(currDate.hashCode());
142     }
143
144     protected String JavaDoc getRowCode(String JavaDoc s, int i)
145     {
146         String JavaDoc is= new String JavaDoc();
147         
148         is= Integer.toString(i);
149         while (is.length()<7)
150         {
151             is="0" + is;
152         }
153
154         is= s + is;
155         return is;
156     }
157
158     protected void setModuleName(String JavaDoc name)
159     {
160             defModuleName=name;
161     }
162
163     protected void setModuleType(int modtype)
164     {
165             defModuleType=modtype;
166     }
167
168
169 }
170
Popular Tags