1 25 package org.ofbiz.webapp.view; 26 27 import java.io.IOException ; 28 import java.io.OutputStreamWriter ; 29 import java.io.Writer ; 30 import javax.servlet.ServletContext ; 31 import javax.servlet.ServletOutputStream ; 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 35 import org.ofbiz.base.util.GeneralException; 36 import org.ofbiz.base.util.UtilJ2eeCompat; 37 38 45 public class JPublishViewHandler implements ViewHandler { 46 47 public static final String module = JPublishViewHandler.class.getName(); 48 49 protected ServletContext servletContext = null; 50 protected JPublishWrapper wrapper = null; 51 52 55 public void init(ServletContext context) throws ViewHandlerException { 56 this.servletContext = context; 57 this.wrapper = (JPublishWrapper) context.getAttribute("jpublishWrapper"); 58 if (this.wrapper == null) { 59 this.wrapper = new JPublishWrapper(servletContext); 60 } 61 62 if (this.wrapper == null) 64 throw new ViewHandlerException("JPublishWrapper not created"); 65 } 66 67 70 public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { 71 Writer writer = null; 72 try { 73 boolean useOutputStreamNotWriter = false; 75 if (this.servletContext != null) { 76 useOutputStreamNotWriter = UtilJ2eeCompat.useOutputStreamNotWriter(this.servletContext); 77 } 78 if (useOutputStreamNotWriter) { 79 ServletOutputStream ros = response.getOutputStream(); 80 writer = new OutputStreamWriter (ros, "UTF-8"); 81 } else { 82 writer = response.getWriter(); 83 } 84 wrapper.render(page, request, response, writer, null, true); 85 } catch (IOException e) { 86 throw new ViewHandlerException("Problems with the response writer/output stream", e); 87 } catch (GeneralException e) { 88 throw new ViewHandlerException("Cannot render page", e); 89 } 90 } 91 } 92 93 | Popular Tags |