1 9 10 package com.opensymphony.module.sitemesh.taglib.decorator; 11 12 import com.opensymphony.module.sitemesh.HTMLPage; 13 import com.opensymphony.module.sitemesh.taglib.AbstractTag; 14 15 import java.io.Writer ; 16 17 25 public class PropertyTag extends AbstractTag { 26 private String propertyName, defaultValue; 27 private boolean writeEntireProperty = false; 28 29 30 public void setProperty(String propertyName) { 31 this.propertyName = propertyName; 32 } 33 34 35 public void setDefault(String defaultValue) { 36 this.defaultValue = defaultValue; 37 } 38 39 40 public final void setWriteEntireProperty(String writeEntireProperty) { 41 if (writeEntireProperty == null || writeEntireProperty.trim().length() == 0) 42 return; 43 44 switch (writeEntireProperty.charAt(0)) { 45 case '1': 46 case 't': 47 case 'T': 48 case 'y': 49 case 'Y': 50 this.writeEntireProperty = true; 51 break; 52 default: 53 this.writeEntireProperty = false; 54 } 55 } 56 57 public final int doEndTag() { 58 try { 59 HTMLPage htmlPage = (HTMLPage)getPage(); 60 String propertyValue = htmlPage.getProperty(propertyName); 61 62 if (propertyValue == null || propertyValue.trim().length() == 0) 63 propertyValue = defaultValue; 64 65 if (propertyValue != null) { 66 Writer out = getOut(); 67 if (writeEntireProperty) { 68 out.write(" "); 69 out.write(propertyName.substring(propertyName.lastIndexOf('.') + 1)); 70 out.write("=\""); 71 out.write(propertyValue); 72 out.write("\""); 73 } 74 else { 75 out.write(propertyValue); 76 } 77 } 78 } 79 catch (Exception e) { 80 trace(e); 81 } 82 return EVAL_PAGE; 83 } 84 85 } | Popular Tags |