Index: src/java/org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java,v retrieving revision 1.3 diff -u -r1.3 GenericMVCPortlet.java --- src/java/org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java 19 Jun 2003 17:12:18 -0000 1.3 +++ src/java/org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java 14 Jul 2003 19:01:08 -0000 @@ -68,9 +68,10 @@ // using the * form due to the puggable nature //ie no recompile to support new view processors import org.apache.jetspeed.util.PortletSessionState; + import org.apache.jetspeed.util.template.JetspeedLink; import org.apache.jetspeed.util.template.JetspeedTemplateLink; - +import org.apache.jetspeed.portal.PortletConfig; import org.apache.turbine.modules.ActionLoader; import org.apache.turbine.services.pull.TurbinePull; import org.apache.turbine.util.Log; @@ -82,14 +83,14 @@ * the views via a ViewProcessor, which is a pluggable, factory * created, run time module for which ever view technology your portlet * uses. - * + * * There is no need to extend this portlet class, just define your porlet * entry in the registy as a child of this class and provide your template * and action class (extened from GenericMVCAction of course) and you * are good to go. - * + * * Example .xreg entry: - * + * * - * + * * See the Velocity and JSP MVC Portlet examples for template and action class clues. - * + * * To add new view processor types, simply implement the ViewProcessor * interface and add your type into the viewprocessor.properties file as * shown in the example below: - * + * * mvc.viewprocessor.Velocity = org.apache.jetspeedportlets.viewprocessors.VelocityViewProcessor * mvc.viewprocessor.JSP = org.apache.jetspeedportlets.viewprocessors.JSPViewProcessor * mvc.viewprocessor.XSL = org.apache.jetspeedportlets.viewprocessors.XSLViewProcessor - * + * * @stereotype role * @author tkuebler * @author Scott T. Weaver @@ -137,167 +138,201 @@ public static final String RUNDATA = "data"; public static final String PORTLET_CONFIG = "conf"; public static final String SKIN = "skin"; - public static final String VIEW_TYPE = "viewType"; - public static final String IS_CACHEABLE = "_IsCacheable"; - - // need cache timer, etc - private String viewType = "ERROR: not set in config"; + public static final String VIEW_TYPE = "viewType"; + public static final String IS_CACHEABLE = "_IsCacheable"; + + /** How long in milliseconds will the content of this portlet be cached. + * The default is zero - never cache the content. + * This is specified in the portlet config parameter "cache-period-milliseconds" **/ + private long cachePeriod = 0; + private long cacheExpire = 0; + /** What view technology is being used? maps to the view processor */ + private String viewType = null; + /** what action is associated with this portlet entry by default */ private String actionName = "ERROR: not set in config"; private String template = "ERROR: not set in config"; private String configureTemplate; private String maximizedTemplate; private ViewProcessor processor = null; private boolean providesCustomization; - - public void init() throws PortletException + + public void init () throws PortletException { - //STW: check custimization attribute - String provConf = getPortletConfig().getInitParameter("provides.customization", "false"); - providesCustomization = new Boolean(provConf).booleanValue(); - - // pull the important info out of the portlet config - actionName = getPortletConfig().getInitParameter("action"); - // STW: Allow subclasses to set viewtype for backward compatibillity - if (getPortletConfig().getInitParameter("viewtype") != null) + PortletConfig config = this.getPortletConfig (); + + // deal with caching and other config stuff + // TODO: should check with master portlet config and override with default if + // psml entry for a attribute is found to be blank + + try + { + cachePeriod = Long.parseLong ( config.getInitParameter ("cache-period-milliseconds","0") ); // 0 seconds is default - not cached -tk + Log.debug ("GenericMVCPortlet - cachePeriod set to " + cachePeriod); + } + catch (NumberFormatException e) { - viewType = getPortletConfig().getInitParameter("viewtype"); + Log.error ("GenericMVCPortlet - Number format exception getting cachePeriod from config - setting to 0"); + cachePeriod = 0; + } + + try + { + String provConf = config.getInitParameter ("provides.customization", "false"); + providesCustomization = new Boolean (provConf).booleanValue (); + actionName = config.getInitParameter ("action",actionName); + // Allow subclasses to set viewtype for backward compatibillity + if (config.getInitParameter ("viewtype") != null && viewType == null) + { + viewType = config.getInitParameter ("viewtype","Velocity"); + } + template = config.getInitParameter ("template",template); + } + catch ( Exception e ) + { + Log.error ("GenericMVCPortlet - error setting config items"); } - - template = getPortletConfig().getInitParameter("template"); - // get viewprocessor from factory - Log.info( + if (Log.getLogger ().isDebugEnabled ()) + { + Log.debug ( "GenericMVCPortlet - creating view processor for viewtype = " - + viewType - + ", template = " - + template); - processor = ViewProcessorFactory.getViewProcessor(viewType); - + + viewType + + ", template = " + + template);} + + processor = ViewProcessorFactory.getViewProcessor (viewType); + // initialize view processor with portlet info - processor.init(this); - - // should make this config file driven - // STW removed this so subclasses can decide this for - // themselves. - // setCacheable(false); + processor.init (this); + Log.info ("GenericMVCPortlet initialized as " + this.getName ()); } - + /** - * By default MVCPortlets are cacheable. This can be overriden by specifying - * "_IsCacheable" parameter. - * - * @return + * Whether or not this portlet provides it's own customizer. + * This can be set at the registry level by adding a + * boolean paramter "provides.customization" + * Defaults to "false" */ - public boolean isCacheable() - { - return getPortletConfig().getInitParameter(IS_CACHEABLE, "true").equalsIgnoreCase("true"); - } - -/** - * Whether or not this portlet provides it's own customizer. - * This can be set at the registry level by adding a - * boolean paramter "provides.customization" - * Defaults to "false" - */ - public boolean providesCustomization() + public boolean providesCustomization () { - return providesCustomization; + //return providesCustomization; + return true; } - - public ConcreteElement getContent(RunData rundata) + + public ConcreteElement getContent (RunData rundata) { - + //if caching is turned off or no expiration time set, generate and return the content - if (!isCacheable() || null == getExpirationMillis()) + if ( cachePeriod == 0 || cacheExpire == 0 ) { - return buildContent(rundata); + if (Log.getLogger ().isDebugEnabled ()) + { + Log.debug ("GenericMVCPortlet:getContent - caching is off or expire not set - building content"); + } + return buildContent (rundata); + // if caching is turned on and expiration set } - - //is the cached content still valid, if not, generate and return the content - if (getExpirationMillis().longValue() <= System.currentTimeMillis()) + else { - return buildContent(rundata); + // if expiration has occured build the content + if ( System.currentTimeMillis () >= cacheExpire ) + { + if (Log.getLogger ().isDebugEnabled ()) + { + Log.debug ("GenericMVCPortlet:getContent - cache is out of date - building content"); + } + return buildContent (rundata); + } + else + { + //else, the cached content is fine to be returned + if (Log.getLogger ().isDebugEnabled ()) + { + Log.debug ("GenericMVCPortlet:getContent - cache is ok - returning cached content"); + } + return getContent (rundata, null, true); + } } - - //else, the cached content is fine to be returned - return getContent(rundata, null, true); - } - - protected ConcreteElement buildContent(RunData rundata) + + protected ConcreteElement buildContent (RunData rundata) { // create a new context // populate it with data - GenericMVCContext context = new GenericMVCContext(TurbinePull.getGlobalContext()); - context.put(RUNDATA, rundata); - context.put(PORTLET, this); - context.put(PORTLET_CONFIG, this.getPortletConfig()); - context.put(SKIN, this.getPortletConfig().getPortletSkin()); - context.put(TEMPLATE, getCurrentTemplate(rundata)); - context.put(VIEW_TYPE, viewType); - populateRequest(rundata); - + GenericMVCContext context = new GenericMVCContext (TurbinePull.getGlobalContext ()); + context.put (RUNDATA, rundata); + context.put (PORTLET, this); + context.put (PORTLET_CONFIG, this.getPortletConfig ()); + context.put (SKIN, this.getPortletConfig ().getPortletSkin ()); + context.put (TEMPLATE, getCurrentTemplate (rundata)); + context.put (VIEW_TYPE, viewType); + populateRequest (rundata); + // put references to the pull tools in the context - TurbinePull.populateContext(context, rundata); + TurbinePull.populateContext (context, rundata); // Initialize jlink and jslink tools with ourselves // to enable links between portlets - Object jlink = context.get("jlink"); - + Object jlink = context.get ("jlink"); + if (jlink instanceof JetspeedTemplateLink) { - ((JetspeedTemplateLink) jlink).setPortlet(this); + ((JetspeedTemplateLink) jlink).setPortlet (this); } - - Object jslink = context.get("jslink"); - + + Object jslink = context.get ("jslink"); + if (jslink instanceof JetspeedLink) { - ((JetspeedLink) jslink).setPortlet(this); + ((JetspeedLink) jslink).setPortlet (this); } - + // Handle Action if (actionName != null) - { - + { try - { - + { // store the context so that the action can retrieve it - //Log.debug("VelocityPortlet found action "+actionName+" context "+context); // note: the name it is stored under is legacy, leaving it this way // because some of the routines fall back to old default behavior // of the velocity portlet and might depend on the name - rundata.getTemplateInfo().setTemplateContext("VelocityPortletContext", context); - - if (Log.getLogger().isDebugEnabled()) + // It is actually a GenericMVCContext + rundata.getTemplateInfo ().setTemplateContext ("VelocityPortletContext", context); + + if (Log.getLogger ().isDebugEnabled ()) { - Log.debug( - "GenericMVCPortlet: Executing action [" - + actionName - + "] for portlet [" - + this.getName() - + "]"); + Log.debug ( + "GenericMVCPortlet: Executing action [" + + actionName + + "] for portlet [" + + this.getName () + + "]"); } - - ActionLoader.getInstance().exec(rundata, actionName); + + ActionLoader.getInstance ().exec (rundata, actionName); } catch (Exception e) { - Log.error("GenericMVCPortlet - error executing action" + e); - e.printStackTrace(); + Log.error ("GenericMVCPortlet - error executing action" + e); + e.printStackTrace (); } } - + // Process View - // call processView method - Log.info("GenericMVCPortlet - calling processView on processor"); - - ConcreteElement result = (ConcreteElement) processor.processView(context); - Log.info("GenericMVCPortlet - setting this portlet's content"); - clearContent(); - setContent(result); // only needed when caching is true I believe + if (Log.getLogger ().isDebugEnabled ()) + { + Log.debug ("GenericMVCPortlet - calling processView on processor"); + } + ConcreteElement result = (ConcreteElement) processor.processView (context); + clearContent (); + setContent (result); + + if ( cachePeriod != 0 ) + { + cacheExpire = System.currentTimeMillis () + cachePeriod; + } + // return result return result; } @@ -305,22 +340,22 @@ * @see setViewType() * @return String */ - protected String getViewType() + protected String getViewType () { return viewType; } - + /** - * STW: Added for backward compatibility when using this + * STW: Added for backward compatibility when using this * class to subclass the existing Jsp and Velocity portlets * so they can set their view prior to super.init(); * @param viewType The viewType to set */ - protected void setViewType(String viewType) + protected void setViewType (String viewType) { this.viewType = viewType; } - + /** * This is called before any action execution happens. * This provides backward compatibility to JspPortletActions @@ -329,28 +364,28 @@ * which normally populates the request with Context objects. * @author Scott Weaver */ - protected void populateRequest(RunData rundata) + protected void populateRequest (RunData rundata) { - HttpServletRequest request = rundata.getRequest(); - request.setAttribute("data", rundata); - request.setAttribute("portlet", this); - request.setAttribute("conf", this.getPortletConfig()); - request.setAttribute("skin", this.getPortletConfig().getPortletSkin()); - request.setAttribute("template", getCurrentTemplate(rundata)); - request.setAttribute("viewType", viewType); + HttpServletRequest request = rundata.getRequest (); + request.setAttribute ("data", rundata); + request.setAttribute ("portlet", this); + request.setAttribute ("conf", this.getPortletConfig ()); + request.setAttribute ("skin", this.getPortletConfig ().getPortletSkin ()); + request.setAttribute ("template", getCurrentTemplate (rundata)); + request.setAttribute ("viewType", viewType); } /** - * + * */ - protected String getCurrentTemplate( RunData data) + protected String getCurrentTemplate ( RunData data) { - String useTemplate = (String) PortletSessionState.getAttribute(this, data, TEMPLATE); - if(useTemplate == null) - { - useTemplate = this.template; - } - - return useTemplate; + String useTemplate = (String) PortletSessionState.getAttribute (this, data, TEMPLATE); + if(useTemplate == null) + { + useTemplate = this.template; + } + + return useTemplate; } } Index: src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java,v retrieving revision 1.9 diff -u -r1.9 JspPortlet.java --- src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java 20 Mar 2003 18:11:50 -0000 1.9 +++ src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java 14 Jul 2003 19:01:08 -0000 @@ -59,7 +59,7 @@ /** * A JSP portlet example. - * + * * STW: Changed to subclass the GenericMVCPortlet to help * unify the handling of all template based portlets. * @author David Sean Taylor @@ -68,20 +68,19 @@ */ public class JspPortlet extends GenericMVCPortlet { - + public static final String TEMPLATE = "template"; - + /** - * STW: Backward compatibility: set the viewType to "JSP". - * By default the data is non cacheable - */ - public void init() throws PortletException + * STW: Backward compatibility: set the viewType to "JSP". + * the data is non cacheable due to the processor writing + * directly to the output stream + */ + public void init () throws PortletException { - setCacheable(false); - setViewType("JSP"); - super.init(); - + setViewType ("JSP"); + super.init (); } - - + + } Index: src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java,v retrieving revision 1.22 diff -u -r1.22 VelocityPortlet.java --- src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java 20 Mar 2003 18:11:50 -0000 1.22 +++ src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java 14 Jul 2003 19:01:08 -0000 @@ -61,10 +61,10 @@ /** * A Velocity based portlet implementation - *

