1 package org.campware.cream.modules.actions; 2 3 42 43 import java.util.Date ; 44 import java.text.SimpleDateFormat ; 45 import java.text.ParsePosition ; 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 60 public class CreamAction 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 defModuleName=new String (); 71 72 protected void initScreen() 73 { 74 } 75 76 83 public void doPerform( RunData data,Context context ) 84 throws Exception 85 { 86 data.setMessage("Can't find the button!"); 87 } 88 89 98 protected boolean isAuthorized( RunData data ) throws Exception 99 { 100 initScreen(); 101 boolean isAuthorized = false; 102 103 AccessControlList acl = data.getACL(); 104 105 if (data.getUser().hasLoggedIn()) 106 { 107 if (acl.hasPermission( defModuleName + "_MODIFY") || acl.hasRole("turbine_root")) 108 { 109 isAuthorized = true; 110 } 111 else 112 { 113 data.setMessage("Sorry, you don't have permission for this operation!"); 114 data.setScreenTemplate("CreamError.vm"); 115 116 isAuthorized = false; 117 } 118 } 119 else 120 { 121 data.setScreenTemplate(Turbine.getConfiguration().getString("template.login")); 122 123 isAuthorized = false; 124 } 125 126 return isAuthorized; 127 } 128 129 protected Date parseDateTime(String d) 130 throws Exception 131 { 132 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy hh:mm:ss"); 134 ParsePosition pos = new ParsePosition (0); 135 return formatter.parse(d, pos); 136 } 137 138 protected Date parseDate(String d) 139 throws Exception 140 { 141 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy"); 143 ParsePosition pos = new ParsePosition (0); 144 try{ 145 Date myDate= formatter.parse(d, pos); 146 return myDate; 147 } 148 catch (Exception e) 149 { 150 return null; 151 } 152 153 } 154 155 protected String formatDate(Date d) 156 { 157 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy"); 158 return formatter.format(d); 159 } 160 161 162 protected String getTempCode() 163 { 164 Date currDate= new Date (); 165 166 return Integer.toString(currDate.hashCode()); 167 } 168 169 protected String getRowCode(String s, int i) 170 { 171 String is= new String (); 172 173 is= Integer.toString(i); 174 while (is.length()<7) 175 { 176 is="0" + is; 177 } 178 179 is= s + is; 180 return is; 181 } 182 183 protected void setModuleName(String name) 184 { 185 defModuleName=name; 186 } 187 188 protected void setModuleType(int modtype) 189 { 190 defModuleType=modtype; 191 } 192 193 194 public void doInsertrow(RunData data, Context context) 195 throws Exception 196 { 197 try{ 198 doInsert(data, context); 199 }catch (Exception e){ 200 handleCreamException(data, e); 201 } 202 } 203 204 public void doUpdaterow(RunData data, Context context) 205 throws Exception 206 { 207 try{ 208 doUpdate(data, context); 209 }catch (Exception e){ 210 handleCreamException(data, e); 211 } 212 } 213 214 public void doDeleterow(RunData data, Context context) 215 throws Exception 216 { 217 try{ 218 doDelete(data, context); 219 }catch (Exception e){ 220 handleCreamException(data, e); 221 } 222 } 223 224 public void doDeleteselectedrows(RunData data, Context context) 225 throws Exception 226 { 227 try{ 228 doDeleteselected(data, context); 229 }catch (Exception e){ 230 handleCreamException(data, e); 231 } 232 } 233 234 public void doInsert(RunData data, Context context) 235 throws Exception 236 { 237 238 } 239 240 public void doUpdate(RunData data, Context context) 241 throws Exception 242 { 243 244 } 245 246 public void doDelete(RunData data, Context context) 247 throws Exception 248 { 249 250 } 251 252 public void doDeleteselected(RunData data, Context context) 253 throws Exception 254 { 255 256 } 257 258 protected void handleCreamException(RunData data, String message) 259 { 260 data.setMessage(message); 261 this.setTemplate( data, "CreamError.vm"); 262 } 263 264 private void handleCreamException(RunData data, Exception e) 265 { 266 this.setTemplate( data, "CreamError.vm"); 267 } 268 269 } 270 | Popular Tags |