1 18 19 package org.apache.struts.tiles.xmlDefinition; 20 21 import org.apache.struts.tiles.DefinitionNameAttribute; 22 import org.apache.struts.tiles.DirectStringAttribute; 23 import org.apache.struts.tiles.PathAttribute; 24 import org.apache.struts.tiles.UntypedAttribute; 25 26 29 public class XmlAttribute { 30 31 34 private String name = null; 35 36 40 private Object value = null; 41 42 45 private String direct = null; 46 47 50 private String valueType = null; 51 52 55 private String role = null; 56 57 62 private Object realValue = null; 63 64 67 public XmlAttribute() { 68 super(); 69 } 70 71 74 public XmlAttribute(String name, Object value) { 75 this.name = name; 76 this.value = value; 77 } 78 79 84 public String getName() { 85 return name; 86 } 87 88 93 public void setRole(String role) { 94 this.role = role; 95 } 96 97 102 public String getRole() { 103 return role; 104 } 105 106 111 public void setName(String aName) { 112 name = aName; 113 } 114 115 120 public String getAttribute() { 121 return name; 122 } 123 124 129 public void setAttribute(String aName) { 130 name = aName; 131 } 132 133 139 public Object getValue() { 140 if (this.realValue == null) { 142 this.realValue = this.computeRealValue(); 143 } 144 145 return this.realValue; 146 } 147 148 153 public void setValue(Object aValue) { 154 realValue = null; 155 value = aValue; 156 } 157 158 163 public void setContent(Object aValue) { 164 setValue(aValue); 165 } 166 167 172 public void setBody(String body) { 173 if (body.length() == 0) { 174 return; 175 } 176 177 setValue(body); 178 } 179 180 185 public void setDirect(String value) { 186 this.direct = value; 187 } 188 189 194 public void setType(String value) { 195 this.valueType = value; 196 } 197 198 201 protected Object computeRealValue() { 202 Object realValue = value; 203 if (direct != null) { 207 this.valueType = 208 Boolean.valueOf(direct).booleanValue() ? "string" : "path"; 209 } 210 211 if (value != null && valueType != null) { 212 String strValue = value.toString(); 213 214 if (valueType.equalsIgnoreCase("string")) { 215 realValue = new DirectStringAttribute(strValue); 216 217 } else if (valueType.equalsIgnoreCase("page")) { 218 realValue = new PathAttribute(strValue); 219 220 } else if (valueType.equalsIgnoreCase("template")) { 221 realValue = new PathAttribute(strValue); 222 223 } else if (valueType.equalsIgnoreCase("instance")) { 224 realValue = new DefinitionNameAttribute(strValue); 225 } 226 227 if (role != null) { 229 ((UntypedAttribute) realValue).setRole(role); 230 } 231 } 232 233 if (role != null && value != null && valueType == null) { 235 realValue = new UntypedAttribute(value.toString(), role); 236 } 237 238 return realValue; 239 } 240 } 241 | Popular Tags |