Return-Path: Delivered-To: apmail-jakarta-jetspeed-dev-archive@www.apache.org Received: (qmail 31336 invoked from network); 22 Dec 2004 23:58:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 22 Dec 2004 23:58:50 -0000 Received: (qmail 25634 invoked by uid 500); 22 Dec 2004 23:58:48 -0000 Delivered-To: apmail-jakarta-jetspeed-dev-archive@jakarta.apache.org Received: (qmail 25449 invoked by uid 500); 22 Dec 2004 23:58:47 -0000 Mailing-List: contact jetspeed-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jetspeed Developers List" Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@jakarta.apache.org Received: (qmail 25436 invoked by uid 500); 22 Dec 2004 23:58:47 -0000 Received: (qmail 25427 invoked by uid 500); 22 Dec 2004 23:58:47 -0000 Received: (qmail 25421 invoked by uid 99); 22 Dec 2004 23:58:47 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 22 Dec 2004 15:58:46 -0800 Received: (qmail 31303 invoked by uid 1813); 22 Dec 2004 23:58:45 -0000 Date: 22 Dec 2004 23:58:45 -0000 Message-ID: <20041222235845.31302.qmail@minotaur.apache.org> From: rogerrut@apache.org To: jakarta-jetspeed-2-cvs@apache.org Subject: cvs commit: jakarta-jetspeed-2/portals-bridges/perl/src/java/org/apache/portals/bridges/perl PerlPortlet.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N rogerrut 2004/12/22 15:58:45 Modified: portals-bridges/perl/src/java/org/apache/portals/bridges/perl PerlPortlet.java Log: Added cache and state so that multiple perl portlets could be on the same page displaying different content Revision Changes Path 1.3 +63 -34 jakarta-jetspeed-2/portals-bridges/perl/src/java/org/apache/portals/bridges/perl/PerlPortlet.java Index: PerlPortlet.java =================================================================== RCS file: /home/cvs/jakarta-jetspeed-2/portals-bridges/perl/src/java/org/apache/portals/bridges/perl/PerlPortlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PerlPortlet.java 8 Nov 2004 22:30:54 -0000 1.2 +++ PerlPortlet.java 22 Dec 2004 23:58:45 -0000 1.3 @@ -1,4 +1,4 @@ -/* + /* * Copyright 2000-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -70,11 +70,25 @@ * DemoMode on or off */ public static final String PARAM_DEMO_MODE = "DemoMode"; + + /** + * PARAM_APPLICATION + * + * ApplicationName identifies the caller so that the portlet only refreshes + * content that was supposed for the portlet. + * If the application name is undefined the portlet will process the request. + * If you have more than one perl-portlet for the same user/session all the portlets + * will be refreshed with the same content. + */ + public static final String PARAM_APPLICATION = "Application"; // Local variables private String perlScript = "perl-demo.cgi"; private String scriptPath = "cgi-bin"; + + private String applicationName = null; + // Switch that shows basic information about the perl script to run private boolean bDemoMode = false; @@ -84,6 +98,9 @@ // caching status -- cache the last query private String lastQuery = null; + // Cache the last generated page + String lastPage = null; + public void init(PortletConfig config) throws PortletException { @@ -94,7 +111,8 @@ // throw an exception scriptPath = config.getInitParameter(PARAM_SCRIPT_PATH); perlScript = config.getInitParameter(PARAM_PERL_SCRIPT); - String demoMode = config.getInitParameter(PARAM_DEMO_MODE); + String demoMode = config.getInitParameter(PARAM_DEMO_MODE); + applicationName = config.getInitParameter(PARAM_APPLICATION); if (demoMode != null && demoMode.compareToIgnoreCase("on") == 0) bDemoMode = true; @@ -131,7 +149,8 @@ { // Perl Parameter Object PerlParameters cgi = new PerlParameters(); - + cgi.setApplicationName(this.applicationName); + // Separate the values before and after the Query Mark ? int ixQuery = perlParameter.indexOf('?'); if ( ixQuery != -1) @@ -206,38 +225,44 @@ PerlParameters perlParam = null; /** - * The Perl parameters are either passed by a session attribute (invoked through an action) or as a query string (invoked from the cgi itself). - * The portlet checks first for the query (navigation inside the perl portlet) and then if a session attribute (SELECTED_VIEW) was defined. + * The Perl parameters are either passed by a session attribute (invoked from a different portlet) or as an action which is replaced + * with a session while processing actions.. */ + + try + { + perlParam = (PerlParameters)request.getPortletSession().getAttribute(PerlParameters.PERL_PARAMETER, PortletSession.APPLICATION_SCOPE); + } + catch (Exception e ) + { + perlParam = null; + } - // Extract the Query string -- Request initiated from inside the CGI script. This allows navigation within the CGI - String queryString = ((HttpServletRequest)((HttpServletRequestWrapper) request).getRequest()).getQueryString(); - - if (queryString != null) + if (perlParam != null) { - query = queryString; - - // Find the perl script -- last argument - String url = ((HttpServletRequest)((HttpServletRequestWrapper) request).getRequest()).getRequestURI(); - perlScript = url.substring(url.lastIndexOf('/')+1); - } - else - { - try - { - perlParam = (PerlParameters)request.getPortletSession().getAttribute(PerlParameters.PERL_PARAMETER, PortletSession.APPLICATION_SCOPE); - } - catch (Exception e ) - { - perlParam = null; - } - - if (perlParam != null) - { + // Only use the values if the call is designated to this script + if (perlParam.getApplicationName().compareToIgnoreCase(this.applicationName) == 0) + { query = perlParam.getQueryString(); perlScript = perlParam.getScriptName(); - - } + } + + if (this.applicationName == null ) // not yet initialized + { + this.applicationName = perlParam.getApplicationName(); + } + else + { + // If the application name doesn't match just use the cached version and return + if ( lastPage != null // has run at least once + && this.applicationName != null // No filtering runs for any perl request + && perlParam.getApplicationName().compareToIgnoreCase(this.applicationName) != 0) + { + // Use cache + writer.println(this.lastPage); + return; + } + } } // Open the perl script and extract the perl executable path. It's the same way as apache HTTP executes PERL @@ -248,9 +273,10 @@ contextPath = pathTranslated.substring(0, pathTranslated.indexOf("webapps") + 7) + contextPath + "/"; contextPath += scriptPath; - - contextPath += "/"; - String inputPath = contextPath; + + // Build full path to scripts + if (perlScript.startsWith("/") == false ) + contextPath += "/"; contextPath += perlScript; // command to execute @@ -374,6 +400,9 @@ // Write the page writer.println(finalPage); + + // Cache page + lastPage = new String(finalPage); } catch(IOException ioe) { --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org