portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morci...@apache.org
Subject cvs commit: jakarta-jetspeed/xdocs changes.xml
Date Fri, 02 May 2003 22:38:13 GMT
morciuch    2003/05/02 15:38:13

  Modified:    docs/site changes.html
               src/java/org/apache/jetspeed/portal/portlets XSLPortlet.java
               src/java/org/apache/jetspeed/portal/portlets/viewprocessor
                        RSSViewProcessor.java XSLViewProcessor.java
               xdocs    changes.xml
  Log:
  Refactored XLS and RSS view processors (see Bugzilla issue# 19612)
  
  Revision  Changes    Path
  1.136     +4 -3      jakarta-jetspeed/docs/site/changes.html
  
  Index: changes.html
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/docs/site/changes.html,v
  retrieving revision 1.135
  retrieving revision 1.136
  diff -u -r1.135 -r1.136
  --- changes.html	2 May 2003 20:44:40 -0000	1.135
  +++ changes.html	2 May 2003 22:38:12 -0000	1.136
  @@ -5,7 +5,6 @@
           
   <!-- start the processing -->
       <!-- ====================================================================== -->
  -    <!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
       <!-- Main Page Section -->
       <!-- ====================================================================== -->
       <html>
  @@ -15,7 +14,6 @@
                           
              
                                       
  -                        
               <title>Jetspeed - Jetspeed Changes Log</title>
           </head>
   
  @@ -137,6 +135,9 @@
   </li>
   -->
   <li>
  +  Fix -   Bug # 19612 - 2003/05/02 - Refactored XSL and RSS view processors (MO)
  +</li>
  +<li>
     Add -   Bug # 19535 - 2003/05/02 - Refactored Registry Editors, contributed by Jeremy
Ford (DST)
   </li>
   <li>
  @@ -927,7 +928,7 @@
                   </td></tr>
                   <tr><td colspan="2">
                       <div align="center"><font color="#525D76" size="-1"><em>
  -                    Copyright &#169; 1999-2003, Apache Software Foundation
  +                    Copyright &#169; 1999-2002, Apache Software Foundation
                       </em></font></div>
                   </td></tr>
               </table>
  
  
  
  1.10      +17 -104   jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java
  
  Index: XSLPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/XSLPortlet.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- XSLPortlet.java	4 Mar 2003 00:05:05 -0000	1.9
  +++ XSLPortlet.java	2 May 2003 22:38:13 -0000	1.10
  @@ -54,115 +54,28 @@
   
   package org.apache.jetspeed.portal.portlets;
   
  -//standard java stuff
  -import java.util.*;
  -
  -//Element Construction Set
  -import org.apache.jetspeed.util.JetspeedClearElement;
  -import org.apache.ecs.ConcreteElement;
  -
   //standard Jetspeed stuff
  -import org.apache.jetspeed.util.*;
  -import org.apache.jetspeed.portal.*;
  -import org.apache.jetspeed.capability.CapabilityMap;
  -import org.apache.jetspeed.services.rundata.JetspeedRunData;
  -
  -//turbine
  -import org.apache.turbine.util.*;
  -
  -//SAX
  -import org.xml.sax.*;
  +import org.apache.jetspeed.portal.PortletException;
   
   /**
  -Simple portlet which does a basic XSLT transform with the stylesheet parameter
  -and the given portlet URL.
  -
  -@author <A HREF="mailto:raphael@apache.org">RaphaŽl Luta</A>
  -@version $Id$
  -*/
  -public class XSLPortlet extends AbstractPortlet {
  + * Simple portlet which does a basic XSLT transform with the stylesheet parameter
  + * and the given portlet URL.
  + * 
  + * @author <A HREF="mailto:raphael@apache.org">RaphaŽl Luta</A>
  + * @version $Id$
  + */
  +public class XSLPortlet extends GenericMVCPortlet 
  +{
   
       /**
  -    The stylesheet parameter
  -    */
  -    public static final String STYLESHEET = "stylesheet";
  -
  -    public final static String ERROR_NOT_VALID = "This does not appear to be an RSS document";
  -    public final static String INVALID_TYPE = "Unable to display for this browser";
  -
  -    private Hashtable stylesheets = null;
  -
  -    /**
  -    This method loads the init parameters
  -    */
  -    public void init() throws PortletException {
  -
  -        stylesheets = new Hashtable();
  -        Iterator en = this.getPortletConfig().getInitParameterNames();
  -        while (en.hasNext()) {
  -            String name = (String)en.next();
  -            String base = MimeType.HTML.toString();
  -            if (name.startsWith(STYLESHEET)) {
  -                int idx=-1;
  -                if ((idx=name.indexOf("."))>-1) {
  -                    base= name.substring(idx+1,name.length());
  -                }
  -                stylesheets.put(base,this.getPortletConfig().getInitParameter(name));
  -            }
  -        }
  -    }
  -
  -
  -    /**
  -    This methods outputs the content of the portlet for a given
  -    request.
  -
  -    @param data the RunData object for the request
  -    @return the content to be displayed to the user-agent
  -    */
  -    public ConcreteElement getContent( RunData 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) {
  -            content = getContent( data, map );
  -            if ( content == null ) {
  -                try {
  -                    content = new JetspeedClearElement(
  -                        SimpleTransform.transform( getPortletConfig().getURL(),
  -                                                   stylesheet,
  -                                                   getPortletConfig().getInitParameters()
) );
  -                    setContent( content, map );
  -                } catch ( SAXException e ) {
  -                    Log.error( e );
  -                    content = new JetspeedClearElement(e.getMessage());
  -                }
  -            }
  -        }
  -
  -        return content;
  -    }
  -
  -    /**
  -    This portlet supports has many types as those
  -    it has stylesheets defined for in its parameters
  -
  -    @see Portlet#supportsType
  -    @param mimeType the MIME type queried
  -    @return true if the portlet knows how to display
  -    content for mimeType
  -    */
  -    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;
  +     * 
  +     * @exception PortletException
  +     */
  +    public void init() throws PortletException
  +    {
  +        setCacheable(true);
  +        setViewType("XSL");
  +        super.init();        
       }
   
   }
  
  
  
  1.2       +44 -282   jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/RSSViewProcessor.java
  
  Index: RSSViewProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/RSSViewProcessor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RSSViewProcessor.java	20 Mar 2003 18:09:39 -0000	1.1
  +++ RSSViewProcessor.java	2 May 2003 22:38:13 -0000	1.2
  @@ -53,152 +53,51 @@
    */
   package org.apache.jetspeed.portal.portlets.viewprocessor;
   
  -import java.io.IOException;
  -
  -//standard java stuff
  -import java.io.Reader;
  -import java.io.StringReader;
  -
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.util.Iterator;
  -
  -
  -//JAXP support
  -import javax.xml.parsers.DocumentBuilder;
  -import javax.xml.parsers.DocumentBuilderFactory;
  -
  -import org.apache.ecs.ConcreteElement;
  -
  -import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
  -import org.apache.jetspeed.capability.CapabilityMap;
  -import org.apache.jetspeed.capability.CapabilityMapFactory;
  +// Jetspeed apis
   import org.apache.jetspeed.portal.Portlet;
   import org.apache.jetspeed.portal.PortletException;
  -import org.apache.jetspeed.portal.portlets.*;
  -import org.apache.jetspeed.portal.portlets.GenericMVCContext;
  -import org.apache.jetspeed.portal.portlets.viewprocessor.*;
  -import org.apache.jetspeed.services.rundata.JetspeedRunData;
  -
  -// Element Construction Set
  -import org.apache.jetspeed.util.JetspeedClearElement;
  -import org.apache.jetspeed.util.MimeType;
  -import org.apache.jetspeed.util.SimpleTransform;
  -import org.apache.jetspeed.xml.JetspeedXMLEntityResolver;
  -
  -import org.apache.turbine.util.Log;
  -import org.apache.turbine.util.RunData;
  -
   
   // XML stuff
  -import org.w3c.dom.Document;
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -
  -
   /**
  -<p>Portlet which renders RDF Site Summary.</p>
  -<p>This portlet uses XML stylesheet for transforming the RSS
  -content into display markup depending on the MimeType requested
  -by the user-agent</p>
  -<p>It accepts the following parameters :
  -<dl>
  -<dt>itemDisplayed</dt>
  -<dd>The number of items from the RSS file to display on screen. Default 15 for HTML,
5 for WML</dd>
  -<dt>showDescription</dt>
  -<dd>Should the portlet show the item descriptions. Must be true or false. Default:
true for HTML, false for WML</dd>
  -<dt>showTitle</dt>
  -<dd>Should the portlet show the channel description. Must be true or false. Default:
true for HTML, false for WML</dd>
  -<dt>stylesheet[.<mime>]</dt>
  -<dd>The stylesheet URL. If a mime-type is specified, the stylesheet
  -is only used for this mime-type</dd>
  -</dl>
  -@author <A HREF="mailto:raphael@apache.org">RaphaŽl Luta</A>
  -@version $Id$
  -*/
  -public class RSSViewProcessor
  -    implements ViewProcessor
  -  {
  -
  -    private static final String XMLDECL = "<?xml version=";
  -    public static final String ERROR_NOT_VALID = "This does not appear to be an RSS document";
  -    public static final String INVALID_TYPE = "Unable to display for this browser";
  -    private Document document = null;
  -    private Hashtable stylesheets = null;
  -    private Hashtable params = null;
  + * <p>Portlet which renders RDF Site Summary.</p>
  + * <p>This portlet uses XML stylesheet for transforming the RSS
  + * content into display markup depending on the MimeType requested
  + * by the user-agent</p>
  + * <p>It accepts the following parameters :
  + * <dl>
  + * <dt>itemDisplayed</dt>
  + * <dd>The number of items from the RSS file to display on screen. Default 15 for
HTML, 5 for WML</dd>
  + * <dt>showDescription</dt>
  + * <dd>Should the portlet show the item descriptions. Must be true or false. Default:
true for HTML, false for WML</dd>
  + * <dt>showTitle</dt>
  + * <dd>Should the portlet show the channel description. Must be true or false. Default:
true for HTML, false for WML</dd>
  + * <dt>stylesheet[.<mime>]</dt>
  + * <dd>The stylesheet URL. If a mime-type is specified, the stylesheet
  + * is only used for this mime-type</dd>
  + * </dl>
  + * 
  + * @author <A HREF="mailto:raphael@apache.org">RaphaŽl Luta</A>
  + * @version $Id$
  + * @since 1.4b4
  + */
  +public class RSSViewProcessor extends XSLViewProcessor
  +{
   
       /**
  -        This method loads the init parameters and
  -        parse the document tied to this portlet
  -    */
  +     * This method loads the init parameters and
  +     * parse the document tied to this portlet
  +     * 
  +     * @param portlet
  +     * @exception PortletException
  +     */
       public void init(Portlet portlet)
  -              throws PortletException
  -      {
  -
  -        DocumentBuilder parser = null;
  -        String url = null;
  +    throws PortletException
  +    {
   
  -        // load stylesheets available
  -        stylesheets = new Hashtable();
  -        params = new Hashtable();
  -
  -        Iterator i = portlet.getPortletConfig().getInitParameterNames();
  -
  -        while (i.hasNext())
  -          {
  -
  -            String name = (String) i.next();
  -            String base = MimeType.HTML.toString();
  -
  -            if (name.startsWith("stylesheet"))
  -              {
  -
  -                int idx = -1;
  -
  -                if ((idx = name.indexOf(".")) > -1)
  -                  {
  -                    base = name.substring(idx + 1, name.length());
  -                  }
  -
  -                stylesheets.put(base, portlet.getPortletConfig().getInitParameter(name));
  -              }
  -            else
  -              {
  -                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");
  -            this.document = parser.parse(isrc);
  -          }
  -        catch (Throwable t)
  -          {
  -
  -            String message = "RSSPortlet:  Couldn't parse out XML document -> " + url;
  -            Log.error(message, t);
  -            throw new PortletException(t.getMessage());
  -          }
  +        super.init(portlet);
   
           //Determine title and description for this portlet
           String title = null;
  @@ -206,172 +105,35 @@
   
           //now find the channel node.
           Node channel = null;
  -        NodeList list = document.getElementsByTagName("channel");
  +        NodeList list = this.document.getElementsByTagName("channel");
   
           if (list.getLength() != 1)
  -          {
  +        {
               throw new PortletException(ERROR_NOT_VALID);
  -          }
  +        }
   
           channel = list.item(0);
   
           Node tn = getNode(channel, "title");
   
           if (tn == null)
  -          {
  +        {
               throw new PortletException(ERROR_NOT_VALID);
  -          }
  +        }
           else
  -          {
  +        {
               title = tn.getFirstChild().getNodeValue();
  -          }
  +        }
   
           Node dn = getNode(channel, "description");
   
           if (dn != null)
  -          {
  +        {
               description = dn.getFirstChild().getNodeValue();
  -          }
  +        }
   
           portlet.setTitle(title);
           portlet.setDescription(description);
  -      }
  -
  -    /**
  -    This methods outputs the content of the portlet for a given
  -    request.
  -
  -    @param data the RunData object for the request
  -    @return the content to be displayed to the user-agent
  -    */
  -    public Object processView(GenericMVCContext context)
  -      {
  -
  -        try
  -          {
  -            init((Portlet) context.get("portlet"));
  -          }
  -        catch (PortletException pe)
  -          {
  -            pe.printStackTrace();
  -            Log.error("RSSViewProcessor - 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)
  -              {
  -                Log.error(e);
  -                content = new JetspeedClearElement(e.getMessage());
  -              }
  -          }
  -        else
  -          {
  -            content = new JetspeedClearElement("stylesheet not defined");
  -          }
  -
  -        return content;
  -      }
  -
  -    /**
  -    This portlet supports has many types as those
  -    it has stylesheets defined for in its parameters
  +    }
   
  -    @see Portlet#supportsType
  -    @param mimeType the MIME type queried
  -    @return true if the portlet knows how to display
  -    content for mimeType
  -    */
  -    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
  -    is name
  -    */
  -    private final 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:
  -    <ul>
  -        <li>
  -            If the document doesn't begin with "<?xml version=" truncate the
  -            content until this is the first line
  -        </li>
  -
  -    </ul>
  -
  -    */
  -    private Reader cleanse(String content)
  -                    throws IOException
  -      {
  -
  -        String filtered = null;
  -        int start = content.indexOf(XMLDECL);
  -
  -        if (start <= 0)
  -          {
  -            filtered = content;
  -          }
  -        else
  -          {
  -            filtered = content.substring(start, content.length());
  -          }
  -
  -        return new StringReader(filtered);
  -      }
  -  }
  +}
  
  
  
  1.2       +207 -92   jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java
  
  Index: XSLViewProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/viewprocessor/XSLViewProcessor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XSLViewProcessor.java	20 Mar 2003 18:09:39 -0000	1.1
  +++ XSLViewProcessor.java	2 May 2003 22:38:13 -0000	1.2
  @@ -1,4 +1,4 @@
  -/* ===================================================================
  +/* ====================================================================
    * The Apache Software License, Version 1.1
    *
    * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
  @@ -53,162 +53,277 @@
    */
   package org.apache.jetspeed.portal.portlets.viewprocessor;
   
  +//standard java stuff
  +import java.io.Reader;
  +import java.io.StringReader;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Iterator;
  +import java.io.IOException;
   
  -import org.apache.ecs.ConcreteElement;
  +//JAXP support
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
   
  +// Jetspeed api
  +import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
   import org.apache.jetspeed.capability.CapabilityMap;
  +import org.apache.jetspeed.capability.CapabilityMapFactory;
   import org.apache.jetspeed.portal.Portlet;
  -import org.apache.jetspeed.portal.portlets.*;
  +import org.apache.jetspeed.portal.PortletException;
   import org.apache.jetspeed.portal.portlets.GenericMVCContext;
  -import org.apache.jetspeed.portal.portlets.viewprocessor.*;
   import org.apache.jetspeed.services.rundata.JetspeedRunData;
  -
  -//Element Construction Set
   import org.apache.jetspeed.util.JetspeedClearElement;
   import org.apache.jetspeed.util.MimeType;
   import org.apache.jetspeed.util.SimpleTransform;
  +import org.apache.jetspeed.xml.JetspeedXMLEntityResolver;
   
  +// Element Construction Set
  +import org.apache.ecs.ConcreteElement;
   
  -//turbine
  +// Turbine api
   import org.apache.turbine.util.Log;
  +import org.apache.turbine.util.RunData;
   
  -
  -//SAX
  +// XML stuff
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NodeList;
  +import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
   
  -
   /**
    * 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
  -  {
   
  -    /**
  -    The stylesheet parameter
  -    */
  -    public static final String STYLESHEET = "stylesheet";
  +public class XSLViewProcessor implements ViewProcessor
  +{
  +
  +    private static final String XMLDECL = "<?xml version=";
       public static final String ERROR_NOT_VALID = "This does not appear to be an XML document";
       public static final String INVALID_TYPE = "Unable to display for this browser";
  -    private Hashtable stylesheets = null;
  +    protected Document document = null;
  +    protected Hashtable stylesheets = null;
  +    private Hashtable params = null;
   
       /**
  -    Constructor
  -    */
  -    public XSLViewProcessor()
  -      {
  -      }
  +     * This method loads the init parameters and
  +     * parse the document tied to this portlet
  +     * 
  +     * @param portlet
  +     * @exception PortletException
  +     */
  +    public void init(Portlet portlet)
  +    throws PortletException
  +    {
   
  -    /**
  -    This methods outputs the content of the portlet for a given
  -    request.
  +        DocumentBuilder parser = null;
  +        String url = null;
  +
  +        // load stylesheets available
  +        stylesheets = new Hashtable();
  +        params = new Hashtable();
   
  -    @param data the RunData object for the request
  -    @return the content to be displayed to the user-agent
  -    */
  +        Iterator i = portlet.getPortletConfig().getInitParameterNames();
  +
  +        while (i.hasNext())
  +        {
  +
  +            String name = (String) i.next();
  +            String base = MimeType.HTML.toString();
  +
  +            if (name.startsWith("stylesheet"))
  +            {
  +
  +                int idx = -1;
  +
  +                if ((idx = name.indexOf(".")) > -1)
  +                {
  +                    base = name.substring(idx + 1, name.length());
  +                }
  +
  +                stylesheets.put(base, portlet.getPortletConfig().getInitParameter(name));
  +            }
  +            else
  +            {
  +                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");
  +            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());
  +        }
  +
  +    }
  +
  +    /**
  +     * 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)
  -      {
  -        getStylesheets((Portlet) context.get("portlet")); // used to be in portlet init,
do we
  +    {
  +
  +        try
  +        {
  +            init((Portlet) context.get("portlet"));
  +        }
  +        catch (PortletException pe)
  +        {
  +            pe.printStackTrace();
  +            Log.error("XSLViewProcessor - error: " + pe);
  +        }
   
  -        // need to get this functionality
  -        // into the model?
  -        CapabilityMap map = ((JetspeedRunData) context.get("data")).getCapability();
  +        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(
  -                                ((Portlet) context.get("portlet")).getPortletConfig().getURL(),

  -                                stylesheet, 
  -                                ((Portlet) context.get("portlet")).getPortletConfig().getInitParameters()));
  -              }
  +            {
  +                content = new JetspeedClearElement(SimpleTransform.transform(this.document,
stylesheet, this.params));
  +
  +                // no caching yet // setContent( content, map );
  +            }
               catch (SAXException e)
  -              {
  +            {
                   Log.error(e);
                   content = new JetspeedClearElement(e.getMessage());
  -              }
  -          }
  +            }
  +        }
  +        else
  +        {
  +            content = new JetspeedClearElement("stylesheet not defined");
  +        }
   
           return content;
  -      }
  +    }
   
       /**
  -    This portlet supports has many types as those
  -    it has stylesheets defined for in its parameters
  -
  -    @see Portlet#supportsType
  -    @param mimeType the MIME type queried
  -    @return true if the portlet knows how to display
  -    content for mimeType
  -    */
  +     * 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)
  -      {
  +    {
   
           Enumeration en = stylesheets.keys();
   
           while (en.hasMoreElements())
  -          {
  +        {
   
               String type = (String) en.nextElement();
   
               if (type.equals(mimeType.toString()))
  -              {
  +            {
   
                   return true;
  -              }
  -          }
  +            }
  +        }
   
           return false;
  -      }
  +    }
   
  -    private void getStylesheets(Portlet portlet)
  -      {
  -        stylesheets = new Hashtable();
  +    /**
  +     * 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)
  +    {
   
  -        Iterator en = portlet.getPortletConfig().getInitParameterNames();
  +        NodeList list = start.getChildNodes();
   
  -        while (en.hasNext())
  -          {
  +        for (int i = 0; i < list.getLength(); ++i)
  +        {
   
  -            String name = (String) en.next();
  -            String base = MimeType.HTML.toString();
  +            Node node = list.item(i);
   
  -            if (name.startsWith(STYLESHEET))
  -              {
  +            if (node.getNodeName().equals(name))
  +            {
   
  -                int idx = -1;
  +                return node;
  +            }
  +        }
   
  -                if ((idx = name.indexOf(".")) > -1)
  -                  {
  -                    base = name.substring(idx + 1, name.length());
  -                  }
  +        return null;
  +    }
   
  -                stylesheets.put(base, portlet.getPortletConfig().getInitParameter(name));
  -              }
  -          }
  -      }
  -
  -    /** Process the template passed in the context
  -     * (context.get("template")).  Invoked by the GenericMVCPortlet
  -     * after action handling to process the template type
  -     * in question.
  -     *
  +    /**
  +     *  Given a URL to some content, clean the content to Xerces can handle it
  +     *  better.  Right now this involves:
  +     * <ul>
  +     *     <li>
  +     *         If the document doesn't begin with "&lt;?xml version=" truncate the
  +     *         content until this is the first line
  +     *     </li>
  +     * 
  +     * </ul>
  +     * 
  +     * @param content
  +     * @return 
  +     * @exception IOException
        */
  -    public void init(Portlet portlet)
  -      {
  -      }
  -  }
  +    protected Reader cleanse(String content)
  +    throws IOException
  +    {
  +
  +        String filtered = null;
  +        int start = content.indexOf(XMLDECL);
  +
  +        if (start <= 0)
  +        {
  +            filtered = content;
  +        }
  +        else
  +        {
  +            filtered = content.substring(start, content.length());
  +        }
  +
  +        return new StringReader(filtered);
  +    }
  +}
  
  
  
  1.155     +4 -1      jakarta-jetspeed/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/xdocs/changes.xml,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- changes.xml	2 May 2003 20:44:32 -0000	1.154
  +++ changes.xml	2 May 2003 22:38:13 -0000	1.155
  @@ -24,6 +24,9 @@
   </li>
   -->
   <li>
  +  Fix -   Bug # 19612 - 2003/05/02 - Refactored XSL and RSS view processors (MO)
  +</li>
  +<li>
     Add -   Bug # 19535 - 2003/05/02 - Refactored Registry Editors, contributed by Jeremy
Ford (DST)
   </li>
   <li>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message