1 5 package com.raptus.owxv3.libtags; 6 7 import java.util.Locale ; 8 9 import javax.servlet.jsp.*; 10 import javax.servlet.jsp.tagext.TagSupport ; 11 12 import org.apache.struts.Globals; 13 import org.apache.struts.util.*; 14 15 import com.raptus.owxv3.api.FieldContainerIFace; 16 17 39 public class FieldTag extends TagSupport { 40 41 42 44 47 protected String name; 48 49 public String getName() 50 { 51 return name; 52 } 53 public void setName(String s) 54 { 55 name=s; 56 } 57 58 protected String scope=null; 59 60 public String getScope() 61 { 62 return scope; 63 } 64 public void setScope(String s) 65 { 66 scope=s; 67 } 68 69 72 protected String field; 73 74 public String getField() 75 { 76 return field; 77 } 78 public void setField(String s) 79 { 80 field=s; 81 } 82 83 86 protected boolean filter=false; 87 public boolean getFilter() 88 { 89 return filter; 90 } 91 public void setFilter(boolean f) 92 { 93 filter=f; 94 } 95 96 100 protected String toBean=null; 101 102 public String getToBean() 103 { 104 return toBean; 105 } 106 public void setToBean(String s) 107 { 108 toBean=s; 109 } 110 111 112 113 115 116 121 public int doStartTag() throws JspException 122 { 123 Object bean = RequestUtils.lookup(pageContext, name, scope); 124 125 if(bean == null) 126 { 127 JspException e = new JspException("Cannot retrieve bean:" + name + " from scope:" + scope); 128 RequestUtils.saveException(pageContext, e); 129 throw e; 130 } 131 if(!(bean instanceof FieldContainerIFace)) 132 { 133 JspException e = new JspException("Bean does not implement FieldContanierIFace."); 134 RequestUtils.saveException(pageContext, e); 135 throw e; 136 } 137 138 FieldContainerIFace fc = (FieldContainerIFace) bean; 139 Locale userLocale = (Locale )pageContext.getAttribute(Globals.LOCALE_KEY, PageContext.SESSION_SCOPE); 140 String fieldValue = fc.getField(field,userLocale); 141 if(fieldValue==null) fieldValue=""; 142 if(filter) 143 { 144 fieldValue=ResponseUtils.filter(fieldValue); 145 } 146 if(toBean==null) 147 { 148 ResponseUtils.write(pageContext, fieldValue); 150 } 151 else 152 { 153 pageContext.setAttribute(toBean, fieldValue, PageContext.PAGE_SCOPE); 155 } 156 return (SKIP_BODY); 158 159 160 } 161 162 163 166 public void release() 167 { 168 super.release(); 169 name=null; 170 scope=null; 171 field=null; 172 filter=false; 173 toBean=null; 174 } 175 176 } 177 178 180 181 | Popular Tags |