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