Author: julien(a)jboss.com
Date: 2008-02-27 20:18:35 -0500 (Wed, 27 Feb 2008)
New Revision: 10149
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/cache/CacheControl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/CacheControlImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
Log:
make FragmentResponse and CacheControl immutables
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/cache/CacheControl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/cache/CacheControl.java 2008-02-28
00:25:00 UTC (rev 10148)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/cache/CacheControl.java 2008-02-28
01:18:35 UTC (rev 10149)
@@ -30,13 +30,13 @@
{
/** Number of seconds this result remains valid, a value of -1 indicates that it never
expires. */
- private int expirationSecs;
+ private final int expirationSecs;
/** The cache scope for this fragment. */
- private CacheScope cacheScope;
+ private final CacheScope cacheScope;
/** The validation token. */
- private String validationToken;
+ private final String validationToken;
public CacheControl(int expirationSecs, CacheScope cacheScope, String
validationToken)
{
@@ -50,49 +50,13 @@
return expirationSecs;
}
- public void setExpirationSecs(int expirationSecs)
- {
- this.expirationSecs = expirationSecs;
- }
-
public CacheScope getCacheScope()
{
return cacheScope;
}
- public void setCacheScope(CacheScope cacheScope)
- {
- this.cacheScope = cacheScope;
- }
-
public String getValidationToken()
{
return validationToken;
}
-
- public void setValidationToken(String validationToken)
- {
- this.validationToken = validationToken;
- }
-
- public CacheControl unmodifiable()
- {
- return new CacheControl(expirationSecs, cacheScope, validationToken)
- {
- public void setCacheScope(CacheScope cacheScope)
- {
- throw new UnsupportedOperationException("Not modifiable");
- }
-
- public void setValidationToken(String token)
- {
- throw new UnsupportedOperationException("Not modifiable");
- }
-
- public void setExpirationSecs(int expirationSecs)
- {
- throw new UnsupportedOperationException("Not modifiable");
- }
- };
- }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java 2008-02-28
00:25:00 UTC (rev 10148)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/ContentBuffer.java 2008-02-28
01:18:35 UTC (rev 10149)
@@ -227,10 +227,6 @@
*/
public void commit() throws IllegalStateException
{
-// if (contentType == null)
-// {
-// throw new IllegalStateException("No content type defined");
-// }
commited = true;
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/CacheControlImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/CacheControlImpl.java 2008-02-28
00:25:00 UTC (rev 10148)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/CacheControlImpl.java 2008-02-28
01:18:35 UTC (rev 10149)
@@ -34,44 +34,53 @@
{
/** . */
- private org.jboss.portal.portlet.cache.CacheControl delegate;
+ private boolean useCachedContent;
/** . */
- private boolean useCachedContent;
+ private int expirationSecs;
- public CacheControlImpl(org.jboss.portal.portlet.cache.CacheControl delegate)
+ /** . */
+ private CacheScope cacheScope;
+
+ /** . */
+ private String validationToken;
+
+ public CacheControlImpl(int expirationSecs, CacheScope cacheScope)
{
- this.delegate = delegate;
+ this.useCachedContent = false;
+ this.expirationSecs = expirationSecs;
+ this.cacheScope = cacheScope;
+ this.validationToken = null;
}
public int getExpirationTime()
{
- return delegate.getExpirationSecs();
+ return expirationSecs;
}
public void setExpirationTime(int expirationTime)
{
- delegate.setExpirationSecs(expirationTime);
+ this.expirationSecs = expirationTime;
}
public boolean isPublicScope()
{
- return delegate.getCacheScope() == CacheScope.PUBLIC;
+ return cacheScope == CacheScope.PUBLIC;
}
public void setPublicScope(boolean publicScope)
{
- delegate.setCacheScope(publicScope ? CacheScope.PUBLIC : CacheScope.PRIVATE);
+ cacheScope = publicScope ? CacheScope.PUBLIC : CacheScope.PRIVATE;
}
public String getETag()
{
- return delegate.getValidationToken();
+ return validationToken;
}
public void setETag(String etag)
{
- delegate.setValidationToken(etag);
+ this.validationToken = etag;
}
public boolean useCachedContent()
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-02-28
00:25:00 UTC (rev 10148)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/MimeResponseImpl.java 2008-02-28
01:18:35 UTC (rev 10149)
@@ -29,6 +29,8 @@
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.info.CacheInfo;
import org.jboss.portal.portlet.cache.CacheScope;
+import org.jboss.portal.portlet.impl.jsr168.ContentBuffer;
+import org.jboss.portal.Mode;
import javax.portlet.MimeResponse;
import javax.portlet.PortletURL;
@@ -38,6 +40,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.util.Locale;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -46,9 +49,6 @@
public abstract class MimeResponseImpl extends PortletResponseImpl implements
MimeResponse
{
- /** The fragment result. */
- protected FragmentResponse fragment;
-
/** Not really used but we need it to memorize what the client set optionally. */
protected int bufferSize;
@@ -58,82 +58,104 @@
/** . */
private boolean contentTypeSet;
+ /** The title if any. */
+ protected String responseTitle;
+
+ /** . */
+ private ContentBuffer responseContent;
+
+ /** . */
+ protected Set<Mode> responseNextModes;
+
public MimeResponseImpl(PortletInvocation invocation, PortletRequestImpl preq)
{
super(invocation, preq);
- //
- FragmentResponse fragment = new FragmentResponse();
-
// Configure expiration value
PortletInfo info = preq.container.getInfo();
CacheInfo cacheInfo = info.getCache();
-
org.jboss.portal.portlet.cache.CacheControl cc = new
org.jboss.portal.portlet.cache.CacheControl(
cacheInfo.getExpirationSecs(),
CacheScope.PRIVATE,
null
);
- //
- fragment.setCacheControl(cc);
-
// 0 means no buffering - we say no buffering
this.bufferSize = 0;
- this.fragment = fragment;
this.contentTypeSet = false;
+ this.responseContent = new ContentBuffer();
+ this.responseTitle = null;
+ this.responseNextModes = null;
}
public PortletInvocationResponse getResponse()
{
- if (cacheControl != null && cacheControl.useCachedContent())
+ org.jboss.portal.portlet.cache.CacheControl cc;
+ if (cacheControl != null)
{
- return new RevalidateMarkupResponse(fragment.getCacheControl());
+ cc = new org.jboss.portal.portlet.cache.CacheControl(
+ cacheControl.getExpirationTime(),
+ cacheControl.isPublicScope() ? CacheScope.PUBLIC : CacheScope.PRIVATE,
+ cacheControl.getETag());
}
else
{
- fragment.setProperties(getProperties(false));
- fragment.setAttributes(preq.attributes.getAttributeMap());
+ PortletInfo info = preq.container.getInfo();
+ CacheInfo cacheInfo = info.getCache();
+ cc = new
org.jboss.portal.portlet.cache.CacheControl(cacheInfo.getExpirationSecs(),
CacheScope.PRIVATE, null);
+ }
- //
- return fragment;
+ //
+ if (cacheControl != null && cacheControl.useCachedContent())
+ {
+ return new RevalidateMarkupResponse(cc);
}
+ else
+ {
+ return new FragmentResponse(
+ getProperties(false),
+ preq.attributes.getAttributeMap(),
+ responseContent,
+ responseTitle,
+ cc,
+ responseNextModes != null ? responseNextModes : preq.supportedModes);
+ }
}
public String getContentType()
{
- return contentTypeSet ? fragment.getContentType() : null;
+ return contentTypeSet ? responseContent.getContentType() : null;
}
public void setContentType(String contentType)
{
- if (fragment.getContentType() == null)
+ if (responseContent.getContentType() == null)
{
- fragment.setContentType(contentType);
+ responseContent.setContentType(contentType);
contentTypeSet = true;
}
}
public PrintWriter getWriter() throws IOException
{
- if (fragment.getContentType() == null)
+ if (responseContent.getContentType() == null)
{
- fragment.setContentType(preq.getResponseContentType());
+ responseContent.setContentType(preq.getResponseContentType());
}
//
- return fragment.getWriter();
+ return responseContent.getWriter();
}
public OutputStream getPortletOutputStream() throws IOException
{
- if (fragment.getContentType() == null)
+ if (responseContent.getContentType() == null)
{
- fragment.setContentType(preq.getResponseContentType());
+ responseContent.setContentType(preq.getResponseContentType());
}
//
- return fragment.getOutputStream();
+ return responseContent.getOutputStream();
}
public PortletURL createRenderURL()
@@ -171,13 +193,13 @@
public void flushBuffer() throws IOException
{
- fragment.getBuffer().commit();
+ responseContent.commit();
}
public void resetBuffer()
{
// Clear the buffer
- fragment.resetBuffer();
+ responseContent.reset();
}
public void reset()
@@ -193,7 +215,7 @@
public boolean isCommitted()
{
- return fragment.getBuffer().isCommited();
+ return responseContent.isCommited();
}
public ResourceURL createResourceURL()
@@ -210,7 +232,7 @@
try
{
int expirationSecs = Integer.parseInt(value);
- fragment.getCacheControl().setExpirationSecs(expirationSecs);
+ getCacheControl().setExpirationTime(expirationSecs);
}
catch (NumberFormatException e)
{
@@ -224,7 +246,7 @@
{
if (value != null)
{
- fragment.getCacheControl().setValidationToken(value);
+ getCacheControl().setETag(value);
}
}
else if (MimeResponse.USE_CACHED_CONTENT.equals(key))
@@ -244,7 +266,9 @@
{
if (cacheControl == null)
{
- cacheControl = new CacheControlImpl(fragment.getCacheControl());
+ PortletInfo info = preq.container.getInfo();
+ CacheInfo cacheInfo = info.getCache();
+ cacheControl = new CacheControlImpl(cacheInfo.getExpirationSecs(),
CacheScope.PRIVATE);
}
return cacheControl;
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-02-28
00:25:00 UTC (rev 10148)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/RenderResponseImpl.java 2008-02-28
01:18:35 UTC (rev 10149)
@@ -50,25 +50,22 @@
super(invocation, preq);
}
- /** . */
- private Set<Mode> nextModes;
-
- public void setTitle(String s)
+ public void setTitle(String title)
{
- fragment.setTitle(s);
+ this.responseTitle = title;
}
public void setNextPossiblePortletModes(Collection<PortletMode> portletModes)
{
if (portletModes != null && portletModes.size() > 0)
{
- if (this.nextModes == null)
+ if (responseNextModes == null)
{
- nextModes = new LinkedHashSet<Mode>(portletModes.size());
+ responseNextModes = new LinkedHashSet<Mode>(portletModes.size());
}
else
{
- nextModes.clear();
+ responseNextModes.clear();
}
//
@@ -81,7 +78,7 @@
//
if (preq.supportedModes.contains(mode))
{
- nextModes.add(mode);
+ responseNextModes.add(mode);
}
}
else
@@ -145,16 +142,4 @@
throw ex;
}
}
-
- public PortletInvocationResponse getResponse()
- {
- PortletInvocationResponse response = super.getResponse();
- if (response instanceof FragmentResponse)
- {
- FragmentResponse fragment = (FragmentResponse)response;
- fragment.setNextModes(nextModes != null ? nextModes : preq.supportedModes);
- }
- return response;
- }
-
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-02-28
00:25:00 UTC (rev 10148)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/invocation/response/FragmentResponse.java 2008-02-28
01:18:35 UTC (rev 10149)
@@ -52,31 +52,31 @@
public static final int TYPE_BYTES = ContentBuffer.TYPE_BYTES;
/** . */
- private ResponseProperties properties;
+ private final ResponseProperties properties;
/** . */
- private Map<String, Object> attributes;
+ private final Map<String, Object> attributes;
/** . */
- private ContentBuffer buffer;
+ private final ContentBuffer buffer;
/** The title if any. */
- private String title;
+ private final String title;
/** . */
- private CacheControl cacheControl;
+ private final CacheControl cacheControl;
/** . */
- private Set<Mode> nextModes;
+ private final Set<Mode> nextModes;
- public FragmentResponse()
+ public FragmentResponse(ResponseProperties properties, Map<String, Object>
attributes, ContentBuffer buffer, String title, CacheControl cacheControl, Set<Mode>
nextModes)
{
- this.buffer = new ContentBuffer();
- this.title = null;
- this.cacheControl = null;
- this.properties = null;
- this.nextModes = null;
- this.attributes = null;
+ this.properties = properties;
+ this.attributes = attributes;
+ this.buffer = buffer;
+ this.title = title;
+ this.cacheControl = cacheControl;
+ this.nextModes = nextModes;
}
public ResponseProperties getProperties()
@@ -84,31 +84,16 @@
return properties;
}
- public void setProperties(ResponseProperties properties)
- {
- this.properties = properties;
- }
-
public CacheControl getCacheControl()
{
return cacheControl;
}
- public void setCacheControl(CacheControl cacheControl)
- {
- this.cacheControl = cacheControl;
- }
-
public Map<String, Object> getAttributes()
{
return attributes;
}
- public void setAttributes(Map<String, Object> attributes)
- {
- this.attributes = attributes;
- }
-
public int getType()
{
return buffer.getType();
@@ -147,16 +132,6 @@
}
/**
- * Set the fragment title.
- *
- * @param title the new title
- */
- public void setTitle(String title)
- {
- this.title = title;
- }
-
- /**
* Return the content type of the generated fragment.
*
* @return the content type
@@ -167,16 +142,6 @@
}
/**
- * Set the fragment of the content type.
- *
- * @param contentType the content type
- */
- public void setContentType(String contentType)
- {
- buffer.setContentType(contentType);
- }
-
- /**
* Returns the writer.
*
* @return the writer
@@ -196,11 +161,6 @@
return buffer.getOutputStream();
}
- public void resetBuffer()
- {
- buffer.reset();
- }
-
public ContentBuffer getBuffer()
{
return buffer;
@@ -210,9 +170,4 @@
{
return nextModes;
}
-
- public void setNextModes(Set<Mode> nextModes)
- {
- this.nextModes = nextModes;
- }
}