You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by pa...@apache.org on 2002/02/05 06:27:26 UTC

cvs commit: jakarta-jetspeed/xdocs portlet_config_WebPagePortlet.xml changes.xml

paulsp      02/02/04 21:27:26

  Modified:    src/java/org/apache/jetspeed/portal/portlets
                        WebPagePortlet.java
               docs/site portlet_config_WebPagePortlet.html changes.html
               xdocs    portlet_config_WebPagePortlet.xml changes.xml
  Log:
  Fix - Cache updates (part 3 of 3) (PS)
  Changes to the WebPagePortlet
  o Implement refreshable functionality
  o Do not get webpage during init().
  o Renamed field pageCached to initDone to acuratly refect
    it's use
  o Cleanup import statements
  o Do not cache an page the has "no-cache" set or expiration=0.
  o Add parameter "open_in_popup" to enable opening links in a new bowser window.
  
  Revision  Changes    Path
  1.8       +79 -47    jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/WebPagePortlet.java
  
  Index: WebPagePortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/WebPagePortlet.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- WebPagePortlet.java	9 Nov 2001 07:11:59 -0000	1.7
  +++ WebPagePortlet.java	5 Feb 2002 05:27:26 -0000	1.8
  @@ -55,28 +55,24 @@
   package org.apache.jetspeed.portal.portlets;
   
   //Element Construction Set
  -import org.apache.ecs.html.*;
  +import org.apache.ecs.ClearElement;
   import org.apache.ecs.ConcreteElement;
  -import org.apache.ecs.ElementContainer;
  -import org.apache.ecs.StringElement;
   
   //Jetspeed stuff
  -import org.apache.jetspeed.portal.*;
  -import org.apache.jetspeed.util.*;
  -
  +import org.apache.jetspeed.portal.PortletConfig;
  +import org.apache.jetspeed.portal.PortletException;
  +import org.apache.jetspeed.util.HTMLRewriter;
   
   //turbine
  -import org.apache.turbine.util.*;
  +import org.apache.turbine.util.Log;
  +import org.apache.turbine.util.RunData;
   
   //standard java stuff
  -import java.net.*;
  -import java.util.*;
  -import java.io.*;
  -
  -//ecs stuff
  -import org.apache.ecs.*;
  -import org.apache.ecs.html.*;
  -
  +import java.io.InputStreamReader;
  +import java.io.IOException;
  +import java.io.Reader;
  +import java.net.URL;
  +import java.net.URLConnection;
   
   /**
    * A class that loads a web page and filters it to have certain features
  @@ -89,11 +85,17 @@
   public class WebPagePortlet extends AbstractPortlet {
   
       HTMLRewriter rewriter = null;
  -    boolean pageCached = false;
  -
  +    boolean initDone = false;
  +    boolean contentStale = true;
  +    boolean cacheContent = false;
  +    
  +    /**
  +     * Initialize this portlet by defining a HTML rewriter.
  +     * @throws PortletException Initialization failed
  +     */    
       public void init() throws PortletException {
     
  -        if (pageCached) // Why is init called more than once per portlet?
  +        if (initDone) // Why is init called more than once per portlet?
               return;
   
           PortletConfig config = this.getPortletConfig();
  @@ -117,9 +119,12 @@
                       ! config.getInitParameter("dont_remove_head","no")
                           .equalsIgnoreCase("yes"),
                       ! config.getInitParameter("dont_remove_onsomething","no")
  +                        .equalsIgnoreCase("yes"),
  +                    config.getInitParameter("open_in_popup","no")
                           .equalsIgnoreCase("yes")
  -                 );
  -
  +                        );
  +            contentStale = true;
  +            initDone = true;
           } catch (Exception e) {
               Log.info("Exception occurred:" + e.toString());
               e.printStackTrace();
  @@ -139,16 +144,45 @@
           URLConnection  pageConn = pageUrl.openConnection();
           long           pageExpiration = pageConn.getExpiration();
           String         encoding = pageConn.getContentEncoding();
  +        String         tempString = null;
  +        String         noCache = "no-cache";
  +        
           if(encoding == null)
           {
               // Standard HTTP encoding
               encoding = "iso-8859-1";
           }
  +
  +        /*
  +         * Determing if content should be cached.
  +         */
  +        cacheContent = true; // Assume content is cached
  +        if (pageExpiration == 0) {
  +            cacheContent = false;
  +        }
  +        // Check header field CacheControl
  +        tempString = pageConn.getHeaderField( "Cache-Control");
  +        if (tempString != null) {
  +            if (tempString.toLowerCase().indexOf(noCache) >= 0) {
  +                cacheContent = false;
  +            }
  +        }
  +        // Check header field Pragma
  +        tempString = pageConn.getHeaderField( "Pragma");
  +        if (tempString != null) {
  +            if (tempString.toLowerCase().indexOf(noCache) >= 0) {
  +                cacheContent = false;
  +            }
  +        }
  +            
  +        // Assign a reader
           Reader rdr = new InputStreamReader(pageConn.getInputStream(),
                                              encoding );
  +
           // Only set the page expiration it the page has not expired
  -        if (pageExpiration > System.currentTimeMillis())
  +        if (pageExpiration > System.currentTimeMillis() && (cacheContent == true))
           {
  +            contentStale = false;
               Log.debug( "WebPagePortlet caching URL: " + 
                          url + 
                          " Expiration: " + 
  @@ -157,17 +191,13 @@
                          (pageExpiration - System.currentTimeMillis() ) +
                          " milliseconds into the future" );
               setExpirationMillis(pageExpiration);
  +        } else {
  +            contentStale = true;
           }
   
           return rdr;
       }
   
  -    /**
  -  
  -    public boolean isCacheable() {
  -        return getExpirationMillis() != null;
  -    }
  -  */
   
       /**
       This methods outputs the content of the portlet for a given 
  @@ -179,26 +209,17 @@
       public ConcreteElement getContent( RunData data ) 
       {
           PortletConfig config = this.getPortletConfig();
  +        
  +        if (contentStale == true)
  +            return getWebPageContent(data, config);
  +        
  +        if (null == getExpirationMillis())
  +            return getContent( data, null, true);
  +        
  +        if (getExpirationMillis().longValue() <= System.currentTimeMillis())
  +            return getWebPageContent(data, config);
   
  -        try
  -        {
  -            if (pageCached)
  -            {
  -                if (null == getExpirationMillis())
  -                    return getContent( data, null, true);
  -
  -                if (getExpirationMillis().longValue() <= System.currentTimeMillis())
  -                    return getWebPageContent(data, config);
  -    
  -                return getContent( data, null , true );
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -        }
  -        // cache page first time
  -        return getWebPageContent(data, config);
  +        return getContent( data, null , true );
       }
   
       private ConcreteElement getWebPageContent( RunData data, PortletConfig config )
  @@ -212,7 +233,6 @@
               Reader htmlReader = getReader( config.getURL() );
               //FIXME: HTMLRewriter should take a Reader, and work
               convertedString = rewriter.convertURLs(htmlReader, config.getURL());
  -            pageCached = true;
               element = new ClearElement(convertedString);
   
               //FIXME: We should do a clearContent() for the media type, not ALL media types
  @@ -227,6 +247,18 @@
           }        
   
           return element;
  +    }
  +    
  +    /**
  +     * Usually called by caching system when portlet is marked as expired, but
  +     * has not be idle longer then TimeToLive.
  +     *
  +     * Any cached content that is expired need to be refreshed.
  +     */
  +    public void refresh() {
  +        if (cacheContent == true) {
  +          getWebPageContent(null, this.getPortletConfig());
  +        }
       }
   
   }
  
  
  
  1.8       +40 -1     jakarta-jetspeed/docs/site/portlet_config_WebPagePortlet.html
  
  Index: portlet_config_WebPagePortlet.html
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/docs/site/portlet_config_WebPagePortlet.html,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- portlet_config_WebPagePortlet.html	2 Feb 2002 03:29:43 -0000	1.7
  +++ portlet_config_WebPagePortlet.html	5 Feb 2002 05:27:26 -0000	1.8
  @@ -490,7 +490,7 @@
   </td>
                                   <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
       <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  -                no
  +                &lt;STYLE&gt; tag.
               </font>
   </td>
               </tr>
  @@ -515,6 +515,45 @@
                 <tr>
                   <td>no</td>
                   <td>&lt;STYLE&gt; tags are removed</td>
  +              </tr>
  +            </table>
  +          
  +            </font>
  +</td>
  +            </tr>
  +                                <tr>
  +                        <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
  +    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  +                openinpopup
  +            </font>
  +</td>
  +                                <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
  +    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  +                Open links in a new window
  +            </font>
  +</td>
  +            </tr>
  +                                <tr>
  +                        <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
  +    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  +                &nbsp;
  +            </font>
  +</td>
  +                                <td bgcolor="#a0ddf0" colspan="" rowspan="" valign="top" align="left">
  +    <font color="#000000" size="-1" face="arial,helvetica,sanserif">
  +                If not present, "no" is the default value
  +            <table>
  +              <tr>
  +                <th>Value</th>
  +                <th>Description</th>
  +              </tr>
  +              <tr>
  +                <td>yes</td>
  +                <td>Links are opened in a pop-up browser window</td>
  +              </tr>
  +              <tr>
  +                <td>no</td>
  +                <td>Links are opened in a the current browser window</td>
                 </tr>
               </table>
             
  
  
  
  1.10      +13 -1     jakarta-jetspeed/docs/site/changes.html
  
  Index: changes.html
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/docs/site/changes.html,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- changes.html	5 Feb 2002 03:08:04 -0000	1.9
  +++ changes.html	5 Feb 2002 05:27:26 -0000	1.10
  @@ -198,7 +198,7 @@
       </ul>
   </li>
   <li>
  -  Fix - Cache uppdates (part 2) (PS)
  +  Fix - Cache updates (part 2) (PS)
       <ul>
          <li>
            The Abstract portlet is now refreshable.  This means the caching system
  @@ -220,6 +220,18 @@
          <li>
            Method have been added to various classes to support the updates to the memory caching.
          </li>
  +    </ul>
  +</li>
  +<li>
  +  Fix - Cache updates (part 3 of 3) (PS)
  +  <br />Changes to the WebPagePortlet
  +    <ul>
  +       <li>Implement refreshable functionality</li>
  +       <li>Do not get webpage during init().</li>
  +       <li>Renamed field pageCached to initDone to accurately reflect it's use</li>
  +       <li>Cleanup import statements.</li>
  +       <li>Do not cache an page the has "no-cache" set or expiration=0.</li>
  +       <li>Add parameter "open_in_popup" to enable opening links in a new bowser window.</li>
       </ul>
   </li>
             </ul>
  
  
  
  1.4       +24 -1     jakarta-jetspeed/xdocs/portlet_config_WebPagePortlet.xml
  
  Index: portlet_config_WebPagePortlet.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/xdocs/portlet_config_WebPagePortlet.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- portlet_config_WebPagePortlet.xml	11 Jan 2002 23:52:30 -0000	1.3
  +++ portlet_config_WebPagePortlet.xml	5 Feb 2002 05:27:26 -0000	1.4
  @@ -227,7 +227,7 @@
           </tr>
           <tr>
             <td>dont_remove_style</td>
  -          <td>no</td>
  +          <td>&lt;STYLE&gt; tag.</td>
           </tr>
           <tr>
             <td></td>
  @@ -244,6 +244,29 @@
                 <tr>
                   <td>no</td>
                   <td>&lt;STYLE&gt; tags are removed</td>
  +              </tr>
  +            </table>
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>openinpopup</td>
  +          <td>Open links in a new window</td>
  +        </tr>
  +        <tr>
  +          <td></td>
  +          <td>If not present, "no" is the default value
  +            <table>
  +              <tr>
  +                <th>Value</th>
  +                <th>Description</th>
  +              </tr>
  +              <tr>
  +                <td>yes</td>
  +                <td>Links are opened in a pop-up browser window</td>
  +              </tr>
  +              <tr>
  +                <td>no</td>
  +                <td>Links are opened in a the current browser window</td>
                 </tr>
               </table>
             </td>
  
  
  
  1.18      +14 -2     jakarta-jetspeed/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/xdocs/changes.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- changes.xml	5 Feb 2002 03:08:05 -0000	1.17
  +++ changes.xml	5 Feb 2002 05:27:26 -0000	1.18
  @@ -1,6 +1,6 @@
   <?xml version="1.0" encoding="iso-8859-1"?>
   <!--
  -$Id: changes.xml,v 1.17 2002/02/05 03:08:05 paulsp Exp $
  +$Id: changes.xml,v 1.18 2002/02/05 05:27:26 paulsp Exp $
   -->
   <document>
     <properties>
  @@ -94,7 +94,7 @@
       </ul>
   </li>
   <li>
  -  Fix - Cache uppdates (part 2) (PS)
  +  Fix - Cache updates (part 2) (PS)
       <ul>
          <li>
            The Abstract portlet is now refreshable.  This means the caching system
  @@ -116,6 +116,18 @@
          <li>
            Method have been added to various classes to support the updates to the memory caching.
          </li>
  +    </ul>
  +</li>
  +<li>
  +  Fix - Cache updates (part 3 of 3) (PS)
  +  <br/>Changes to the WebPagePortlet
  +    <ul>
  +       <li>Implement refreshable functionality</li>
  +       <li>Do not get webpage during init().</li>
  +       <li>Renamed field pageCached to initDone to accurately reflect it's use</li>
  +       <li>Cleanup import statements.</li>
  +       <li>Do not cache an page the has "no-cache" set or expiration=0.</li>
  +       <li>Add parameter "open_in_popup" to enable opening links in a new bowser window.</li>
       </ul>
   </li>
             </ul>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>