- * NOTE:This supports the pre-MVC style of template + *

+ * NOTE:This supports the pre-MVC style of template * based portlet development and is supplied for backward compatibility. - * The prefered method is to define template-based portlets is to use + * The prefered method is to define template-based portlets is to use * @see org.apache.jetspeed.portal.portlets.GenericMVCPortlet * or a sub-class there of. The GenericMVCPortlet javadoc provides * instructions for using using the MVC portlet model. @@ -77,17 +77,16 @@ public class VelocityPortlet extends GenericMVCPortlet { - /** - * STW: Backward compatibility: set the viewType to "Velocity". - */ - public void init() throws PortletException + /** + * STW: Backward compatibility: set the viewType to "Velocity". + */ + public void init () throws PortletException { - setCacheable(true); - setViewType("Velocity"); - super.init(); + setViewType ("Velocity"); + super.init (); } - - - + + + } Index: src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java,v retrieving revision 1.10 diff -u -r1.10 XSLPortlet.java --- src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java 2 May 2003 22:38:13 -0000 1.10 +++ src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java 14 Jul 2003 19:01:08 -0000 @@ -60,22 +60,20 @@ /** * Simple portlet which does a basic XSLT transform with the stylesheet parameter * and the given portlet URL. - * + * * @author Raphaël Luta * @version $Id: XSLPortlet.java,v 1.10 2003/05/02 22:38:13 morciuch Exp $ */ -public class XSLPortlet extends GenericMVCPortlet +public class XSLPortlet extends GenericMVCPortlet { - /** - * + * * @exception PortletException */ - public void init() throws PortletException + public void init () throws PortletException { - setCacheable(true); - setViewType("XSL"); - super.init(); + setViewType ("XSL"); + super.init (); } - + } Index: src/java/org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java,v retrieving revision 1.3 diff -u -r1.3 JSPViewProcessor.java --- src/java/org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java 25 Apr 2003 23:10:51 -0000 1.3 +++ src/java/org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java 14 Jul 2003 19:01:08 -0000 @@ -82,14 +82,14 @@ * JspViewProcessor - MVC processor for serving jsp files. *

