Index: org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java,v retrieving revision 1.4 diff -u -r1.4 GenericMVCPortlet.java --- org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java 23 Jul 2003 19:50:17 -0000 1.4 +++ org/apache/jetspeed/portal/portlets/GenericMVCPortlet.java 25 Jul 2003 16:08:45 -0000 @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -62,23 +62,19 @@ import org.apache.ecs.ConcreteElement; -import org.apache.jetspeed.portal.Portlet; import org.apache.jetspeed.portal.PortletException; -import org.apache.jetspeed.portal.portlets.viewprocessor.ViewProcessor; -import org.apache.jetspeed.portal.portlets.viewprocessor.ViewProcessorFactory; -//import org.apache.jetspeed.portal.portlets.viewprocessor.*; +import org.apache.jetspeed.portal.portlets.viewprocessor.*; // using the * form due to the puggable nature //ie no recompile to support new view processors -// The above * form removed. No need, as imports are only used at compile time -// Pluggable will work fine anyway. (HO) -import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; -import org.apache.jetspeed.services.logging.JetspeedLogger; 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.jetspeed.services.logging.JetspeedLogFactoryService; +import org.apache.jetspeed.services.logging.JetspeedLogger; import org.apache.turbine.util.RunData; /** @@ -87,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 @@ -136,106 +132,136 @@ */ public class GenericMVCPortlet extends AbstractInstancePortlet { - /** * Static initialization of the logger for this class */ private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(GenericMVCPortlet.class.getName()); - + // STW: Context keys public static final String PORTLET = "portlet"; public static final String TEMPLATE = "template"; 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"; - private String actionName = "ERROR: not set in config"; - private String template = "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 = null; + private String template = null; private String configureTemplate; private String maximizedTemplate; private ViewProcessor processor = null; private boolean providesCustomization; - + 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 { - viewType = getPortletConfig().getInitParameter("viewtype"); + cachePeriod = Long.parseLong(config.getInitParameter("cache-period-milliseconds", "0") ); // 0 seconds is default - not cached -tk + logger.debug("cachePeriod set to " + cachePeriod); + } + catch (NumberFormatException e) + { + logger.error("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 ) + { + logger.error("Error setting config items", e); } - - template = getPortletConfig().getInitParameter("template"); - // get viewprocessor from factory - logger.info( - "GenericMVCPortlet - creating view processor for viewtype = " - + viewType - + ", template = " - + template); + if (logger.isDebugEnabled()) + { + logger.debug( + "Creating view processor for 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); + logger.info("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() { - return providesCustomization; + //return providesCustomization; + return true; } - + 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 ) { + if (logger.isDebugEnabled()) + { + logger.debug("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 (logger.isDebugEnabled()) + { + logger.debug("getContent - cache is out of date - building content"); + } + return buildContent(rundata); + } + else + { + //else, the cached content is fine to be returned + if (logger.isDebugEnabled()) + { + logger.debug("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) { // create a new context @@ -248,66 +274,70 @@ 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); // Initialize jlink and jslink tools with ourselves // to enable links between portlets Object jlink = context.get("jlink"); - + if (jlink instanceof JetspeedTemplateLink) { ((JetspeedTemplateLink) jlink).setPortlet(this); } - + Object jslink = context.get("jslink"); - + if (jslink instanceof JetspeedLink) { ((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 + // It is actually a GenericMVCContext rundata.getTemplateInfo().setTemplateContext("VelocityPortletContext", context); - + if (logger.isDebugEnabled()) { logger.debug( - "GenericMVCPortlet: Executing action [" - + actionName - + "] for portlet [" - + this.getName() - + "]"); + "GenericMVCPortlet: Executing action [" + + actionName + + "] for portlet [" + + this.getName() + + "]"); } - + ActionLoader.getInstance().exec(rundata, actionName); } catch (Exception e) { - logger.error("GenericMVCPortlet - error executing action", e); + logger.error("Error executing action" + e); } } - + // Process View - // call processView method - logger.info("GenericMVCPortlet - calling processView on processor"); - + if (logger.isDebugEnabled()) + { + logger.debug("Calling processView on processor"); + } ConcreteElement result = (ConcreteElement) processor.processView(context); - logger.info("GenericMVCPortlet - setting this portlet's content"); + clearContent(); - setContent(result); // only needed when caching is true I believe - + setContent(result); + + if ( cachePeriod != 0 ) + { + cacheExpire = System.currentTimeMillis() + cachePeriod; + } + // return result return result; } @@ -319,9 +349,9 @@ { 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 @@ -330,7 +360,7 @@ { this.viewType = viewType; } - + /** * This is called before any action execution happens. * This provides backward compatibility to JspPortletActions @@ -351,16 +381,16 @@ } /** - * + * */ 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: org/apache/jetspeed/portal/portlets/JspPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/JspPortlet.java,v retrieving revision 1.9 diff -u -r1.9 JspPortlet.java --- org/apache/jetspeed/portal/portlets/JspPortlet.java 20 Mar 2003 18:11:50 -0000 1.9 +++ org/apache/jetspeed/portal/portlets/JspPortlet.java 25 Jul 2003 16:08:45 -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 - */ + * 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(); - } - - + + } Index: org/apache/jetspeed/portal/portlets/VelocityPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/VelocityPortlet.java,v retrieving revision 1.22 diff -u -r1.22 VelocityPortlet.java --- org/apache/jetspeed/portal/portlets/VelocityPortlet.java 20 Mar 2003 18:11:50 -0000 1.22 +++ org/apache/jetspeed/portal/portlets/VelocityPortlet.java 25 Jul 2003 16:08:45 -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". - */ + /** + * STW: Backward compatibility: set the viewType to "Velocity". + */ public void init() throws PortletException { - setCacheable(true); setViewType("Velocity"); - super.init(); + super.init(); } - - - + + + } Index: org/apache/jetspeed/portal/portlets/XSLPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java,v retrieving revision 1.10 diff -u -r1.10 XSLPortlet.java --- org/apache/jetspeed/portal/portlets/XSLPortlet.java 2 May 2003 22:38:13 -0000 1.10 +++ org/apache/jetspeed/portal/portlets/XSLPortlet.java 25 Jul 2003 16:08:45 -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 { - setCacheable(true); setViewType("XSL"); - super.init(); + super.init(); } - + } Index: org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java,v retrieving revision 1.4 diff -u -r1.4 JSPViewProcessor.java --- org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java 23 Jul 2003 19:50:18 -0000 1.4 +++ org/apache/jetspeed/portal/portlets/viewprocessor/JSPViewProcessor.java 25 Jul 2003 16:08:45 -0000 @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -62,14 +62,14 @@ import org.apache.jetspeed.portal.portlets.GenericMVCContext; import org.apache.jetspeed.services.TemplateLocator; import org.apache.jetspeed.services.Registry; -import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; -import org.apache.jetspeed.services.logging.JetspeedLogger; import org.apache.jetspeed.om.registry.PortletEntry; import org.apache.jetspeed.util.servlet.EcsServletElement; import org.apache.jetspeed.util.ServiceUtil; // Turbine stuff import org.apache.turbine.services.jsp.JspService; +import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; +import org.apache.jetspeed.services.logging.JetspeedLogger; // Turbine util import org.apache.turbine.util.RunData; @@ -83,14 +83,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 @@ -99,63 +99,58 @@ public class JSPViewProcessor implements ViewProcessor { - + /** * Static initialization of the logger for this class */ - private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JSPViewProcessor.class.getName()); - - /** Creates a new instance of JSPViewProcessor */ - public JSPViewProcessor() - { - } + private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JSPViewProcessor.class.getName()); + Portlet portlet = null; + public Object processView(GenericMVCContext context) { - - Portlet portlet = (Portlet) context.get("portlet"); + + 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"); - logger.info("JSPViewProcessor - processing template " + template); - + logger.debug("JSPViewProcessor - processing template " + template); + try { - // Allow access to portlet from .jsp template request.setAttribute("portlet", portlet); - + // put context in attribute so you can get to it from .jsp template request.setAttribute("context", context); - + // Add js_peid out of convenience 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 + + // 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()); - + // 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 (template != null && -1 == template.indexOf(".jsp")) { template = template + ".jsp"; } - - logger.info("JSPViewProcessor - locating template - " + data.toString() - + " - " + template); - + + logger.debug("JSPViewProcessor - locating template - " + data.toString() + + " - " + template); + //we use the template locator to translate the template String locatedTemplate = TemplateLocator.locatePortletTemplate(data, template); - logger.info("JSPViewProcessor - located template: " + locatedTemplate); - + logger.debug("JSPViewProcessor - located template: " + locatedTemplate); + /*if (locatedTemplate == null) { locatedTemplate = TemplateLocator.locateScreenTemplate(data, template); @@ -165,55 +160,55 @@ } logger.debug("JSPViewProcessor - located screen template: " + locatedTemplate); } */ - + 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); - + // handle request service.handleRequest(data, locatedTemplate); - + } else { // Build parameter list to be passed with the jsp Iterator names = portlet.getPortletConfig().getInitParameterNames(); - while (names.hasNext()) + while (names.hasNext()) { String name = (String) names.next(); String value = (String) portlet.getPortletConfig().getInitParameter(name); data.getParameters().setString(name, value); } - + template = pe.getURL(); - + if (logger.isDebugEnabled()) { logger.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()); } - + } catch (Exception e) { - - String message = "JSPViewProcessor: Could not include the following JSP Page: [" + template + "] :\n\t" - + e.getMessage(); + + String message = "JSPViewProcessor: Could not include the following JSP Page: [" + template + "] :\n\t" + + e.getMessage(); logger.error(message, e); - + return new StringElement(message); } - + 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 @@ -222,5 +217,6 @@ */ public void init(Portlet portlet) { + this.portlet = portlet; } } Index: org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java,v retrieving revision 1.3 diff -u -r1.3 VelocityViewProcessor.java --- org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java 23 Jul 2003 19:50:18 -0000 1.3 +++ org/apache/jetspeed/portal/portlets/viewprocessor/VelocityViewProcessor.java 25 Jul 2003 16:08:45 -0000 @@ -1,7 +1,7 @@ /* ==================================================================== * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,11 +65,11 @@ import org.apache.jetspeed.portal.portlets.GenericMVCContext; import org.apache.jetspeed.portal.portlets.viewprocessor.*; import org.apache.jetspeed.services.TemplateLocator; -import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; -import org.apache.jetspeed.services.logging.JetspeedLogger; import org.apache.jetspeed.util.JetspeedClearElement; import org.apache.turbine.services.velocity.TurbineVelocity; +import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; +import org.apache.jetspeed.services.logging.JetspeedLogger; import org.apache.turbine.util.RunData; @@ -77,24 +77,23 @@ * * @author tkuebler */ -public class VelocityViewProcessor implements ViewProcessor +public class VelocityViewProcessor +implements ViewProcessor { - + /** * Static initialization of the logger for this class */ - private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityViewProcessor.class.getName()); - - /** Creates a new instance of VelocityViewProcessor */ - public VelocityViewProcessor() - { - } + private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityViewProcessor.class.getName()); + Portlet portlet = null; + public void init(Portlet portlet) - throws PortletException - { - } - + 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 @@ -102,73 +101,50 @@ * */ public Object processView(GenericMVCContext context) - { - + { + // generate the content JetspeedClearElement element = null; String template = (String) context.get("template"); - logger.info("VelocityViewProcessor - processing " + template); - + + logger.debug("VelocityViewProcessor - processing " + template); + try - { - + { + if (-1 == template.indexOf(".vm")) - { + { template = template + ".vm"; - } - - logger.info("VelocityViewProcessor - locating template - " + - ((RunData) context.get("data")).toString() + template); - + } + + logger.debug("VelocityViewProcessor - locating template - " + + ((RunData) context.get("data")).toString() + template); + String templatePath = TemplateLocator.locatePortletTemplate( - (RunData) context.get("data"), - template); - - // need to add cache support + (RunData) context.get("data"), + template); + 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) - { - abstractPortlet =(AbstractPortlet) portlet; - if(abstractPortlet.getExpirationMillis() != null) - { - cachePeriod = abstractPortlet.getExpirationMillis().longValue(); - } - } - - 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()); - } + element = new JetspeedClearElement(TurbineVelocity.handleRequest(context, templatePath)); - } + } catch (Exception e) - { + { element = new JetspeedClearElement(e.toString()); logger.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: org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java,v retrieving revision 1.3 diff -u -r1.3 XSLViewProcessor.java --- org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java 23 Jul 2003 19:50:18 -0000 1.3 +++ org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java 25 Jul 2003 16:08:45 -0000 @@ -72,8 +72,6 @@ import org.apache.jetspeed.portal.Portlet; import org.apache.jetspeed.portal.PortletException; import org.apache.jetspeed.portal.portlets.GenericMVCContext; -import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; -import org.apache.jetspeed.services.logging.JetspeedLogger; import org.apache.jetspeed.services.rundata.JetspeedRunData; import org.apache.jetspeed.util.JetspeedClearElement; import org.apache.jetspeed.util.MimeType; @@ -84,6 +82,8 @@ import org.apache.ecs.ConcreteElement; // Turbine api +import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; +import org.apache.jetspeed.services.logging.JetspeedLogger; import org.apache.turbine.util.RunData; // XML stuff @@ -96,7 +96,7 @@ /** * 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 @@ -108,51 +108,48 @@ /** * Static initialization of the logger for this class */ - private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(XSLViewProcessor.class.getName()); - + private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(XSLViewProcessor.class.getName()); + private static final String XMLDECL = " -1) { base = name.substring(idx + 1, name.length()); } - + stylesheets.put(base, portlet.getPortletConfig().getInitParameter(name)); } else @@ -160,23 +157,21 @@ params.put(name.toLowerCase(), portlet.getPortletConfig().getInitParameter(name)); } } - + // read content, clean it, parse it and cache the DOM try { - 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"); @@ -184,51 +179,48 @@ } catch (Throwable t) { - String message = "XSLViewProcessor: Couldn't parse out XML document -> " + url; logger.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) { - + try { init((Portlet) context.get("portlet")); } catch (PortletException pe) { - logger.error("XSLViewProcessor - error: " + pe.getMessage(), pe); + pe.printStackTrace(); + logger.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); - + if (stylesheet != null) { - try { content = new JetspeedClearElement(SimpleTransform.transform(this.document, stylesheet, this.params)); - - // no caching yet // setContent( content, map ); } catch (SAXException e) { - logger.error("SAXException", e); + logger.error(e); content = new JetspeedClearElement(e.getMessage()); } } @@ -236,14 +228,13 @@ { 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 @@ -251,28 +242,25 @@ */ public boolean supportsType(MimeType mimeType) { - 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 @@ -280,24 +268,21 @@ */ 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: @@ -306,20 +291,20 @@ * 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) throws IOException { - + String filtered = null; int start = content.indexOf(XMLDECL); - + if (start <= 0) { filtered = content; @@ -328,7 +313,7 @@ { filtered = content.substring(start, content.length()); } - + return new StringReader(filtered); } }