1 16 package org.apache.jetspeed.portal.portlets.viewprocessor; 17 18 import org.apache.ecs.ElementContainer; 20 import org.apache.ecs.StringElement; 21 22 import org.apache.jetspeed.portal.Portlet; 24 import org.apache.jetspeed.portal.portlets.GenericMVCContext; 25 import org.apache.jetspeed.services.TemplateLocator; 26 import org.apache.jetspeed.services.Registry; 27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 28 import org.apache.jetspeed.services.logging.JetspeedLogger; 29 import org.apache.jetspeed.om.registry.PortletEntry; 30 import org.apache.jetspeed.util.ServiceUtil; 31 32 import org.apache.turbine.services.jsp.JspService; 34 35 import org.apache.turbine.util.RunData; 37 38 import java.util.Iterator ; 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.RequestDispatcher ; 42 43 60 public class JSPViewProcessor 61 implements ViewProcessor 62 { 63 64 67 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JSPViewProcessor.class.getName()); 68 69 70 public JSPViewProcessor() 71 { 72 } 73 74 public Object processView(GenericMVCContext context) 75 { 76 77 Portlet portlet = (Portlet) context.get("portlet"); 78 RunData data = (RunData) context.get("data"); 79 HttpServletRequest request = data.getRequest(); 80 String template = (String ) context.get("template"); 81 logger.info("JSPViewProcessor - processing template " + template); 82 83 try 84 { 85 86 request.setAttribute("portlet", portlet); 88 89 request.setAttribute("context", context); 91 92 request.setAttribute("js_peid", portlet.getID()); 94 95 request.setAttribute(JspService.RUNDATA, data); 97 98 PortletEntry pe = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName()); 101 102 if (pe.getURL() == null || pe.getURL().trim().length() == 0) 106 { 107 108 if (template != null && -1 == template.indexOf(".jsp")) 109 { 110 template = template + ".jsp"; 111 } 112 113 logger.info("JSPViewProcessor - locating template - " + data.toString() 114 + " - " + template); 115 116 String locatedTemplate = TemplateLocator.locatePortletTemplate(data, template); 118 logger.info("JSPViewProcessor - located template: " + locatedTemplate); 119 120 129 130 JspService service = (JspService) ServiceUtil.getServiceByName(JspService.SERVICE_NAME); 131 132 service.addDefaultObjects(data); 135 136 service.handleRequest(data, locatedTemplate); 138 139 } 140 else 141 { 142 Iterator names = portlet.getPortletConfig().getInitParameterNames(); 144 while (names.hasNext()) 145 { 146 String name = (String ) names.next(); 147 String value = (String ) portlet.getPortletConfig().getInitParameter(name); 148 data.getParameters().setString(name, value); 149 } 150 151 template = pe.getURL(); 152 153 if (logger.isDebugEnabled()) 154 { 155 logger.debug("JSPViewProcessor - serving jsp directly using: " + template); 156 } 157 158 RequestDispatcher dispatcher = data.getServletContext().getRequestDispatcher(template); 160 data.getOut().flush(); 161 dispatcher.include(data.getRequest(), data.getResponse()); 162 } 163 164 } 165 catch (Exception e) 166 { 167 168 String message = "JSPViewProcessor: Could not include the following JSP Page: [" + template + "] :\n\t" 169 + e.getMessage(); 170 logger.error(message, e); 171 172 return new StringElement(message); 173 } 174 175 return new ElementContainer(); 176 } 177 178 184 public void init(Portlet portlet) 185 { 186 } 187 } 188 | Popular Tags |