1 34 35 36 package com.micronova.jsp.tag; 37 38 import com.micronova.util.*; 39 import java.util.*; 40 41 42 43 public class MapTag extends YuzuTag 44 { 45 protected Object _source; 46 protected NestedMap _map; 47 protected String _bodyProperty; 48 protected Object _body; 49 50 51 52 protected void init() 53 { 54 super.init(); 55 56 _source = null; 57 _bodyProperty = null; 58 _body = null; 59 60 NestedMap map = _map; 61 62 if (map == null) 63 { 64 map = new NestedMap(); 65 _map = map; 66 } 67 else 68 { 69 map.clear(); 70 map.setAcceptable(null); 71 } 72 73 _value = map; 74 } 75 76 77 78 protected void cleanup() 79 { 80 if (_isAssigned) 81 { 82 _map = null; 83 } 84 } 85 86 87 88 public void setSource(Object expression) throws Exception 89 { 90 Object source = evaluateAttribute("source", expression, Object .class); 91 92 _source = source; 93 94 if (_isInBody) 95 { 96 copyFromSource(source); 97 } 98 } 99 100 101 102 protected void copyFromSource(Object source) throws Exception 103 { 104 _map.copyFromSource(source); 105 } 106 107 108 109 protected Object prepareValue(Object tagValue) throws Exception 110 { 111 Object source = _source; 112 113 if (source != null) 114 { 115 copyFromSource(source); 116 } 117 118 return super.prepareValue(tagValue); 119 } 120 121 protected boolean doesImport(Object tagValue) 122 { 123 return (!isEmptyString(_bodyProperty)); 124 } 125 126 protected Object importBody(Object tagValue) throws Exception 127 { 128 if (_body == null) 129 { 130 Object importedValue = super.importBody(tagValue); 131 132 if (importedValue != tagValue) 133 { 134 _body = importedValue; 135 } 136 } 137 138 return tagValue; 139 } 140 141 protected Object processValue(Object tagValue) throws Exception 142 { 143 NestedMap map = _map; 144 145 String bodyProperty = _bodyProperty; 146 147 if (!isEmptyString(bodyProperty)) 148 { 149 map.put(bodyProperty, _body); 150 } 151 152 return tagValue; 153 } 154 155 public void setBodyProperty(Object expression) throws Exception 156 { 157 _bodyProperty = (String )evaluateAttribute("bodyProperty", expression, String .class); 158 } 159 } 160 | Popular Tags |