1 package org.campware.cream.modules.screens; 2 3 42 43 import java.util.List ; 44 import java.util.Locale ; 45 import java.text.SimpleDateFormat ; 46 import java.text.DecimalFormat ; 47 import java.text.DecimalFormatSymbols ; 48 49 import org.apache.turbine.util.RunData; 50 import org.apache.turbine.util.security.AccessControlList; 51 52 import org.apache.torque.util.Criteria; 53 import org.apache.velocity.context.Context; 54 import org.apache.turbine.Turbine; 55 56 63 public class CreamList extends SecureScreen 64 { 65 66 private int defModuleType; 67 private String defModuleName=new String (); 68 private String defIdName=new String (); 69 private String defOrderColumn=new String (); 70 71 protected void initScreen() 72 { 73 } 74 75 79 public void doBuildTemplate(RunData data, Context context) 80 { 81 82 int filterNo = 0; 83 int sortNo = 0; 84 String orderStr = new String (); 85 String findStr = new String (); 86 87 Locale myLocale = new Locale ("ENGLISH", "UK"); 88 data.setLocale(myLocale); 89 90 filterNo = data.getParameters().getInt("filter", 0); 91 sortNo = data.getParameters().getInt("sortcol", 0); 92 orderStr = data.getParameters().getString("sortord", "ASC"); 93 findStr = data.getParameters().getString("find", ""); 94 95 Criteria criteria = new Criteria(); 96 criteria.add(defIdName, 1000, Criteria.GREATER_THAN); 97 98 if (filterNo>0) 99 { 100 setFilter(filterNo, criteria, data); 101 } 102 else 103 { 104 if (findStr.length()>0) 105 { 106 findStr= findStr + "%"; 107 setFind(findStr, criteria); 108 } 109 } 110 111 if (sortNo>0) 112 { 113 String sortCol= new String (getSortColumn(sortNo)); 114 if (sortCol.length()>0){ 115 if (orderStr.equals("ASC")){ 116 criteria.addAscendingOrderByColumn(sortCol); 117 }else{ 118 criteria.addDescendingOrderByColumn(sortCol); 119 } 120 } 121 } 122 123 criteria.setIgnoreCase(true); 124 125 context.put("entries", getEntries(criteria)); 126 context.put("df", new SimpleDateFormat ("dd.MM.yyyy")); 127 128 DecimalFormatSymbols symb= new DecimalFormatSymbols (); 129 symb.setDecimalSeparator('.'); 130 131 context.put("af", new DecimalFormat ("0.00", symb)); 132 context.put("rf", new DecimalFormat ("0.000000", symb)); 133 134 } 135 136 protected boolean isAuthorized( RunData data ) throws Exception 137 { 138 139 initScreen(); 140 boolean isAuthorized = false; 141 AccessControlList acl = data.getACL(); 142 143 if (data.getUser().hasLoggedIn()) 144 { 145 if (acl.hasPermission( defModuleName + "_VIEW") || acl.hasRole("turbine_root")) 146 { 147 isAuthorized = true; 148 } 149 else 150 { 151 data.setMessage("Sorry, you don't have permission for this operation!"); 152 data.setScreenTemplate("CreamError.vm"); 153 154 isAuthorized = false; 155 } 156 } 157 else 158 { 159 data.setScreenTemplate(Turbine.getConfiguration().getString("template.login")); 160 161 isAuthorized = false; 162 } 163 164 return isAuthorized; 165 } 166 167 protected void setFilter(int filterNo, Criteria listCriteria, RunData data) 168 { 169 } 170 171 protected void setSort(int sortNo, Criteria listCriteria) 172 { 173 } 174 175 protected String getSortColumn(int sortNo) 176 { 177 return ""; 178 } 179 180 protected void setFind(String findStr, Criteria listCriteria) 181 { 182 } 183 184 protected void setDefOrderColumn(String name) 185 { 186 defOrderColumn=name; 187 } 188 189 protected void setIdName(String name) 190 { 191 defIdName=name; 192 } 193 194 protected void setModuleName(String name) 195 { 196 defModuleName=name; 197 } 198 199 protected void setModuleType(int modtype) 200 { 201 defModuleType=modtype; 202 } 203 204 210 protected List getEntries(Criteria criteria) 211 { 212 return null; 213 } 214 215 216 } 217 | Popular Tags |