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 15 Jul 2003 03:16:28 -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,94 +138,124 @@ 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 { - //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 + Log.debug("GenericMVCPortlet - cachePeriod set to " + cachePeriod); + } + catch (NumberFormatException e) + { + 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); + + 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); + 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() { - 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 (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) { // create a new context @@ -237,49 +268,47 @@ 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 (Log.getLogger().isDebugEnabled()) { Log.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) @@ -288,16 +317,22 @@ e.printStackTrace(); } } - + // Process View - // call processView method - Log.info("GenericMVCPortlet - calling processView on processor"); - + if (Log.getLogger().isDebugEnabled()) + { + Log.debug("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 - + setContent(result); + + if ( cachePeriod != 0 ) + { + cacheExpire = System.currentTimeMillis() + cachePeriod; + } + // return result return result; } @@ -309,9 +344,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 @@ -320,7 +355,7 @@ { this.viewType = viewType; } - + /** * This is called before any action execution happens. * This provides backward compatibility to JspPortletActions @@ -341,16 +376,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: 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 15 Jul 2003 03:16:28 -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: 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 15 Jul 2003 03:16:29 -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: 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 15 Jul 2003 03:16:29 -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: 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 15 Jul 2003 03:16:29 -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) { - - 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"); - Log.info("JSPViewProcessor - processing template " + template); - + Log.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"; } - - 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); - + Log.debug("JSPViewProcessor - located template: " + locatedTemplate); + /*if (locatedTemplate == null) { locatedTemplate = TemplateLocator.locateScreenTemplate(data, template); @@ -159,55 +154,55 @@ } Log.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 (Log.getLogger().isDebugEnabled()) { 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()); } - + } 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(); Log.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 @@ -216,5 +211,6 @@ */ 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 15 Jul 2003 03:16:29 -0000 @@ -77,19 +77,17 @@ * @author tkuebler */ public class VelocityViewProcessor - implements ViewProcessor - { - - /** Creates a new instance of VelocityViewProcessor */ - public VelocityViewProcessor() - { - } - +implements ViewProcessor +{ + + 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 @@ -97,73 +95,50 @@ * */ public Object processView(GenericMVCContext context) - { - + { + // generate the content JetspeedClearElement element = null; String template = (String) context.get("template"); - Log.info("VelocityViewProcessor - processing " + 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); - + } + + Log.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()); 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 15 Jul 2003 03:16:30 -0000 @@ -95,7 +95,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 @@ -103,50 +103,46 @@ public class XSLViewProcessor implements ViewProcessor { - private static final String XMLDECL = " -1) { base = name.substring(idx + 1, name.length()); } - + stylesheets.put(base, portlet.getPortletConfig().getInitParameter(name)); } else @@ -154,23 +150,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"); @@ -178,24 +172,23 @@ } catch (Throwable t) { - String message = "XSLViewProcessor: Couldn't parse out XML document -> " + url; 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) { - + try { init((Portlet) context.get("portlet")); @@ -205,21 +198,18 @@ 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); - + if (stylesheet != null) { - try { content = new JetspeedClearElement(SimpleTransform.transform(this.document, stylesheet, this.params)); - - // no caching yet // setContent( content, map ); } catch (SAXException e) { @@ -231,14 +221,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 @@ -246,28 +235,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 @@ -275,24 +261,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: @@ -301,20 +284,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; @@ -323,7 +306,7 @@ { filtered = content.substring(start, content.length()); } - + return new StringReader(filtered); } }