1 18 19 20 package org.apache.struts.taglib.bean; 21 22 23 import javax.servlet.jsp.JspException ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.struts.config.ModuleConfig; 27 import org.apache.struts.taglib.TagUtils; 28 import org.apache.struts.util.MessageResources; 29 30 31 37 38 public class StrutsTag extends TagSupport { 39 40 41 43 44 48 protected String id = null; 49 50 public String getId() { 51 return (this.id); 52 } 53 54 public void setId(String id) { 55 this.id = id; 56 } 57 58 59 62 protected static MessageResources messages = 63 MessageResources.getMessageResources 64 ("org.apache.struts.taglib.bean.LocalStrings"); 65 66 67 70 protected String formBean = null; 71 72 public String getFormBean() { 73 return (this.formBean); 74 } 75 76 public void setFormBean(String formBean) { 77 this.formBean = formBean; 78 } 79 80 81 84 protected String forward = null; 85 86 public String getForward() { 87 return (this.forward); 88 } 89 90 public void setForward(String forward) { 91 this.forward = forward; 92 } 93 94 95 98 protected String mapping = null; 99 100 public String getMapping() { 101 return (this.mapping); 102 } 103 104 public void setMapping(String mapping) { 105 this.mapping = mapping; 106 } 107 108 109 111 112 118 public int doStartTag() throws JspException { 119 120 int n = 0; 122 if (formBean != null) 123 n++; 124 if (forward != null) 125 n++; 126 if (mapping != null) 127 n++; 128 if (n != 1) { 129 JspException e = new JspException 130 (messages.getMessage("struts.selector")); 131 TagUtils.getInstance().saveException(pageContext, e); 132 throw e; 133 } 134 135 ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext); 137 138 Object object = null; 140 String selector = null; 141 if (formBean != null) { 142 selector = formBean; 143 object = config.findFormBeanConfig(formBean); 144 } else if (forward != null) { 145 selector = forward; 146 object = config.findForwardConfig(forward); 147 } else if (mapping != null) { 148 selector = mapping; 149 object = config.findActionConfig(mapping); 150 } 151 if (object == null) { 152 JspException e = new JspException 153 (messages.getMessage("struts.missing", selector)); 154 TagUtils.getInstance().saveException(pageContext, e); 155 throw e; 156 } 157 158 pageContext.setAttribute(id, object); 160 return (SKIP_BODY); 161 162 } 163 164 165 168 public void release() { 169 170 super.release(); 171 id = null; 172 formBean = null; 173 forward = null; 174 mapping = null; 175 176 } 177 178 179 } 180 | Popular Tags |