1 25 package org.ofbiz.widget.screen; 26 27 import java.io.IOException ; 28 import java.io.OutputStreamWriter ; 29 import java.io.Writer ; 30 31 import javax.servlet.ServletContext ; 32 import javax.servlet.ServletOutputStream ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import javax.xml.parsers.ParserConfigurationException ; 36 37 import org.ofbiz.base.util.GeneralException; 38 import org.ofbiz.base.util.UtilJ2eeCompat; 39 import org.ofbiz.webapp.view.ViewHandler; 40 import org.ofbiz.webapp.view.ViewHandlerException; 41 import org.ofbiz.widget.html.HtmlScreenRenderer; 42 import org.xml.sax.SAXException ; 43 44 51 public class ScreenWidgetViewHandler implements ViewHandler { 52 53 public static final String module = ScreenWidgetViewHandler.class.getName(); 54 55 protected ServletContext servletContext = null; 56 protected HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer(); 57 58 61 public void init(ServletContext context) throws ViewHandlerException { 62 this.servletContext = context; 63 } 64 65 68 public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { 69 Writer writer = null; 70 try { 71 boolean useOutputStreamNotWriter = false; 73 if (this.servletContext != null) { 74 useOutputStreamNotWriter = UtilJ2eeCompat.useOutputStreamNotWriter(this.servletContext); 75 } 76 if (useOutputStreamNotWriter) { 77 ServletOutputStream ros = response.getOutputStream(); 78 writer = new OutputStreamWriter (ros, "UTF-8"); 79 } else { 80 writer = response.getWriter(); 81 } 82 83 ScreenRenderer screens = new ScreenRenderer(writer, null, htmlScreenRenderer); 84 screens.populateContextForRequest(request, response, servletContext); 85 screens.render(page); 86 } catch (IOException e) { 87 throw new ViewHandlerException("Error in the response writer/output stream: " + e.toString(), e); 88 } catch (SAXException e) { 89 throw new ViewHandlerException("XML Error rendering page: " + e.toString(), e); 90 } catch (ParserConfigurationException e) { 91 throw new ViewHandlerException("XML Error rendering page: " + e.toString(), e); 92 } catch (GeneralException e) { 93 throw new ViewHandlerException("Lower level error rendering page: " + e.toString(), e); 94 } 95 } 96 } 97 | Popular Tags |