1 9 package org.jboss.portal.server.theme; 10 11 import org.apache.log4j.Logger; 12 import org.jboss.portal.server.PortalRequest; 13 import org.jboss.portal.server.PortalResponse; 14 import org.jboss.portal.server.servlet.FilterCommand; 15 16 import javax.servlet.FilterChain ; 17 import javax.servlet.RequestDispatcher ; 18 import javax.servlet.ServletException ; 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletRequestWrapper ; 21 import javax.servlet.http.HttpServletResponse ; 22 import java.io.IOException ; 23 24 32 public class LayoutDispatcher implements FilterCommand 33 { 34 35 private static final Logger log = Logger.getLogger(LayoutDispatcher.class); 36 37 40 private final PortalLayout layout; 41 private String uri; 42 43 47 public LayoutDispatcher(PortalLayout layout, String uri) throws IllegalArgumentException 48 { 49 if (layout == null) 50 { 51 throw new IllegalArgumentException ("No null layout allowed here"); 52 } 53 this.layout = layout; 54 this.uri = uri; 55 } 56 57 public Object execute(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws ServletException , IOException 58 { 59 HttpServletRequest wrapper = new HttpServletRequestWrapper (req) 61 { 62 public String getContextPath() 63 { 64 return layout.getContextPath(); 65 } 66 }; 67 68 chain.doFilter(wrapper, resp); 70 return null; 71 } 72 73 76 public void include(PortalRequest req, PortalResponse resp) throws IOException , ServletException 77 { 78 try 79 { 80 RequestDispatcher dispatcher = layout.getServletContext().getRequestDispatcher(uri); 81 log.debug("got request dispatcher for layout resource: " + (dispatcher != null)); 82 if (dispatcher == null) 83 { 84 throw new IOException ("No dispatcher found for : " + layout.getName() + " [" + uri + "]"); 85 } 86 req.setAttribute(FilterCommand.REQ_ATT_KEY, this); 87 dispatcher.include(req, resp); 88 log.debug("done with the layout"); 89 } 90 finally 91 { 92 req.removeAttribute(FilterCommand.REQ_ATT_KEY); 93 } 94 } 95 } 96 | Popular Tags |