1 24 package org.ofbiz.widget; 25 26 import java.util.Map ; 27 import javax.servlet.ServletContext ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.ofbiz.base.util.UtilHttp; 32 import org.ofbiz.base.util.UtilValidate; 33 import org.ofbiz.webapp.control.RequestHandler; 34 import org.ofbiz.webapp.taglib.ContentUrlTag; 35 36 public class WidgetWorker { 37 38 public static final String module = WidgetWorker.class.getName(); 39 40 public WidgetWorker () {} 41 42 public static void buildHyperlinkUrl(StringBuffer buffer, String requestName, String targetType, HttpServletRequest request, HttpServletResponse response, Map context) { 43 String localRequestName = UtilHttp.encodeAmpersands(requestName); 44 45 if ("intra-app".equals(targetType)) { 46 appendOfbizUrl(buffer, "/" + localRequestName, request, response); 47 } else if ("inter-app".equals(targetType)) { 48 String fullTarget = localRequestName; 49 buffer.append(fullTarget); 50 String externalLoginKey = (String ) request.getAttribute("externalLoginKey"); 51 if (UtilValidate.isNotEmpty(externalLoginKey)) { 52 if (fullTarget.indexOf('?') == -1) { 53 buffer.append('?'); 54 } else { 55 buffer.append("&"); 56 } 57 buffer.append("externalLoginKey="); 58 buffer.append(externalLoginKey); 59 } 60 } else if ("content".equals(targetType)) { 61 appendContentUrl(buffer, localRequestName, request); 62 } else if ("plain".equals(targetType)) { 63 buffer.append(localRequestName); 64 } else { 65 buffer.append(localRequestName); 66 } 67 68 69 return; 70 } 71 72 public static void appendOfbizUrl(StringBuffer buffer, String location, HttpServletRequest request, HttpServletResponse response) { 73 ServletContext ctx = (ServletContext ) request.getAttribute("servletContext"); 74 RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); 75 buffer.append(rh.makeLink(request, response, location)); 77 } 78 79 public static void appendContentUrl(StringBuffer buffer, String location, HttpServletRequest request) { 80 ContentUrlTag.appendContentPrefix(request, buffer); 81 buffer.append(location); 82 } 83 84 public static void makeHyperlinkString(StringBuffer buffer, String linkStyle, String targetType, String target, String description, HttpServletRequest request, HttpServletResponse response, Map context, String targetWindow) { 85 if (UtilValidate.isNotEmpty(description)) { 86 buffer.append("<a"); 87 88 if (UtilValidate.isNotEmpty(linkStyle)) { 89 buffer.append(" class=\""); 90 buffer.append(linkStyle); 91 buffer.append("\""); 92 } 93 94 buffer.append(" HREF=\""); 95 96 WidgetWorker.buildHyperlinkUrl(buffer, target, targetType, request, response, context); 97 98 buffer.append("\""); 99 100 if (UtilValidate.isNotEmpty(targetWindow)) { 101 buffer.append(" target=\""); 102 buffer.append(targetWindow); 103 buffer.append("\""); 104 } 105 106 107 buffer.append('>'); 108 109 buffer.append(description); 110 buffer.append("</a>"); 111 } 112 } 113 } 114 | Popular Tags |