1 16 17 package org.apache.jetspeed.portal; 18 19 import java.io.File ; 20 import java.util.StringTokenizer ; 21 22 import org.apache.jetspeed.capability.CapabilityMap; 23 import org.apache.turbine.services.servlet.TurbineServlet; 24 25 34 public class BasePortletSkin extends java.util.HashMap implements PortletSkin 35 { 36 37 public String name = null; 38 private CapabilityMap cm; 39 private static final String [] VALID_EXTENSIONS = new String [] { "gif", "jpg", "png" }; 40 41 45 public String getName() 46 { 47 return this.name; 48 } 49 50 52 public void setName(String name) 53 { 54 this.name = name; 55 } 56 57 61 public String getTextColor() 62 { 63 return (String )get(TEXT_COLOR); 64 } 65 66 70 public void setTextColor(String color) 71 { 72 if (color!=null) 73 { 74 put(TEXT_COLOR,color); 75 } 76 } 77 78 82 public String getBackgroundColor() 83 { 84 return (String )get(BACKGROUND_COLOR); 85 } 86 87 91 public void setBackgroundColor(String color) 92 { 93 if (color!=null) 94 { 95 put(BACKGROUND_COLOR,color); 96 } 97 } 98 99 100 104 public String getTitleTextColor() 105 { 106 return (String )get(TITLE_TEXT_COLOR); 107 } 108 109 110 114 public void setTitleTextColor(String color) 115 { 116 if (color!=null) 117 { 118 put(TITLE_TEXT_COLOR,color); 119 } 120 } 121 122 126 public String getTitleBackgroundColor() 127 { 128 return (String )get(TITLE_BACKGROUND_COLOR); 129 } 130 131 135 public void setTitleBackgroundColor(String color) 136 { 137 if (color!=null) 138 { 139 put(TITLE_BACKGROUND_COLOR,color); 140 } 141 } 142 143 147 public String getHighlightTextColor() 148 { 149 return (String )get(HIGHLIGHT_TEXT_COLOR); 150 } 151 152 156 public void setHighlightTextColor(String color) 157 { 158 if (color!=null) 159 { 160 put(HIGHLIGHT_TEXT_COLOR,color); 161 } 162 } 163 164 168 public String getHighlightBackgroundColor() 169 { 170 return (String )get(HIGHLIGHT_BACKGROUND_COLOR); 171 } 172 173 177 public void setHighlightBackgroundColor(String color) 178 { 179 if (color!=null) 180 { 181 put(HIGHLIGHT_BACKGROUND_COLOR,color); 182 } 183 } 184 185 189 public String getPortletStyleClass() 190 { 191 return (String )get(PORTLET_STYLE_CLASS); 192 } 193 194 198 public void setPortletStyleClass(String portletStyleClass) 199 { 200 if (portletStyleClass!=null) 201 { 202 put(PORTLET_STYLE_CLASS,portletStyleClass); 203 } 204 } 205 206 210 public String getTitleStyleClass() 211 { 212 return (String )get(TITLE_STYLE_CLASS); 213 } 214 215 219 public void setTitleStyleClass(String titleStyleClass) 220 { 221 if (titleStyleClass!=null) 222 { 223 put(TITLE_STYLE_CLASS,titleStyleClass); 224 } 225 } 226 227 231 public String getContentStyleClass() 232 { 233 return (String )get(CONTENT_STYLE_CLASS); 234 } 235 236 240 public void setContentStyleClass(String contentStyleClass) 241 { 242 if (contentStyleClass!=null) 243 { 244 put(CONTENT_STYLE_CLASS,contentStyleClass); 245 } 246 } 247 248 252 public String getTabStyleClass() 253 { 254 return (String )get(TAB_STYLE_CLASS); 255 } 256 257 261 public void setTabStyleClass(String tabStyleClass) 262 { 263 if (tabStyleClass!=null) 264 { 265 put(TAB_STYLE_CLASS,tabStyleClass); 266 } 267 } 268 269 273 public String getTabTitleStyleClass() 274 { 275 return (String )get(TAB_TITLE_STYLE_CLASS); 276 } 277 278 282 public void setTabTitleStyleClass(String tabTitleStyleClass) 283 { 284 if (tabTitleStyleClass!=null) 285 { 286 put(TAB_TITLE_STYLE_CLASS,tabTitleStyleClass); 287 } 288 } 289 290 294 public String getTabContentStyleClass() 295 { 296 return (String )get(TAB_CONTENT_STYLE_CLASS); 297 } 298 299 303 public void setTabContentStyleClass(String tabContentStyleClass) 304 { 305 if (tabContentStyleClass!=null) 306 { 307 put(TAB_CONTENT_STYLE_CLASS,tabContentStyleClass); 308 } 309 } 310 311 315 public String getHighlightTitleStyleClass() 316 { 317 return (String )get(HIGHLIGHT_TITLE_STYLE_CLASS); 318 } 319 320 324 public void setHighlightTitleStyleClass(String highlightTitleStyleClass) 325 { 326 if (highlightTitleStyleClass!=null) 327 { 328 put(HIGHLIGHT_TITLE_STYLE_CLASS, highlightTitleStyleClass); 329 } 330 } 331 332 336 public String getControllerStyleClass() 337 { 338 return (String )get(CONTROLLER_STYLE_CLASS); 339 } 340 341 345 public void setControllerStyleClass(String controllerStyleClass) 346 { 347 if (controllerStyleClass!=null) 348 { 349 put(CONTROLLER_STYLE_CLASS,controllerStyleClass); 350 } 351 } 352 353 357 public String getPortletSkinClass() 358 { 359 return (String )get(PORTLET_SKIN_CLASS); 360 } 361 362 366 public void setPortletSkinClass(String portletSkinClass) 367 { 368 if (portletSkinClass!=null) 369 { 370 put(PORTLET_SKIN_CLASS,portletSkinClass); 371 } 372 } 373 374 377 public String getImage(String name, String dftPath) 378 { 379 380 if (containsKey("image-" + name)) 381 { 382 return buildMediaTypeSpecificPath((String ) get("image-" + name)); 383 } 384 385 String path = imageDiscovery(name); 386 if (path != null) 387 { 388 return path; 389 } 390 else 391 { 392 return dftPath; 393 } 394 } 395 396 397 403 public void setCapabilityMap(CapabilityMap cm) 404 { 405 this.cm = cm; 406 } 407 408 411 private String buildMediaTypeSpecificPath(String relativePath) 412 { 413 String path = "images/" + cm.getPreferredMediaType() + "/skins/" + relativePath; 414 return path; 415 } 416 417 420 private String buildMediaTypeSpecificPath() 421 { 422 return buildMediaTypeSpecificPath(name); 423 } 424 425 private String imageDiscovery(String imageName) 426 { 427 String imagePathes = (String ) get("image.paths"); 428 boolean hasExtension = hasImageExtension(imageName); 429 String fullPath = null; 430 if (imagePathes != null) 431 { 432 StringTokenizer tokenizer = new StringTokenizer (imagePathes, ","); 433 while (tokenizer.hasMoreTokens()) 434 { 435 fullPath = 436 buildValidImage( 437 buildMediaTypeSpecificPath(tokenizer.nextToken()), 438 imageName, 439 hasExtension); 440 if (fullPath != null) 441 { 442 return fullPath; 443 } 444 } 445 } 446 447 if (fullPath == null) 448 { 449 String skinBasedPath = buildMediaTypeSpecificPath(); 450 fullPath = buildValidImage(skinBasedPath, imageName, hasExtension); 451 } 452 return fullPath; 453 } 454 455 458 private boolean hasImageExtension(String path) 459 { 460 return (path.indexOf(".gif") > -1) 461 || (path.indexOf(".jpg") > -1) 462 || (path.indexOf(".png") > -1); 463 } 464 465 470 private String buildValidImage(String absPath, String relPath, boolean hasExtension) 471 { 472 String path = null; 473 474 if (hasExtension) 475 { 476 path = absPath + "/" + relPath; 477 if (fileExists(path)) 478 { 479 return path; 480 } 481 } 482 else 483 { 484 for (int i = 0; i < VALID_EXTENSIONS.length; i++) 485 { 486 path = absPath + "/" + relPath + "." + VALID_EXTENSIONS[i]; 487 if (fileExists(path)) 488 { 489 return path; 490 } 491 } 492 } 493 494 return null; 495 } 496 497 500 private boolean fileExists(String path) 501 { 502 File testPath = null; 503 testPath = new File (TurbineServlet.getRealPath(path)); 504 if (testPath.exists()) 505 { 506 testPath = null; 507 return true; 508 } 509 else 510 { 511 testPath = null; 512 return false; 513 } 514 } 515 516 } 517 | Popular Tags |