1 16 22 package org.apache.jetspeed.portal.portlets.viewprocessor; 23 24 import org.apache.jetspeed.portal.Portlet; 25 import org.apache.jetspeed.portal.PortletException; 26 import org.apache.jetspeed.portal.portlets.*; 27 import org.apache.jetspeed.portal.portlets.GenericMVCContext; 28 import org.apache.jetspeed.services.TemplateLocator; 29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 30 import org.apache.jetspeed.services.logging.JetspeedLogger; 31 import org.apache.jetspeed.util.JetspeedClearElement; 32 33 import org.apache.turbine.services.velocity.TurbineVelocity; 34 import org.apache.turbine.util.RunData; 35 36 37 41 public class VelocityViewProcessor implements ViewProcessor 42 { 43 44 47 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityViewProcessor.class.getName()); 48 49 50 public VelocityViewProcessor() 51 { 52 } 53 54 public void init(Portlet portlet) 55 throws PortletException 56 { 57 } 58 59 65 public Object processView(GenericMVCContext context) 66 { 67 68 JetspeedClearElement element = null; 70 String template = (String ) context.get("template"); 71 logger.info("VelocityViewProcessor - processing " + template); 72 73 try 74 { 75 76 if (-1 == template.indexOf(".vm")) 77 { 78 template = template + ".vm"; 79 } 80 81 logger.info("VelocityViewProcessor - locating template - " + 82 ((RunData) context.get("data")).toString() + template); 83 84 String templatePath = TemplateLocator.locatePortletTemplate( 85 (RunData) context.get("data"), 86 template); 87 88 Portlet portlet = (Portlet) context.get("portlet"); 90 RunData rundata = (RunData) context.get("data"); 91 long cachePeriod = -1; 92 AbstractPortlet abstractPortlet = null; 93 if(portlet instanceof AbstractPortlet) 95 { 96 abstractPortlet =(AbstractPortlet) portlet; 97 if(abstractPortlet.getExpirationMillis() != null) 98 { 99 cachePeriod = abstractPortlet.getExpirationMillis().longValue(); 100 } 101 } 102 103 if (cachePeriod > 0 && abstractPortlet != null) 104 { 105 String s = TurbineVelocity.handleRequest(context, templatePath); 106 abstractPortlet.setExpirationMillis( 107 cachePeriod + System.currentTimeMillis()); 108 element = new JetspeedClearElement(s); 109 110 } 111 else 112 { 113 TurbineVelocity.handleRequest( 114 context, templatePath, rundata.getOut()); 115 } 116 117 118 } 119 catch (Exception e) 120 { 121 element = new JetspeedClearElement(e.toString()); 122 logger.error("VelocityViewProcessor - had problems handling request - " + e); 123 e.printStackTrace(); 124 } 125 126 TurbineVelocity.requestFinished(context); 127 128 if (element == null) 129 { 130 element = new JetspeedClearElement(""); 131 } 132 133 return element; 134 } 135 } 136 | Popular Tags |