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 2001/11/07 23:11:58 UTC
cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets WebPagePortlet.java
paulsp 01/11/07 14:11:58
Modified: src/java/org/apache/jetspeed/portal/portlets
WebPagePortlet.java
Log:
Include the following fixes (Thanks David for the patch):
1) init() no longer gets the content from the web server
2) getContent() now gets content from web server if the content not in
cache, otherwise return the cached content.
Revision Changes Path
1.6 +75 -9 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebPagePortlet.java 2001/10/18 18:17:40 1.5
+++ WebPagePortlet.java 2001/11/07 22:11:58 1.6
@@ -84,19 +84,24 @@
*
*@author <a href="mailto:rammer@sycom.at">Ingo Rammer</a>
*@author <a href="mailto:sgala@apache.org">Santiago Gala</a>
+ *@author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
*/
public class WebPagePortlet extends AbstractPortlet {
+ HTMLRewriter rewriter = null;
+ boolean pageCached = false;
+
public void init() throws PortletException {
+
+ if (pageCached) // Why is init called more than once per portlet?
+ return;
+
PortletConfig config = this.getPortletConfig();
- String convertedString; // parsed and re-written HTML
-
try
{
- Reader htmlReader = getReader( config.getURL() );
//FIXME: HTMLRewriter should take a Reader, and work
- convertedString = new HTMLRewriter(
+ rewriter = new HTMLRewriter(
! config.getInitParameter("dont_remove_script","no")
.equalsIgnoreCase("yes"),
! config.getInitParameter("dont_remove_style","no")
@@ -113,9 +118,9 @@
.equalsIgnoreCase("yes"),
! config.getInitParameter("dont_remove_onsomething","no")
.equalsIgnoreCase("yes")
- ).convertURLs(htmlReader,config.getURL());
+ );
- this.setContent( new ClearElement(convertedString));
+ Log.debug("*** Created rewriter for " + config.getURL() );
} catch (Exception e) {
Log.info("Exception occurred:" + e.toString());
@@ -130,8 +135,8 @@
*/
// FIXME: Currently only the expiration the HTTP Reponse header is honored.
// Expiration information in <meta> tags are not honored
- private Reader getReader(String url) throws IOException {
-
+ private Reader getReader(String url) throws IOException
+ {
URL pageUrl = new URL(url);
URLConnection pageConn = pageUrl.openConnection();
long pageExpiration = pageConn.getExpiration();
@@ -160,10 +165,71 @@
}
/**
- */
+
public boolean isCacheable() {
return getExpirationMillis() != null;
}
+ */
+
+ /**
+ 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 )
+ {
+ PortletConfig config = this.getPortletConfig();
+
+ try
+ {
+ if (pageCached)
+ {
+ Log.debug("[cached] in getContent for " + config.getURL() );
+
+ if (null == getExpirationMillis())
+ return getContent( data, null, true);
+
+ if (getExpirationMillis().longValue() < System.currentTimeMillis())
+ return getWebPageContent(data, config);
+
+ return getContent( data, null , true );
+ }
+ Log.debug("[not cached] in getContent for " + config.getURL() );
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ // cache page first time
+ return getWebPageContent(data, config);
+ }
+
+ private ConcreteElement getWebPageContent( RunData data, PortletConfig config )
+ {
+
+ String convertedString; // parsed and re-written HTML
+ ClearElement element = null;
+
+ try
+ {
+ Reader htmlReader = getReader( config.getURL() );
+ //FIXME: HTMLRewriter should take a Reader, and work
+ convertedString = rewriter.convertURLs(htmlReader, config.getURL());
+ Log.debug("converted URL: " + config.getURL() );
+ pageCached = true;
+ element = new ClearElement(convertedString);
+ this.setContent(element);
+
+ } catch (Exception e) {
+ Log.info("Exception occurred:" + e.toString());
+ e.printStackTrace();
+// throw new PortletException( e.toString() );
+ }
+
+ return element;
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>