* The .jsp file location may be specified in two different ways: - *

  • using the "template" parameter - the JspTemplateService will search portlets and then screens - * folder to locate the appropriate template. The template must be specifed in the "template" + *
  • using the "template" parameter - the JspTemplateService will search portlets and then screens + * folder to locate the appropriate template. The template must be specifed in the "template" * portlet parameter. - *
  • using relative url - the .jsp template will be served directly bypassing the - * JspTemplateService. The template must be specifed in the portlet url property. + *
  • using relative url - the .jsp template will be served directly bypassing the + * JspTemplateService. The template must be specifed in the portlet url property. * Example: /html/welcome.jsp. *

    - * + * * @author Tod Kuebler * @author Scott Weaver * @author Mark Orciuch @@ -98,58 +98,53 @@ public class JSPViewProcessor implements ViewProcessor { - - /** Creates a new instance of JSPViewProcessor */ - public JSPViewProcessor() + + Portlet portlet = null; + + public Object processView (GenericMVCContext context) { - } - - public Object processView(GenericMVCContext context) - { - - Portlet portlet = (Portlet) context.get("portlet"); - RunData data = (RunData) context.get("data"); - HttpServletRequest request = data.getRequest(); - String template = (String) context.get("template"); - Log.info("JSPViewProcessor - processing template " + template); - + + portlet = (Portlet) context.get ("portlet"); // already have portlet if init called, maybe remove? + RunData data = (RunData) context.get ("data"); + HttpServletRequest request = data.getRequest (); + String template = (String) context.get ("template"); + Log.debug ("JSPViewProcessor - processing template " + template); + try - { - + { // Allow access to portlet from .jsp template - request.setAttribute("portlet", portlet); - + request.setAttribute ("portlet", portlet); + // put context in attribute so you can get to it from .jsp template - request.setAttribute("context", context); - + request.setAttribute ("context", context); + // Add js_peid out of convenience - request.setAttribute("js_peid", portlet.getID()); - + request.setAttribute ("js_peid", portlet.getID ()); + // Add rundata out of convenience (JspService.RUNDATA differs from GenericMVCPortlet.RUNDATA) - request.setAttribute(JspService.RUNDATA, data); - - // Retrieve the URL. For backward compatibility, use the URL first + request.setAttribute (JspService.RUNDATA, data); + + // Retrieve the URL. For backward compatibility, use the URL first // and then fallback to "template" parameter - PortletEntry pe = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName()); - + PortletEntry pe = (PortletEntry) Registry.getEntry (Registry.PORTLET, portlet.getName ()); + // Files referenced from default templates folder will be processed // using JspService. Otherwise, they will be loaded using EcsServletElement // from where ever they came from. - if (pe.getURL() == null || pe.getURL().trim().length() == 0) + if (pe.getURL () == null || pe.getURL ().trim ().length () == 0) { - - if (template != null && -1 == template.indexOf(".jsp")) + if (template != null && -1 == template.indexOf (".jsp")) { template = template + ".jsp"; } - - Log.info("JSPViewProcessor - locating template - " + data.toString() - + " - " + template); - + + Log.debug ("JSPViewProcessor - locating template - " + data.toString () + + " - " + template); + //we use the template locator to translate the template - String locatedTemplate = TemplateLocator.locatePortletTemplate(data, template); - Log.info("JSPViewProcessor - located template: " + locatedTemplate); - + String locatedTemplate = TemplateLocator.locatePortletTemplate (data, template); + Log.debug ("JSPViewProcessor - located template: " + locatedTemplate); + /*if (locatedTemplate == null) { locatedTemplate = TemplateLocator.locateScreenTemplate(data, template); @@ -159,62 +154,63 @@ } Log.debug("JSPViewProcessor - located screen template: " + locatedTemplate); } */ - - JspService service = (JspService) ServiceUtil.getServiceByName(JspService.SERVICE_NAME); - + + JspService service = (JspService) ServiceUtil.getServiceByName (JspService.SERVICE_NAME); + // this is only necessary if we don't run in a JSP page environment // but better be safe than sorry... - service.addDefaultObjects(data); - + service.addDefaultObjects (data); + // handle request - service.handleRequest(data, locatedTemplate); - + service.handleRequest (data, locatedTemplate); + } else { // Build parameter list to be passed with the jsp - Iterator names = portlet.getPortletConfig().getInitParameterNames(); - while (names.hasNext()) + Iterator names = portlet.getPortletConfig ().getInitParameterNames (); + while (names.hasNext ()) { - String name = (String) names.next(); - String value = (String) portlet.getPortletConfig().getInitParameter(name); - data.getParameters().setString(name, value); + String name = (String) names.next (); + String value = (String) portlet.getPortletConfig ().getInitParameter (name); + data.getParameters ().setString (name, value); } - - template = pe.getURL(); - - if (Log.getLogger().isDebugEnabled()) + + template = pe.getURL (); + + if (Log.getLogger ().isDebugEnabled ()) { - Log.debug("JSPViewProcessor - serving jsp directly using: " + template); + Log.debug ("JSPViewProcessor - serving jsp directly using: " + template); } - + // get the RequestDispatcher for the JSP - RequestDispatcher dispatcher = data.getServletContext().getRequestDispatcher(template); - data.getOut().flush(); - dispatcher.include(data.getRequest(), data.getResponse()); + RequestDispatcher dispatcher = data.getServletContext ().getRequestDispatcher (template); + data.getOut ().flush (); + dispatcher.include (data.getRequest (), data.getResponse ()); } - + } catch (Exception e) { - - String message = "JSPViewProcessor: Could not include the following JSP Page: [" + template + "] :\n\t" - + e.getMessage(); - Log.error(message, e); - - return new StringElement(message); + + String message = "JSPViewProcessor: Could not include the following JSP Page: [" + template + "] :\n\t" + + e.getMessage (); + Log.error (message, e); + + return new StringElement (message); } - - return new ElementContainer(); + + return new ElementContainer (); } - + /** Process the template passed in the context * (context.get("template")). Invoked by the GenericMVCPortlet * after action handling to process the template type * in question. * */ - public void init(Portlet portlet) + public void init (Portlet portlet) { + this.portlet = portlet; } } Index: src/java/org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java,v retrieving revision 1.2 diff -u -r1.2 VelocityViewProcessor.java --- src/java/org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java 24 Mar 2003 01:17:41 -0000 1.2 +++ src/java/org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java 14 Jul 2003 19:01:08 -0000 @@ -77,93 +77,68 @@ * @author tkuebler */ public class VelocityViewProcessor - implements ViewProcessor - { - - /** Creates a new instance of VelocityViewProcessor */ - public VelocityViewProcessor() - { - } - - public void init(Portlet portlet) - throws PortletException - { - } - +implements ViewProcessor +{ + + Portlet portlet = null; + + public void init (Portlet portlet) + throws PortletException + { + this.portlet = portlet; + } + /** Process the template passed in the context * (context.get("template")). Invoked by the GenericMVCPortlet * after action handling to process the template type * in question. * */ - public Object processView(GenericMVCContext context) - { - + public Object processView (GenericMVCContext context) + { + // generate the content JetspeedClearElement element = null; - String template = (String) context.get("template"); - Log.info("VelocityViewProcessor - processing " + template); - + String template = (String) context.get ("template"); + + Log.debug ("VelocityViewProcessor - processing " + template); + try - { - - if (-1 == template.indexOf(".vm")) - { - template = template + ".vm"; - } - - Log.info("VelocityViewProcessor - locating template - " + - ((RunData) context.get("data")).toString() + template); - - String templatePath = TemplateLocator.locatePortletTemplate( - (RunData) context.get("data"), - template); - - // need to add cache support - Portlet portlet = (Portlet) context.get("portlet"); - RunData rundata = (RunData) context.get("data"); - long cachePeriod = -1; - AbstractPortlet abstractPortlet = null; - // STW: Safety net ;) - if(portlet instanceof AbstractPortlet) + { + + if (-1 == template.indexOf (".vm")) { - abstractPortlet =(AbstractPortlet) portlet; - if(abstractPortlet.getExpirationMillis() != null) - { - cachePeriod = abstractPortlet.getExpirationMillis().longValue(); - } + template = template + ".vm"; } - - if (cachePeriod > 0 && abstractPortlet != null) - { - String s = TurbineVelocity.handleRequest(context, templatePath); - abstractPortlet.setExpirationMillis( - cachePeriod + System.currentTimeMillis()); - element = new JetspeedClearElement(s); - - } - else - { - TurbineVelocity.handleRequest( - context, templatePath, rundata.getOut()); - } + Log.debug ("VelocityViewProcessor - locating template - " + + ((RunData) context.get ("data")).toString () + template); + + String templatePath = TemplateLocator.locatePortletTemplate ( + (RunData) context.get ("data"), + template); + + Portlet portlet = (Portlet) context.get ("portlet"); + RunData rundata = (RunData) context.get ("data"); + + element = new JetspeedClearElement (TurbineVelocity.handleRequest (context, templatePath)); - } + } catch (Exception e) - { - element = new JetspeedClearElement(e.toString()); - Log.error("VelocityViewProcessor - had problems handling request - " + e); - e.printStackTrace(); - } - - TurbineVelocity.requestFinished(context); - + { + element = new JetspeedClearElement (e.toString ()); + Log.error ("VelocityViewProcessor - had problems handling request - " + e); + e.printStackTrace (); + } + + TurbineVelocity.requestFinished (context); + + // catch the null pointer case and return something kosher if (element == null) - { - element = new JetspeedClearElement(""); - } - + { + element = new JetspeedClearElement ("portlet content n/a - check log for errors"); + } + return element; - } - } + } +} Index: src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java =================================================================== RCS file: /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java,v retrieving revision 1.2 diff -u -r1.2 XSLViewProcessor.java --- src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java 2 May 2003 22:38:13 -0000 1.2 +++ src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java 14 Jul 2003 19:01:08 -0000 @@ -95,204 +95,187 @@ /** * Simple ViewProcessor which does a basic XSLT transform with the stylesheet parameter * and the given URL. - * + * * @author tkuebler@cisco.com * @version $Id: $ * @since 1.4b4 */ public class XSLViewProcessor implements ViewProcessor -{ - +{ private static final String XMLDECL = " -1) + + if ((idx = name.indexOf (".")) > -1) { - base = name.substring(idx + 1, name.length()); + base = name.substring (idx + 1, name.length ()); } - - stylesheets.put(base, portlet.getPortletConfig().getInitParameter(name)); + + stylesheets.put (base, portlet.getPortletConfig ().getInitParameter (name)); } else { - params.put(name.toLowerCase(), portlet.getPortletConfig().getInitParameter(name)); + params.put (name.toLowerCase (), portlet.getPortletConfig ().getInitParameter (name)); } } - + // read content, clean it, parse it and cache the DOM try { - - final DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance(); - + final DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance (); + //Have it non-validating - docfactory.setValidating(false); - parser = docfactory.newDocumentBuilder(); - parser.setEntityResolver(new JetspeedXMLEntityResolver()); - url = portlet.getPortletConfig().getURL(); - - String content = JetspeedDiskCache.getInstance().getEntry(url).getData(); - CapabilityMap xmap = CapabilityMapFactory.getCapabilityMap(CapabilityMapFactory.AGENT_XML); - - // no cache yet // portlet.setContent( new JetspeedClearElement(content), xmap ); - InputSource isrc = new InputSource(this.cleanse(content)); - isrc.setSystemId(url); - isrc.setEncoding("UTF-8"); - this.document = parser.parse(isrc); + docfactory.setValidating (false); + parser = docfactory.newDocumentBuilder (); + parser.setEntityResolver (new JetspeedXMLEntityResolver ()); + url = portlet.getPortletConfig ().getURL (); + + String content = JetspeedDiskCache.getInstance ().getEntry (url).getData (); + CapabilityMap xmap = CapabilityMapFactory.getCapabilityMap (CapabilityMapFactory.AGENT_XML); + + InputSource isrc = new InputSource (this.cleanse (content)); + isrc.setSystemId (url); + isrc.setEncoding ("UTF-8"); + this.document = parser.parse (isrc); } catch (Throwable t) { - String message = "XSLViewProcessor: Couldn't parse out XML document -> " + url; - Log.error(message, t); - throw new PortletException(t.getMessage()); + Log.error (message, t); + throw new PortletException (t.getMessage ()); } - + } - + /** * This methods outputs the content of the portlet for a given * request. - * + * * @param context * @return the content to be displayed to the user-agent */ - public Object processView(GenericMVCContext context) + public Object processView (GenericMVCContext context) { - + try { - init((Portlet) context.get("portlet")); + init ((Portlet) context.get ("portlet")); } catch (PortletException pe) { - pe.printStackTrace(); - Log.error("XSLViewProcessor - error: " + pe); + pe.printStackTrace (); + Log.error ("XSLViewProcessor - error: " + pe); } - - RunData data = (RunData) context.get("data"); - CapabilityMap map = ((JetspeedRunData) data).getCapability(); - String type = map.getPreferredType().toString(); - ConcreteElement content = new JetspeedClearElement(INVALID_TYPE); - String stylesheet = (String) stylesheets.get(type); - + + RunData data = (RunData) context.get ("data"); + CapabilityMap map = ((JetspeedRunData) data).getCapability (); + String type = map.getPreferredType ().toString (); + ConcreteElement content = new JetspeedClearElement (INVALID_TYPE); + String stylesheet = (String) stylesheets.get (type); + if (stylesheet != null) { - try { - content = new JetspeedClearElement(SimpleTransform.transform(this.document, stylesheet, this.params)); - - // no caching yet // setContent( content, map ); + content = new JetspeedClearElement (SimpleTransform.transform (this.document, stylesheet, this.params)); } catch (SAXException e) { - Log.error(e); - content = new JetspeedClearElement(e.getMessage()); + Log.error (e); + content = new JetspeedClearElement (e.getMessage ()); } } else { - content = new JetspeedClearElement("stylesheet not defined"); + content = new JetspeedClearElement ("stylesheet not defined"); } - return content; } - + /** * This portlet supports has many types as those * it has stylesheets defined for in its parameters - * + * * @param mimeType the MIME type queried * @return true if the portlet knows how to display * content for mimeType * @see Portlet#supportsType */ - public boolean supportsType(MimeType mimeType) + public boolean supportsType (MimeType mimeType) { - - Enumeration en = stylesheets.keys(); - - while (en.hasMoreElements()) - { - - String type = (String) en.nextElement(); - - if (type.equals(mimeType.toString())) + Enumeration en = stylesheets.keys (); + + while (en.hasMoreElements ()) + { + String type = (String) en.nextElement (); + + if (type.equals (mimeType.toString ())) { - return true; } } - + return false; } - + /** * Utility method for traversing the document parsed * DOM tree and retrieving a Node by tagname - * + * * @param start the parent node for the search * @param name the tag name to be searched for * @return the first child node of start whose tagname * is name */ - protected Node getNode(Node start, String name) - { - - NodeList list = start.getChildNodes(); - - for (int i = 0; i < list.getLength(); ++i) - { - - Node node = list.item(i); - - if (node.getNodeName().equals(name)) - { - + protected Node getNode (Node start, String name) + { + NodeList list = start.getChildNodes (); + + for (int i = 0; i < list.getLength (); ++i) + { + Node node = list.item (i); + + if (node.getNodeName ().equals (name)) + { return node; } } - + return null; } - + /** * Given a URL to some content, clean the content to Xerces can handle it * better. Right now this involves: @@ -301,29 +284,29 @@ * If the document doesn't begin with "<?xml version=" truncate the * content until this is the first line *

  • - * + * * - * + * * @param content - * @return + * @return * @exception IOException */ - protected Reader cleanse(String content) + protected Reader cleanse (String content) throws IOException { - + String filtered = null; - int start = content.indexOf(XMLDECL); - + int start = content.indexOf (XMLDECL); + if (start <= 0) { filtered = content; } else { - filtered = content.substring(start, content.length()); + filtered = content.substring (start, content.length ()); } - - return new StringReader(filtered); + + return new StringReader (filtered); } }