1 19 20 package za.org.coefficient.html; 21 22 import za.org.coefficient.interfaces.ThemeLocalIf; 23 import za.org.coefficient.util.ejb.VelocityScreenUtil; 24 25 import java.util.HashMap ; 26 import java.util.Properties ; 27 28 34 public abstract class Theme implements ThemeLocalIf { 35 37 public static final String WEST_POSITION = "WEST"; 38 public static final String EAST_POSITION = "EAST"; 39 public static final String NORTH_POSITION = "NORTH"; 40 public static final String SOUTH_POSITION = "SOUTH"; 41 public static final String CENTER_POSITION = "CENTER"; 42 public static final String NULL_POSITION = "null"; 43 44 public String TABLEWIDTH = new String ("100%"); 45 public String BGCOLOUR = new String ("ffffff"); 46 public String CENTERBGCOLOUR = new String ("ffffff"); 47 public String CENTERPERCENTAGE = "60%"; 48 public String EAST = "east.vm"; 49 public String EASTBGCOLOUR = new String ("ffffff"); 50 public String EASTPERCENTAGE = "20%"; 51 public String HEADER = "header.vm"; 52 public String NORTH = "north.vm"; 53 public String NORTHBGCOLOUR = new String ("ffffff"); 54 public String SOUTH = "south.vm"; 55 public String SOUTHBGCOLOUR = new String ("ffffff"); 56 public String WELCOME = "welcome.vm"; 57 public String WEST = "west.vm"; 58 public String WESTBGCOLOUR = new String ("ffffff"); 59 public String WESTPERCENTAGE = "20%"; 60 public String CELLPADDING = "1"; 61 public String CELLSPACING = "1"; 62 public String themeName = null; 63 Properties props = new Properties (); 64 VelocityScreenUtil velocityScreenUtil = null; 65 66 protected String pathToThemeResource; 67 68 public void init(String themeName) { 69 this.themeName = themeName; 70 pathToThemeResource = this.getClass().getName(); 71 int lastPos = pathToThemeResource.lastIndexOf("."); 73 if (lastPos>0) { 74 pathToThemeResource = pathToThemeResource.substring(0, lastPos).replaceAll("\\.","/")+"/resource"; 75 } else { 76 pathToThemeResource="resource"; 77 } 78 try { 79 VelocityScreenUtil velocityScreenUtil = new VelocityScreenUtil(); 80 81 java.io.InputStream propStream = null; 82 propStream = 83 Theme.class.getResourceAsStream("/"+pathToThemeResource+"/"+themeName+".properties"); 84 if (propStream == null) { 85 System.out.println(themeName + " no properties"); 86 } 87 88 if (propStream != null) { 89 props.load(propStream); 90 } 91 92 java.lang.reflect.Field [] fields = this.getClass() 93 .getFields(); 94 int i; 95 for (i = 0; i < fields.length; i++) { 96 String name = fields[i].getName(); 97 String value = props.getProperty(name); 98 if (value != null) { 99 fields[i].set(this, value.trim()); 100 } 101 } 102 } catch (Throwable t) { 103 System.out.println(themeName + "Theme throws " + t); 104 } 105 } 106 107 109 public String getTableWidth(Page page) { 110 return TABLEWIDTH; 111 } 112 public String getBackGround(Page page) { 113 return BGCOLOUR; 114 } 115 116 public String getPathToThemeResource() { 117 return this.pathToThemeResource; 118 } 119 120 public String getCenter(Page page) { 121 StringBuffer sb = new StringBuffer (""); 122 sb.append("<table width=\"100%\" border=\"0\" cellpadding=\"0\" "); 124 sb.append("cellspacing=\"0\" "); 125 sb.append(BGCOLOUR); 126 sb.append(">\n"); 128 sb.append("<tr><td>\n"); 129 sb.append(page.getCenterContent()); 130 sb.append("</table>"); 131 132 return sb.toString(); 133 } 134 135 public String getCenterBackGround(Page page) { 136 return CENTERBGCOLOUR; 137 } 138 139 public String getCenterPercentage(Page page) { 140 return CENTERPERCENTAGE; 141 } 142 143 public String getEast(Page page) { 144 StringBuffer sb = new StringBuffer (""); 145 HashMap hash = new HashMap (); 146 hash.put("content", page.getEastContent()); 147 hash.put("width", EASTPERCENTAGE); 148 sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(pathToThemeResource + "/" +EAST, hash)); 149 150 return sb.toString(); 151 } 152 153 public String getEastBackGround(Page page) { 154 return EASTBGCOLOUR; 155 } 156 157 public String getEastPercentage(Page page) { 158 return EASTPERCENTAGE; 159 } 160 161 public String getFooter(Page page) { 162 return ""; 163 } 164 165 public String getHeader(Page page) { 166 StringBuffer sb = new StringBuffer (""); 167 sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(pathToThemeResource + "/" +HEADER, 168 new HashMap ())); 169 170 return sb.toString(); 171 } 172 173 public String getName(Page page) { 174 return themeName + "Theme"; 175 } 176 177 public String getName() { 178 return getName(null); 179 } 180 181 182 public String getNorth(Page page) { 183 StringBuffer sb = new StringBuffer (""); 184 HashMap hash = new HashMap (); 185 hash.put("content", page.getNorthContent()); 186 hash.put("project", page.getProject()); 187 sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(pathToThemeResource + "/" +NORTH, 188 hash)); 189 190 return sb.toString(); 191 } 192 193 public String getNorthBackGround(Page page) { 194 return NORTHBGCOLOUR; 195 } 196 197 public String getPosition(String moduleName) { 198 String position = props.getProperty(moduleName.trim()); 201 if (position == null) { 202 position = "CENTER"; 203 } 204 205 return position; 206 } 207 208 public String getSouth(Page page) { 209 StringBuffer sb = new StringBuffer (""); 210 HashMap hash = new HashMap (); 211 hash.put("content", page.getSouthContent()); 212 sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(pathToThemeResource + "/" +SOUTH, 213 hash)); 214 215 return sb.toString(); 216 } 217 218 public String getSouthBackGround(Page page) { 219 return SOUTHBGCOLOUR; 220 } 221 222 public String getWelcomePageContent() { 223 String content = null; 224 HashMap hash = new HashMap (); 225 try { 226 content = 227 velocityScreenUtil.getProcessedScreenFullyQualified(pathToThemeResource + "/" +WELCOME, 228 hash) 229 .toString(); 230 } catch (Throwable t) { 231 } 233 234 return content; 235 } 236 237 public String getWest(Page page) { 238 StringBuffer sb = new StringBuffer (""); 239 HashMap hash = new HashMap (); 240 hash.put("content", page.getWestContent()); 241 hash.put("project", page.getProject()); 242 hash.put("width", WESTPERCENTAGE); 243 sb.append(velocityScreenUtil.getProcessedScreenFullyQualified(pathToThemeResource + "/" +WEST, hash)); 244 245 return sb.toString(); 246 } 247 248 public String getWestBackGround(Page page) { 249 return WESTBGCOLOUR; 250 } 251 252 public String getWestPercentage(Page page) { 253 return WESTPERCENTAGE; 254 } 255 256 public String getCellPadding(Page page) { 257 return CELLPADDING; 258 } 259 260 public String getCellSpacing(Page page) { 261 return CELLSPACING; 262 } 263 264 public void format(Page page, String moduleName, String html) { 265 String position = getPosition(moduleName.replaceAll(" ", "")); 273 274 if (position.toLowerCase().equals(NULL_POSITION)) { 280 return; 281 } 282 283 int idx = position.indexOf(","); 284 Integer index = null; 285 if (idx > 0) { 286 index = Integer.decode(position.substring(idx + 1, position.length()).trim()); 287 position = position.substring(0, idx).trim(); 288 } 289 if(position.equals(WEST_POSITION)) { 290 page.setWestContent(html, index, moduleName); 291 } else if(position.equals(EAST_POSITION)) { 292 page.setEastContent(html, index, moduleName); 293 } else if(position.equals(NORTH_POSITION)) { 294 page.setNorthContent(html, index, moduleName); 295 } else if(position.equals(SOUTH_POSITION)) { 296 page.setSouthContent(html, index, moduleName); 297 } else if(position.equals(CENTER_POSITION)) { 298 page.setCenterContent(html, index, moduleName); 299 } 300 } 301 302 public String getPositionForModule(String moduleName) { 303 String position = getPosition(moduleName.replaceAll(" ", "")); 311 312 if(position.toLowerCase().equals(NULL_POSITION)) { 318 return NULL_POSITION; 319 } 320 321 int idx = position.indexOf(","); 322 if (idx > 0) { 323 position = position.substring(0, idx).trim(); 324 } 325 if(position == null) { 326 position = CENTER_POSITION; 327 } 328 return position; 329 } 330 } 331 | Popular Tags |