1 package org.campware.cream.modules.screens; 2 3 42 43 import java.util.Date ; 44 import java.text.SimpleDateFormat ; 45 import java.text.DecimalFormat ; 46 import java.text.DecimalFormatSymbols ; 47 48 import org.apache.turbine.util.RunData; 49 import org.apache.turbine.util.security.AccessControlList; 50 51 import org.apache.torque.util.Criteria; 52 53 import org.apache.velocity.context.Context; 54 import org.apache.turbine.Turbine; 55 56 62 public class CreamForm extends SecureScreen 63 { 64 65 private int defModuleType; 66 private String defModuleName=new String (); 67 private String defIdName=new String (); 68 private String defFormIdName=new String (); 69 protected RunData myData; 70 71 protected void initScreen() 72 { 73 } 74 75 80 public void doBuildTemplate(RunData data, Context context) 81 { 82 try 83 { 84 myData= data; 85 int entry_id = data.getParameters().getInt(defFormIdName); 86 87 if (entry_id>0) 88 { 89 Criteria criteria = new Criteria(); 90 criteria.add(defIdName, entry_id); 91 getEntry(criteria, context); 92 93 context.put("mode", "update"); 94 } 95 else if (entry_id<0) 96 { 97 getNewRelated(entry_id * (-1), context); 98 context.put("mode", "insert"); 99 } 100 else 101 { 102 getNew(context); 103 context.put("mode", "insert"); 104 } 105 106 getLookups(context); 107 108 context.put("df", new SimpleDateFormat ("dd.MM.yyyy")); 109 context.put("dtf", new SimpleDateFormat ("dd.MM.yyyy hh:mm:ss")); 110 111 DecimalFormatSymbols symb= new DecimalFormatSymbols (); 112 symb.setDecimalSeparator('.'); 113 114 context.put("af", new DecimalFormat ("0.00", symb)); 115 context.put("rf", new DecimalFormat ("0.000000", symb)); 116 context.put("today", new Date ()); 117 } 118 catch (Exception e) 119 { 120 } 122 } 123 124 protected boolean isAuthorized( RunData data ) throws Exception 125 { 126 127 initScreen(); 128 boolean isAuthorized = false; 129 AccessControlList acl = data.getACL(); 130 131 if (data.getUser().hasLoggedIn()) 132 { 133 if (acl.hasPermission( defModuleName + "_VIEW") || acl.hasRole("turbine_root")) 134 { 135 isAuthorized = true; 136 } 137 else 138 { 139 data.setMessage("Sorry, you don't have permission for this operation!"); 140 data.setScreenTemplate("CreamError.vm"); 141 142 isAuthorized = false; 143 } 144 } 145 else 146 { 147 data.setScreenTemplate(Turbine.getConfiguration().getString("template.login")); 148 149 isAuthorized = false; 150 } 151 152 return isAuthorized; 153 } 154 155 protected boolean getEntry(Criteria criteria, Context context) 156 { 157 return false; 158 } 159 160 protected boolean getNew(Context context) 161 { 162 return false; 163 } 164 165 protected boolean getNewRelated(int relid, Context context) 166 { 167 return false; 168 } 169 170 protected boolean getLookups(Context context) 171 { 172 return false; 173 } 174 175 protected void setIdName(String name) 176 { 177 defIdName=name; 178 } 179 180 protected void setFormIdName(String name) 181 { 182 defFormIdName=name; 183 } 184 185 protected void setModuleName(String name) 186 { 187 defModuleName=name; 188 } 189 190 protected void setModuleType(int modtype) 191 { 192 defModuleType=modtype; 193 } 194 195 protected String formatDateTime(Date d) 196 { 197 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy hh:mm:ss"); 199 return formatter.format(d); 200 } 201 202 protected String formatDate(Date d) 203 { 204 SimpleDateFormat formatter = new SimpleDateFormat ("dd.MM.yyyy"); 206 return formatter.format(d); 207 } 208 209 210 } 211 | Popular Tags |