1 26 package org.ofbiz.webapp.region; 27 28 import java.util.HashMap ; 29 import java.util.Map ; 30 import javax.servlet.RequestDispatcher ; 31 import javax.servlet.ServletContext ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.servlet.jsp.JspException ; 36 import javax.servlet.jsp.PageContext ; 37 38 import org.ofbiz.base.util.Debug; 39 import org.ofbiz.base.util.UtilJ2eeCompat; 40 41 50 public class Region extends Content { 51 52 public static final String module = Region.class.getName(); 53 54 private Map sections = new HashMap (); 55 protected String id; 56 57 public Region(String id, String content) { 58 this(id, content, null); } 60 61 public Region(String id, String content, Map sections) { 62 super(content, "region"); 63 this.id = id; 64 if (sections != null) { 65 this.sections.putAll(sections); 66 } 67 } 68 69 public String getId() { 70 return this.id; 71 } 72 73 public void put(Section section) { 74 sections.put(section.getName(), section); 75 } 76 77 public void putAll(Map newSections) { 78 sections.putAll(newSections); 79 } 80 81 public Section get(String name) { 82 return (Section) sections.get(name); 83 } 84 85 public Map getSections() { 86 return sections; 87 } 88 89 public void render(PageContext pageContext) throws JspException { 90 if (Debug.verboseOn()) Debug.logVerbose("Rendering " + this.toString(), module); 91 92 try { 93 this.render((HttpServletRequest ) pageContext.getRequest(), (HttpServletResponse ) pageContext.getResponse()); 94 } catch (java.io.IOException e) { 95 Debug.logError(e, "Error rendering region: ", module); 96 if (UtilJ2eeCompat.useNestedJspException(pageContext.getServletContext())) 97 throw new JspException (e); 98 else 99 throw new JspException (e.toString()); 100 } catch (ServletException e) { 101 Throwable throwable = e.getRootCause() != null ? e.getRootCause() : e; 102 103 Debug.logError(throwable, "Error rendering region: ", module); 104 if (UtilJ2eeCompat.useNestedJspException(pageContext.getServletContext())) { 105 throw new JspException (throwable); 106 } else { 107 throw new JspException (throwable.toString()); 108 } 109 } 110 } 111 112 public void render(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException , ServletException { 113 if (Debug.verboseOn()) Debug.logVerbose("Rendering " + this.toString(), module); 114 115 ServletContext application = (ServletContext ) request.getAttribute("servletContext"); 116 RequestDispatcher rd = application.getRequestDispatcher(content); 117 Debug.logInfo("real path for [" + content + "] is: " + application.getRealPath(content), module); 118 if (rd == null) { 120 throw new IllegalArgumentException ("HttpServletRequest returned a null RequestDispatcher for: [" + content + "]"); 121 } else { 122 } 125 rd.include(request, response); 126 } 127 128 public String toString() { 129 String s = "Region: " + content + ", type=" + type; 130 131 143 return s; 144 } 145 } 146 | Popular Tags |