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:
- *
+ *
*
- * 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: - *
- * + * * @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 *