sgala 01/10/18 11:17:40
Modified: src/java/org/apache/jetspeed/util HTMLRewriter.java
src/java/org/apache/jetspeed/portal/portlets
AbstractPortlet.java WebPagePortlet.java
Log:
Patches to use Reader in WebPagePortlet, also to handle content caching in
AbstractPortlet in the general case (was using a null key, now default CapabilityMap
for coherent behaviour). Also, added security checks for some properties and cleaned
deprecations.
Revision Changes Path
1.5 +6 -6
jakarta-jetspeed/src/java/org/apache/jetspeed/util/HTMLRewriter.java
Index: HTMLRewriter.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/util/HTMLRewriter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HTMLRewriter.java 2001/03/07 06:49:52 1.4
+++ HTMLRewriter.java 2001/10/18 18:17:40 1.5
@@ -106,7 +106,8 @@
/**
*
* @author Ingo Rammer ([EMAIL PROTECTED])
- * @version 0.1
+ * @author <a href="mailto:[EMAIL PROTECTED]">Santiago Gala</a>
+ * @version 0.2
*/
public class HTMLRewriter {
@@ -142,8 +143,8 @@
cb.removeOnSomething = removeOnSomething;
}
-/** Does the conversion of the HTML-String
- * @param HTML HTML-String to be converted
+/** Does the conversion of the HTML
+ * @param HTMLrdr Reader for HTML to be converted
* @param BaseUrl URL from which this HTML was taken. We be the base-Url
* for all URL-rewritings.
* @throws MalformedURLException If the BaseUrl is not a valid URL or if an URL
inside
@@ -152,14 +153,13 @@
* @return HTML-String with rewritten URLs and removed (according
* to constructor-settings) tags
*/
- public synchronized String convertURLs(String HTML, String BaseUrl) throws
MalformedURLException
+ public synchronized String convertURLs(Reader HTMLrdr, String BaseUrl) throws
MalformedURLException
{
HTMLEditorKit.Parser parse = new HTMLRewriter.ParserGetter().getParser();
- StringReader read = new StringReader(HTML);
String res ="";
try {
cb.baseUrl = new URL(BaseUrl);
- parse.parse(read,cb,true);
+ parse.parse(HTMLrdr,cb,true);
res = cb.getResult();
} catch (Exception e)
{
1.47 +57 -13
jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/AbstractPortlet.java
Index: AbstractPortlet.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/portlets/AbstractPortlet.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- AbstractPortlet.java 2001/10/07 12:29:15 1.46
+++ AbstractPortlet.java 2001/10/18 18:17:40 1.47
@@ -66,6 +66,7 @@
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.om.registry.MediaTypeEntry;
+import org.apache.jetspeed.services.JetspeedSecurity;
//ecs
import org.apache.ecs.*;
@@ -92,7 +93,8 @@
@author <A HREF="mailto:[EMAIL PROTECTED]">Kevin A. Burton</A>
@author <A HREF="mailto:[EMAIL PROTECTED]">Rapha�l Luta</A>
-@version $Id: AbstractPortlet.java,v 1.46 2001/10/07 12:29:15 paulsp Exp $
+@author <A HREF="mailto:[EMAIL PROTECTED]">Santiago Gala</A>
+@version $Id: AbstractPortlet.java,v 1.47 2001/10/18 18:17:40 sgala Exp $
*/
public abstract class AbstractPortlet implements Portlet, PortletState, Cacheable
{
@@ -239,7 +241,7 @@
if (!(config instanceof PortletConfig))
{
return null;
-
+
}
// By default, only take into account the init parameters
@@ -276,7 +278,7 @@
public ConcreteElement getContent( RunData rundata, CapabilityMap map ) {
CapabilityMap mymap = map;
if ( mymap == null ) mymap = CapabilityMapFactory.getCapabilityMap( rundata
);
-
+
return (ConcreteElement)content.get( mymap.toString() );
}
@@ -286,6 +288,14 @@
CapabilityMap map,
boolean allowRecurse ) {
+ if (!JetspeedSecurity.checkPermission(rundata,
+ JetspeedSecurity.PERMISSION_VIEW,
+ this))
+ {
+ return new ClearElement("Sorry, you have no permission to see this
portlet");
+ }
+
+
CapabilityMap mymap = map;
if ( mymap == null ) mymap = CapabilityMapFactory.getCapabilityMap( rundata
);
@@ -302,7 +312,7 @@
this.setContent( element, mymap );
}
} catch (Exception e) {
- element = new StringElement("Error when retrieving Portlet
contents");
+ element = new ClearElement("Error when retrieving Portlet
contents");
}
} else {
if( element == null ) {
@@ -310,7 +320,7 @@
mymap = CapabilityMapFactory.getDefaultCapabilityMap();
element = (ConcreteElement)content.get( mymap.toString() );
if( element == null ) {
- element = new ClearElement("");
+ element = new ClearElement("Unknown Problem getting
Contents");
}
}
}
@@ -329,13 +339,15 @@
/**
*/
protected void setContent( ConcreteElement content ) {
- this.setContent( content, null );
+ this.setContent( content,
+ CapabilityMapFactory.getDefaultCapabilityMap() );
}
/**
*/
protected void setContent( String content ) {
- this.setContent( new ClearElement( content ), null );
+ this.setContent( new ClearElement( content ),
+ CapabilityMapFactory.getDefaultCapabilityMap() );
}
/**
@@ -492,7 +504,14 @@
*/
public boolean allowClose( RunData rundata )
{
- return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
+ if ( (rundata.getUser() == null) || !rundata.getUser().hasLoggedIn() )
+ {
+ return false; //No permission if user not logged in
+ }
+ return (JetspeedSecurity.checkPermission(rundata,
+ JetspeedSecurity.PERMISSION_CLOSE,
+ this));
+
}
/**
@@ -525,7 +544,13 @@
*/
public boolean allowInfo( RunData rundata )
{
- return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
+ if ( (rundata.getUser() == null) || !rundata.getUser().hasLoggedIn() )
+ {
+ return false; //No permission if user not logged in
+ }
+ return (JetspeedSecurity.checkPermission(rundata,
+ JetspeedSecurity.PERMISSION_INFO,
+ this));
}
/**
@@ -536,7 +561,13 @@
*/
public boolean allowCustomize( RunData rundata )
{
- return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
+ if ( (rundata.getUser() == null) || !rundata.getUser().hasLoggedIn() )
+ {
+ return false; //No permission if user not logged in
+ }
+ return (JetspeedSecurity.checkPermission(rundata,
+
JetspeedSecurity.PERMISSION_CUSTOMIZE,
+ this));
}
/**
@@ -547,7 +578,13 @@
*/
public boolean allowMaximize( RunData rundata )
{
- return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
+ if ( (rundata.getUser() == null) || !rundata.getUser().hasLoggedIn() )
+ {
+ return false; //No permission if user not logged in
+ }
+ return (JetspeedSecurity.checkPermission(rundata,
+
JetspeedSecurity.PERMISSION_MAXIMIZE,
+ this));
}
/**
@@ -558,7 +595,14 @@
*/
public boolean allowMinimize( RunData rundata )
{
- return ( (rundata.getUser() != null) && rundata.getUser().hasLoggedIn() );
+ if ( (rundata.getUser() == null) || !rundata.getUser().hasLoggedIn() )
+ {
+ return false; //No permission if user not logged in
+ }
+ return (JetspeedSecurity.checkPermission(rundata,
+
JetspeedSecurity.PERMISSION_MINIMIZE,
+ this));
+
}
/**
@@ -611,7 +655,7 @@
}
catch ( Exception e )
{
- Log.error("Exception while retrieving attribute "+attrName+" for
portlet "+getName(),e);
+ Log.debug("Exception while retrieving attribute "+attrName+" for
portlet "+getName(),e);
attrValue = attrDefValue ;
}
1.5 +38 -31
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebPagePortlet.java 2001/10/15 03:38:19 1.4
+++ WebPagePortlet.java 2001/10/18 18:17:40 1.5
@@ -63,7 +63,6 @@
//Jetspeed stuff
import org.apache.jetspeed.portal.*;
import org.apache.jetspeed.util.*;
-import org.apache.jetspeed.cache.disk.*;
//turbine
@@ -80,22 +79,23 @@
/**
-
-@author <a href="mailto:[EMAIL PROTECTED]">Ingo Rammer</a>
-
+ * A class that loads a web page and filters it to have certain features
+ * deleted.
+ *
+ *@author <a href="mailto:[EMAIL PROTECTED]">Ingo Rammer</a>
+ *@author <a href="mailto:[EMAIL PROTECTED]">Santiago Gala</a>
*/
-public class WebPagePortlet extends FileWatchPortlet {
+public class WebPagePortlet extends AbstractPortlet {
public void init() throws PortletException {
PortletConfig config = this.getPortletConfig();
- String htmlString; // original content
String convertedString; // parsed and re-written HTML
try
{
- htmlString = getURL( JetspeedDiskCache.getInstance()
- .getEntry( config.getURL() ).getURL() );
+ Reader htmlReader = getReader( config.getURL() );
+ //FIXME: HTMLRewriter should take a Reader, and work
convertedString = new HTMLRewriter(
! config.getInitParameter("dont_remove_script","no")
.equalsIgnoreCase("yes"),
@@ -113,12 +113,12 @@
.equalsIgnoreCase("yes"),
! config.getInitParameter("dont_remove_onsomething","no")
.equalsIgnoreCase("yes")
- ).convertURLs(htmlString,config.getURL());
+ ).convertURLs(htmlReader,config.getURL());
this.setContent( new ClearElement(convertedString));
} catch (Exception e) {
- Log.note("Exception occurred:" + e.toString());
+ Log.info("Exception occurred:" + e.toString());
e.printStackTrace();
throw new PortletException( e.toString() );
}
@@ -130,33 +130,40 @@
*/
// FIXME: Currently only the expiration the HTTP Reponse header is honored.
// Expiration information in <meta> tags are not honored
- private String getURL(String url) throws IOException {
+ private Reader getReader(String url) throws IOException {
- int CAPACITY = 1024;
URL pageUrl = new URL(url);
URLConnection pageConn = pageUrl.openConnection();
- long pageExpiration = 0;
- InputStream is = pageConn.getInputStream();
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
- //now process the InputStream...
- byte[] bytes = new byte[CAPACITY];
-
- int readCount = 0;
- while( ( readCount = is.read( bytes )) > 0 ) {
-
- buffer.write( bytes, 0, readCount);
+ long pageExpiration = pageConn.getExpiration();
+ String encoding = pageConn.getContentEncoding();
+ if(encoding == null)
+ {
+ // Standard HTTP encoding
+ encoding = "iso-8859-1";
}
-
- pageExpiration = pageConn.getExpiration();
- is.close();
-
+ Reader rdr = new InputStreamReader(pageConn.getInputStream(),
+ encoding );
// Only set the page expiration it the page has not expired
- if (pageExpiration > System.currentTimeMillis()) {
- Log.debug( "WebPagePortlet caching URL: " + url + " Expiration: " +
pageExpiration);
- setExpirationMillis(pageExpiration);
+ if (pageExpiration > System.currentTimeMillis())
+ {
+ Log.debug( "WebPagePortlet caching URL: " +
+ url +
+ " Expiration: " +
+ pageExpiration +
+ ", " +
+ (pageExpiration - System.currentTimeMillis() ) +
+ " milliseconds into the future" );
+ setExpirationMillis(pageExpiration);
}
- return buffer.toString();
+ return rdr;
}
+
+ /**
+ */
+ public boolean isCacheable() {
+ return getExpirationMillis() != null;
+ }
+
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]