1 17 18 package com.finalist.jag; 19 20 21 import com.finalist.jag.template.*; 22 import com.finalist.jag.template.parser.*; 23 import com.finalist.jag.taglib.*; 24 import org.apache.commons.beanutils.ConvertUtils; 25 import org.apache.commons.beanutils.PropertyUtils; 26 27 28 29 36 public class TagProcess implements TagConstants { 37 38 39 private TagSupport tagInstance = null; 40 41 42 private TemplateTag tagRef = null; 43 44 45 private int process = EVAL_PAGE; 46 47 48 private String bodyText; 49 50 51 58 public TagProcess(TemplateTag tagRef) { 59 this.tagRef = tagRef; 60 } 61 62 63 72 public int process() throws JagException { 73 74 if (tagInstance == null) { 75 try { 76 TagDef tagDef = tagRef.getTagDefinition(); 77 Object object = 78 Class.forName(tagDef.getTagClass()).newInstance(); 79 80 tagInstance = (TagSupport) object; 81 82 tagInstance.setPageContext(tagRef.getPageContext()); 84 85 JagParameter[] params = tagRef.getParamArray(); 87 88 for (int i = 0; i < params.length; i++) { 89 String sIdent = params[i].getIdent(); 90 String sValue = params[i].getValue(); 91 Object value = ConvertUtils.convert(sValue, String .class); 92 PropertyUtils.setProperty(tagInstance, sIdent, value); 93 } 94 95 AttributeDef[] tagAttributes = tagDef.getAttributeDefArray(); 97 98 for (int i = 0; i < tagAttributes.length; i++) { 99 if (!tagAttributes[i].getRequired()) { 100 continue; 101 } 102 103 String sPropertyName = tagAttributes[i].getName(); 104 Object value = PropertyUtils.getProperty(tagInstance, sPropertyName); 105 106 if ((value == null) || (value.toString().length() < 1)) { 107 throw new JagException("ERROR: Can't find '" + sPropertyName + "' in " + tagInstance); 108 } 109 } 110 } 111 catch (Exception exc) { 112 throw new JagException(exc.toString()); 113 } 114 115 if (tagInstance == null) { 116 return getProcess(); 117 } 118 119 if (!tagRef.isProcessed()) { 120 tagRef.setProcessed(true); 121 tagRef.clearCloseTag(); 122 tagRef.clearTag(); 123 } 124 } 125 JagTextBlockWriter writer = new JagTextBlockWriter(tagRef.getTextBuffer()); 127 tagInstance.setWriter(writer); 128 129 process(tagInstance); 130 131 return getProcess(); 132 } 133 134 135 144 public void process(TagSupport tagInstance) throws JagException { 145 146 if (process == EVAL_PAGE) { 147 process = tagInstance.doStartTag(); 148 149 if (process == SKIP_PAGE) { 150 return; 151 } 152 } 153 154 if ((process != SKIP_BODY && process != SKIP_CLEAR_BODY) 155 && (tagInstance instanceof TagBodySupport)) { 156 TagBodySupport bodyTag = (TagBodySupport) tagInstance; 157 158 bodyTag.setBodyText(bodyText); 159 160 if (process == EVAL_PAGE) { 161 bodyTag.doInitBodyTag(); 162 } 163 164 process = bodyTag.doAfterBodyTag(); 165 166 if (process == EVAL_BODY_TAG) { 167 return; 168 } 169 170 if (process == SKIP_BODY || process == SKIP_CLEAR_BODY) { 171 return; 172 } 173 } 174 175 process = tagInstance.doEndTag(); 176 177 tagInstance.release(); 178 } 179 180 181 188 public int getProcess() { 189 return process; 190 } 191 192 193 200 public void setBodyText(String bodyText) { 201 this.bodyText = bodyText; 202 } 203 } 204 205 ; | Popular Tags |