Author: cziegeler
Date: Wed Aug 22 12:36:04 2012
New Revision: 1376018
URL: http://svn.apache.org/viewvc?rev=1376018&view=rev
Log:
SLING-2546 : Add Support JSR 168 portlet caching to Sling Portal Container.
Apply patch from Antonio Sanso
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
(with props)
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
(with props)
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
(with props)
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
(with props)
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
(with props)
Modified:
sling/whiteboard/portal/container/pom.xml
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/SlingPortletWindow.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/DefaultPortletContainer.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletContainerImpl.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletRenderResponseContextImpl.java
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletWindowImpl.java
Modified: sling/whiteboard/portal/container/pom.xml
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/pom.xml?rev=1376018&r1=1376017&r2=1376018&view=diff
==============================================================================
--- sling/whiteboard/portal/container/pom.xml (original)
+++ sling/whiteboard/portal/container/pom.xml Wed Aug 22 12:36:04 2012
@@ -50,6 +50,14 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-scr-descriptor</id>
+ <goals>
+ <goal>scr</goal>
+ </goals>
+ </execution>
+ </executions>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
@@ -70,10 +78,11 @@
</Import-Package>
<Export-Package>
org.apache.sling.portal.container,
+ org.apache.sling.portal.container.cache,
org.apache.sling.portal.container.spi;version:=1.0
</Export-Package>
<Private-Package>
- org.apache.sling.portal.container.internal,
+ org.apache.sling.portal.container.internal,
org.apache.sling.portal.container.internal.impl,
org.apache.sling.portal.container.internal.request,
org.apache.sling.portal.container.internal.services,
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java?rev=1376018&view=auto
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
(added)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
Wed Aug 22 12:36:04 2012
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.portal.container;
+
+import java.io.PrintWriter;
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+
+public interface PortletContent {
+
+ /**
+ * Get a writer to the content to stream content into this object
+ * @return
+ */
+ PrintWriter getWriter();
+
+ /**
+ * Retrieve the actual content of a portlet as a string
+ *
+ * @return
+ */
+ String getContent();
+
+ /**
+ * Gets the portlet mode of this portlet content.
+ *
+ * @return
+ */
+ PortletMode getPortletMode();
+
+ /**
+ * Gets the window state of this portlet content.
+ *
+ * @return
+ */
+ WindowState getWindowState();
+
+ /**
+ * Get the expiration setting for this content if it is cached.
+ * @return
+ */
+ int getExpiration();
+
+ /**
+ * Sets the expiration setting for this content.
+ *
+ * @param expiration
+ */
+ void setExpiration(int expiration);
+
+}
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/PortletContent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/SlingPortletWindow.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/SlingPortletWindow.java?rev=1376018&r1=1376017&r2=1376018&view=diff
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/SlingPortletWindow.java
(original)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/SlingPortletWindow.java
Wed Aug 22 12:36:04 2012
@@ -28,6 +28,11 @@ public interface SlingPortletWindow exte
SlingPortletEntity getPortletEntity();
ValueMap getConfiguration();
+
+ PortletContent getPortletContent();
+
+ void setPortletContent(PortletContent portletContent);
+
}
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java?rev=1376018&view=auto
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
(added)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
Wed Aug 22 12:36:04 2012
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.portal.container.cache;
+
+import java.util.Collection;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.pluto.container.PortletWindow;
+
+/**
+ * The <code>Cache</code> is an optional service for caching
+ * content.
+ * A content is identified by a unique key and is associated with
+ * a <code>CacheValue</code> storing meta information about the cached
+ * content.
+ * The cache has no knowledge about the content type it stores, therefore
+ * it is up to the client of the cache to generate unique cache keys. The
+ * <code>CacheKeyGenerator</code> service is used for this.
+ *
+ * Cached content can either be removed or the cache itself can have an
+ * internal mechanism to invalidate cached content (e.g. by using an epxires
+ * information).
+ */
+public interface Cache {
+
+ /**
+ * Get a cached value for the unique key.
+ * @param key The cache key
+ * @return The <code>CacheValue</code> or null if there is no valid content
+ * for the key.
+ */
+ CacheValue getCacheEntry(String key);
+
+ /**
+ * Put a cached content into the cache.
+ * @param key The cache key
+ * @param cachedResponse
+ */
+ void putCacheEntry(String key, CacheValue cachedResponse);
+
+ /**
+ * Remove the content with the unique key from the cache.
+ * @param key The cache key
+ * @return <code>true</code> if the content was removed.
+ */
+ boolean removeCacheEntry(String key);
+
+ /**
+ * Return all currently available keys.
+ * This collection might contain keys which might already have
+ * been expired.
+ * @return A collection of keys
+ */
+ Collection<String> getKeys();
+
+ /**
+ * Clear the cache.
+ */
+ void clearCache();
+
+ /**
+ * Generate a unique key
+ * @param portletWindow The request portletWindow.
+ * @param request The current HttpServletRequest .
+ * @return A cache key or <code>null</code>
+ */
+ String createCacheKey(PortletWindow portletWindow, HttpServletRequest
request);
+
+ /**
+ *
+ * @return the idle time in seconds for this cache
+ */
+ public long getTimeToIdleSeconds();
+
+ /**
+ *
+ * @return the idle time in seconds for this cache
+ */
+ public long getTimeToLiveSeconds();
+
+}
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/Cache.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java?rev=1376018&view=auto
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
(added)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
Wed Aug 22 12:36:04 2012
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.portal.container.cache;
+
+import javax.servlet.http.HttpServletRequest;
+import org.apache.pluto.container.PortletWindow;
+
+
+/**
+ * Generate a cache key for the current request.
+ */
+public interface CacheKeyGenerator {
+
+ /**
+ * Generate a unique key
+ * @param portletWindow The request portletWindow.
+ * @param request The current HttpServletRequest .
+ * @return A cache key or <code>null</code>
+ */
+ String generateCacheKey(PortletWindow portletWindow, HttpServletRequest
request);
+}
\ No newline at end of file
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheKeyGenerator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java?rev=1376018&view=auto
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
(added)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
Wed Aug 22 12:36:04 2012
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.portal.container.cache;
+
+import java.io.Serializable;
+import org.apache.sling.portal.container.PortletContent;
+
+/**
+ * The <code>CacheValue</code> represents a cached value in the
+ * <code>Cache</code>.
+ * A cached content is the content itself, a corresponding
+ * content type and character encoding.
+ * Additionally an expires value defining a date when the
+ * value expires. A value of zero 0 or a negativ value
+ * means the entry never expires.
+ */
+public class CacheValue implements Serializable {
+
+ /** The content type for the cached content. */
+ private String contentType;
+
+ /** The character encoding for the cached content. */
+ private String characterEncoding;
+
+ /** The cached content. */
+ private PortletContent portletContent;
+
+ private long timeToLive;
+ private long timeToIdle;
+
+
+ public CacheValue(PortletContent portletContent){
+ this.portletContent = portletContent;
+ }
+
+ /**
+ * Get the content type for the cached content.
+ * @return The content type
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Set the content type for the cached content.
+ * @param contentType The content type.
+ */
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ /**
+ * Get the character encoding of the content.
+ * @return The character encoding or <code>null</code>
+ */
+ public String getCharacterEncoding() {
+ return characterEncoding;
+ }
+
+ /**
+ * Set the character encoding for the content.
+ * @param characterEncoding The encoding.
+ */
+ public void setCharacterEncoding(String characterEncoding) {
+ this.characterEncoding = characterEncoding;
+ }
+
+ /**
+ * Get the cached content.
+ * @return The cached content.
+ */
+ public PortletContent getContent() {
+ return portletContent;
+ }
+
+ /**
+ * Set the cached content.
+ * @param content The content.
+ */
+ public void setContent(PortletContent portletContent) {
+ this.portletContent = portletContent;
+ }
+
+ /**
+ *
+ * @return the idle time in seconds for this cache element
+ */
+ public long getTimeToIdleSeconds(){
+ return timeToIdle;
+ }
+
+ /**
+ *
+ * @return the idle time in seconds for this cache element
+ */
+ public long getTimeToLiveSeconds(){
+ return timeToLive;
+ }
+
+ public void setTimeToLiveSeconds(long timeToLive){
+ this.timeToLive= timeToLive;
+ }
+
+ public void setTimeToIdleSeconds(long timeToIdle){
+ this.timeToIdle= timeToIdle;
+ }
+}
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/cache/CacheValue.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/DefaultPortletContainer.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/DefaultPortletContainer.java?rev=1376018&r1=1376017&r2=1376018&view=diff
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/DefaultPortletContainer.java
(original)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/DefaultPortletContainer.java
Wed Aug 22 12:36:04 2012
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRes
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.apache.pluto.container.ContainerInfo;
import org.apache.pluto.container.ContainerServices;
@@ -38,6 +39,7 @@ import org.apache.sling.portal.container
import org.apache.sling.portal.container.PortletWindowManager;
import org.apache.sling.portal.container.SlingPortletContainer;
import org.apache.sling.portal.container.SlingPortletWindow;
+import org.apache.sling.portal.container.cache.Cache;
import
org.apache.sling.portal.container.internal.services.DefaultContainerInfo;
import org.apache.sling.portal.container.spi.PortalEventCoordinatorService;
import org.osgi.framework.BundleContext;
@@ -66,6 +68,9 @@ public class DefaultPortletContainer imp
@Reference
private SlingRepository repository;
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY)
+ private Cache portletContentCache;
+
protected String containerName = "sling-portal";
protected String portalName = "Apache Sling Portal";
protected String portalVersion = "0.9.0";
@@ -112,7 +117,7 @@ public class DefaultPortletContainer imp
final ContainerServicesImpl containerServices = new
ContainerServicesImpl(ctx, info,
this.bundleContext,
this.repository);
- this.portletContainer = new PortletContainerImpl(info,
containerServices);
+ this.portletContainer = new PortletContainerImpl(info,
containerServices, portletContentCache);
if (!portletContainer.isInitialized()) {
logger.debug ("Initializing portlet container...");
Modified:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletContainerImpl.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletContainerImpl.java?rev=1376018&r1=1376017&r2=1376018&view=diff
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletContainerImpl.java
(original)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletContainerImpl.java
Wed Aug 22 12:36:04 2012
@@ -16,12 +16,28 @@
*/
package org.apache.sling.portal.container.internal;
+import java.io.IOException;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
import org.apache.pluto.container.ContainerInfo;
import org.apache.pluto.container.PortletContainerException;
+import org.apache.pluto.container.PortletWindow;
+import org.apache.pluto.container.om.portlet.PortletDefinition;
+import org.apache.sling.portal.container.PortletContent;
import org.apache.sling.portal.container.PortletRegistryService;
import org.apache.sling.portal.container.PortletWindowManager;
+import org.apache.sling.portal.container.SlingPortletConfig;
import org.apache.sling.portal.container.SlingPortletContainer;
+import org.apache.sling.portal.container.SlingPortletWindow;
import org.apache.sling.portal.container.api.PortletApplicationRegistry;
+import org.apache.sling.portal.container.cache.Cache;
+import org.apache.sling.portal.container.cache.CacheValue;
+import org.apache.sling.portal.container.internal.impl.PortletContentImpl;
import org.apache.sling.portal.container.spi.PortalEventCoordinatorService;
/**
@@ -38,14 +54,18 @@ public class PortletContainerImpl
/** Window Manager. */
private final PortletWindowManager windowManager;
+ /** Cache */
+ private Cache portletContentCache;
+
/**
* Constructor
* @param requiredServices The required services.
*/
- public PortletContainerImpl(ContainerInfo info, ContainerServicesImpl
requiredServices) {
+ public PortletContainerImpl(ContainerInfo info, ContainerServicesImpl
requiredServices, Cache portletContentCache) {
super(info.getPortletContainerName(), requiredServices);
this.registry = requiredServices.getPortletRegistryService();
this.windowManager = requiredServices.getPortletWindowManager();
+ this.portletContentCache=portletContentCache;
}
/**
@@ -85,4 +105,93 @@ public class PortletContainerImpl
public PortalEventCoordinatorService getPortalEventCoordinatorService() {
return
((ContainerServicesImpl)this.getContainerServices()).getPortalEventCoordinatorService();
}
+
+ public void doRender(final PortletWindow portletWindow,
+ final HttpServletRequest request,
+ final HttpServletResponse response)
+ throws PortletException, IOException, PortletContainerException {
+
+ final SlingPortletConfig config =
((SlingPortletWindow)portletWindow).getPortletEntity().getPortletConfig();
+ final PortletDefinition portletDD = config.getPortletDefinition();
+ int expirationCache=getExpirationCache(portletDD);
+
+ PortletContent portletContent=null;
+
+ if (portletContentCache!=null && expirationCache != 0){
+ //try to check if the content is already present in the cache
and is not expired
+ portletContent=retrieveCachedContent(portletWindow,request);
+ }
+
+ //if portletContent is null invoke handling method from the portlet
+ if (portletContent==null){
+ portletContent =
createPortletContent(portletWindow,expirationCache);
+
((SlingPortletWindow)portletWindow).setPortletContent(portletContent);
+ super.doRender(portletWindow, request, response);
+ if (portletContentCache!=null && portletContent.getExpiration() !=
0){
+ addToCache(portletContent,portletWindow,request);
+ }
+ }
+
+ response.getWriter().write(portletContent.getContent());
+ }
+
+
+ //TODO change me
+ public void doLoad(final PortletWindow portletWindow,
+ final HttpServletRequest request,
+ final HttpServletResponse response)
+ throws PortletException, IOException, PortletContainerException {
+
+ PortletContent portletContent = createPortletContent();
+ ((SlingPortletWindow)portletWindow).setPortletContent(portletContent);
+ super.doLoad(portletWindow, request, response);
+ }
+
+ protected PortletContent createPortletContent(){
+ PortletContent portletContent= new PortletContentImpl();
+ return portletContent;
+ }
+
+ protected PortletContent createPortletContent(final PortletWindow
portletWindow, int expirationCache){
+ PortletContent portletContent= new
PortletContentImpl(expirationCache,portletWindow.getPortletMode(),portletWindow.getWindowState());
+ return portletContent;
+ }
+
+ protected int getExpirationCache(PortletDefinition portletDefinition){
+ return portletDefinition == null ? 0 :
portletDefinition.getExpirationCache();
+ }
+
+ protected PortletContent retrieveCachedContent(final PortletWindow
portletWindow,final HttpServletRequest request){
+ String cacheKey = portletContentCache.createCacheKey(portletWindow,
request);
+ CacheValue cachedElement = portletContentCache.getCacheEntry(cacheKey);
+
+ if (cachedElement != null){
+ PortletContent portletContent = cachedElement.getContent();
+
+ PortletMode portletMode = portletContent.getPortletMode();
+ WindowState windowState = portletContent.getWindowState();
+
+ if (portletWindow.getPortletMode().equals(portletMode) &&
portletWindow.getWindowState().equals(windowState)){
+
((SlingPortletWindow)portletWindow).setPortletContent(portletContent);
+ return portletContent;
+ }
+ }
+
+ return null;
+ }
+
+ protected void addToCache(final PortletContent content,final PortletWindow
portletWindow, final HttpServletRequest request){
+
+ String cacheKey = portletContentCache.createCacheKey(portletWindow,
request);
+ CacheValue cacheValue = new CacheValue(content);
+
+ if (content.getExpiration() == -1){
+
cacheValue.setTimeToIdleSeconds(portletContentCache.getTimeToIdleSeconds());
+
cacheValue.setTimeToLiveSeconds(portletContentCache.getTimeToLiveSeconds());
+ }else{
+ cacheValue.setTimeToIdleSeconds(content.getExpiration());
+ cacheValue.setTimeToLiveSeconds(content.getExpiration());
+ }
+ portletContentCache.putCacheEntry(cacheKey, cacheValue);
+ }
}
Modified:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletRenderResponseContextImpl.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletRenderResponseContextImpl.java?rev=1376018&r1=1376017&r2=1376018&view=diff
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletRenderResponseContextImpl.java
(original)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/PortletRenderResponseContextImpl.java
Wed Aug 22 12:36:04 2012
@@ -33,6 +33,8 @@ import org.apache.pluto.container.Portle
import org.apache.pluto.container.om.portlet.DisplayName;
import org.apache.pluto.container.om.portlet.PortletDefinition;
import org.apache.pluto.container.om.portlet.Supports;
+import org.apache.pluto.container.util.PrintWriterServletOutputStream;
+import org.apache.sling.portal.container.PortletContent;
import org.apache.sling.portal.container.SlingPortletContainer;
import org.apache.sling.portal.container.SlingPortletWindow;
import org.apache.sling.portal.container.internal.request.PortalURL;
@@ -55,6 +57,8 @@ public class PortletRenderResponseContex
private final boolean writeTitle;
+ private PortletContent portletContent;
+
public PortletRenderResponseContextImpl(final SlingPortletContainer
container,
final HttpServletRequest containerRequest,
final HttpServletResponse containerResponse,
@@ -74,6 +78,7 @@ public class PortletRenderResponseContex
}
}
this.writeTitle = !window.getConfiguration().get("hideTitleBar",
false);
+ this.portletContent = window.getPortletContent();
}
private boolean written() {
@@ -184,16 +189,17 @@ public class PortletRenderResponseContex
@Override
public PrintWriter getWriter() throws IOException, IllegalStateException {
- final PrintWriter pw = super.getWriter();
+ final PrintWriter pw = portletContent.getWriter();
this.drawWindowTitle(pw);
return pw;
}
@Override
public OutputStream getOutputStream() throws IOException,
IllegalStateException {
- final OutputStream os = super.getOutputStream();
- this.drawWindowTitle(new PrintWriter(new OutputStreamWriter(os,
getServletResponse().getCharacterEncoding())));
- return os;
+ final OutputStream os = new
PrintWriterServletOutputStream(portletContent.getWriter(),
+ getServletResponse().getCharacterEncoding());
+ this.drawWindowTitle(new PrintWriter(new OutputStreamWriter(os,
getServletResponse().getCharacterEncoding())));
+ return os;
}
}
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java?rev=1376018&view=auto
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
(added)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
Wed Aug 22 12:36:04 2012
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.portal.container.internal.impl;
+
+import java.io.CharArrayWriter;
+import java.io.PrintWriter;
+import javax.portlet.PortletMode;
+import javax.portlet.WindowState;
+import org.apache.sling.portal.container.PortletContent;
+
+public class PortletContentImpl implements PortletContent{
+
+ private CharArrayWriter cw;
+ private PrintWriter writer;
+
+ private int expiration;
+ private PortletMode portletMode;
+ private WindowState windowState;
+
+ public PortletContentImpl(){
+ cw = new CharArrayWriter();
+ writer = new PrintWriter(cw);
+ }
+
+ public PortletContentImpl(int expiration, PortletMode portletMode,
+ WindowState windowState) {
+ this();
+ this.expiration = expiration;
+ this.portletMode = portletMode;
+ this.windowState = windowState;
+ }
+
+ public PrintWriter getWriter(){
+ return writer;
+ }
+
+ public String getContent(){
+ return toString();
+ }
+
+ public String toString(){
+ writer.flush();
+ return cw.toString();
+ }
+
+ public PortletMode getPortletMode() {
+ return portletMode;
+ }
+
+ public WindowState getWindowState() {
+ return windowState;
+ }
+
+ public int getExpiration() {
+ return expiration;
+ }
+
+ public void setExpiration(int expiration) {
+ this.expiration = expiration;
+ }
+}
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletContentImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletWindowImpl.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletWindowImpl.java?rev=1376018&r1=1376017&r2=1376018&view=diff
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletWindowImpl.java
(original)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/impl/PortletWindowImpl.java
Wed Aug 22 12:36:04 2012
@@ -22,6 +22,7 @@ import javax.portlet.WindowState;
import org.apache.pluto.container.PortletWindowID;
import org.apache.pluto.container.om.portlet.PortletDefinition;
import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.portal.container.PortletContent;
import org.apache.sling.portal.container.SlingPortletEntity;
import org.apache.sling.portal.container.SlingPortletWindow;
@@ -35,6 +36,7 @@ public class PortletWindowImpl implement
private final PortletWindowID windowId;
private final SlingPortletEntity entity;
private final ValueMap configuration;
+ private PortletContent portletContent;
/**
* Constructs an instance.
@@ -89,4 +91,12 @@ public class PortletWindowImpl implement
public ValueMap getConfiguration() {
return this.configuration;
}
+
+ public PortletContent getPortletContent() {
+ return portletContent;
+ }
+
+ public void setPortletContent(PortletContent portletContent) {
+ this.portletContent= portletContent;
+ }
}
\ No newline at end of file