1 34 35 36 package com.micronova.jsp.tag; 37 38 import com.micronova.util.*; 39 import com.micronova.util.servlet.*; 40 import java.util.*; 41 import java.util.regex.*; 42 import javax.servlet.*; 43 import javax.servlet.jsp.*; 44 import javax.servlet.http.*; 45 46 47 48 public class CallTag extends MapTag 49 { 50 protected String _path; 51 protected String _contextPath; 52 protected boolean _doesForward; 53 54 public final static String BODYPROPERTY = "parameter"; 55 public final static String RETURNPROPERTY = "_return"; 56 public final static String VALUEPROPERTY = "value"; 57 58 protected void init() 59 { 60 super.init(); 61 62 _path = null; 63 _contextPath = null; 64 _bodyProperty = BODYPROPERTY; 65 _doesForward = false; 66 } 67 68 69 70 public String getPath(String path, HttpServletRequest request) 71 { 72 if (!path.startsWith("/")) 73 { 74 path = request.getServletPath().replaceFirst("/[^/]*$", "") + "/" + path; 75 } 76 77 return path; 78 } 79 80 public String getContextPath(String contextPath) 81 { 82 if (contextPath != null) 83 { 84 if (!contextPath.startsWith("/")) 85 { 86 contextPath = "/" + contextPath; 87 } 88 } 89 90 return contextPath; 91 } 92 93 protected Object processValue(Object tagValue) throws Exception 94 { 95 super.processValue(tagValue); 96 97 NestedMap map = _map; 98 99 Map returnMap = map.getSubMap(RETURNPROPERTY); 100 101 returnMap.put(VALUEPROPERTY, null); 102 103 HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); 104 105 String path = getPath(_path, request); 106 String contextPath = getContextPath(_contextPath); 107 108 if (_doesForward) 109 { 110 HttpDispatch.forward(pageContext, path, contextPath, map); 111 } 112 else 113 { 114 tagValue = HttpDispatch.include(pageContext, path, contextPath, map); 115 } 116 117 Object returnValue = returnMap.get(VALUEPROPERTY); 118 119 if (!isEmptyString(returnValue)) 120 { 121 tagValue = returnValue; 122 } 123 124 return tagValue; 125 } 126 127 protected void copyFromSource(Object source) throws Exception 128 { 129 super.copyFromSource(source); 130 } 131 132 public void setPath(Object expression) throws Exception 133 { 134 _path = (String )evaluateAttribute("path", expression, String .class); 135 } 136 137 public void setContextPath(Object expression) throws Exception 138 { 139 _contextPath = (String )evaluateAttribute("contextPath", expression, String .class); 140 } 141 142 public void setBody(Object expression) throws Exception 143 { 144 _body = evaluateAttribute("body", expression, Object .class); 145 } 146 147 public void setDoesForward(Object expression) throws Exception 148 { 149 _doesForward = ((Boolean )evaluateAttribute("doesForward", expression, Boolean .class)).booleanValue(); 150 } 151 } 152 | Popular Tags |