You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2007/02/03 23:27:06 UTC

svn commit: r503325 - in /portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal: Configuration.java impl/RenderResponseImpl.java

Author: ddewolf
Date: Sat Feb  3 14:27:05 2007
New Revision: 503325

URL: http://svn.apache.org/viewvc?view=rev&rev=503325
Log:
PLUTO-299; Buffering Support for some weblogic versions.  Configure it in props file so it doesn't break the plt spec

Modified:
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/Configuration.java
    portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/RenderResponseImpl.java

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/Configuration.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/Configuration.java?view=diff&rev=503325&r1=503324&r2=503325
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/Configuration.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/Configuration.java Sat Feb  3 14:27:05 2007
@@ -20,6 +20,7 @@
 
 import java.util.ResourceBundle;
 import java.util.PropertyResourceBundle;
+import java.util.MissingResourceException;
 
 /**
  * Central location for Configuration info.
@@ -27,7 +28,7 @@
  * @author ddewolf@apache.org
  * @since Jul 2, 2005
  */
-class Configuration {
+public class Configuration {
     
     private static final Log LOG = 
             LogFactory.getLog(Configuration.class);
@@ -37,6 +38,12 @@
 
     private static final String DESCRIPTOR_SERVICE =
         "org.apache.pluto.descriptors.services.PortletAppDescriptorService";
+
+    /**
+     * org.apache.pluto.ALLOW_BUFFER
+     */
+    private static final String BUFFER_SUPPORT =
+        "org.apache.pluto.ALLOW_BUFFER";
             
 
     public static String getPortletAppDescriptorServiceImpl() {
@@ -45,5 +52,15 @@
             LOG.debug("Using Descriptor Service Impl: "+impl);
         }
         return impl;
+    }
+
+    public static boolean isBufferingSupported() {
+        try {
+            String buffer = BUNDLE.getString(BUFFER_SUPPORT);
+            return Boolean.TRUE.toString().equalsIgnoreCase(buffer);
+        } catch(MissingResourceException mre) {
+            return false;
+        }
+
     }
 }

Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/RenderResponseImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/RenderResponseImpl.java?view=diff&rev=503325&r1=503324&r2=503325
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/RenderResponseImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/RenderResponseImpl.java Sat Feb  3 14:27:05 2007
@@ -18,10 +18,11 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pluto.PortletContainer;
-import org.apache.pluto.internal.InternalPortletWindow;
-import org.apache.pluto.internal.InternalRenderResponse;
 import org.apache.pluto.descriptors.portlet.PortletDD;
 import org.apache.pluto.descriptors.portlet.SupportsDD;
+import org.apache.pluto.internal.Configuration;
+import org.apache.pluto.internal.InternalPortletWindow;
+import org.apache.pluto.internal.InternalRenderResponse;
 import org.apache.pluto.spi.PortalCallbackService;
 import org.apache.pluto.util.ArgumentUtility;
 import org.apache.pluto.util.NamespaceMapper;
@@ -33,7 +34,6 @@
 import javax.portlet.RenderResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
@@ -42,43 +42,46 @@
 
 /**
  * Implementation of the <code>javax.portlet.RenderResponse</code> interface.
- * 
+ *
  * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>
  * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a>
  */
 public class RenderResponseImpl extends PortletResponseImpl
-implements RenderResponse, InternalRenderResponse {
-    
-	/** Logger. */
-	private static final Log LOG = LogFactory.getLog(RenderResponseImpl.class);
-	
+    implements RenderResponse, InternalRenderResponse {
+
+    /**
+     * Logger.
+     */
+    private static final Log LOG = LogFactory.getLog(RenderResponseImpl.class);
+
     private static final StringManager EXCEPTIONS = StringManager.getManager(
-    		RenderResponseImpl.class.getPackage().getName());
-    
-    
+        RenderResponseImpl.class.getPackage().getName());
+
     // Private Member Variables ------------------------------------------------
-    
-    /** True if we are in an include call. */
+
+    /**
+     * True if we are in an include call.
+     */
     private boolean included = false;
-    
-    /** The current content type. */
+
+    /**
+     * The current content type.
+     */
     private String currentContentType = null;
-    
+
     private NamespaceMapper mapper = new NamespaceMapperImpl();
-    
-    
+
     // Constructor -------------------------------------------------------------
-    
+
     public RenderResponseImpl(PortletContainer container,
                               InternalPortletWindow internalPortletWindow,
                               HttpServletRequest servletRequest,
                               HttpServletResponse servletResponse) {
         super(container, internalPortletWindow, servletRequest, servletResponse);
     }
-    
-    
+
     // RenderResponse Impl -----------------------------------------------------
-    
+
     public String getContentType() {
         // NOTE: in servlet 2.4 we could simply use this:
         //   return super.getHttpServletResponse().getContentType();
@@ -94,35 +97,35 @@
     }
 
     public String getNamespace() {
-         String namespace = mapper.encode(getInternalPortletWindow().getId(), "");
-         StringBuffer validNamespace = new StringBuffer();
-         for (int i = 0; i < namespace.length(); i++) {
-         	char ch = namespace.charAt(i);
-         	if (Character.isJavaIdentifierPart(ch)) {
-         		validNamespace.append(ch);
-         	} else {
-         		validNamespace.append('_');
-         	}
-         }
-         return validNamespace.toString();
+        String namespace = mapper.encode(getInternalPortletWindow().getId(), "");
+        StringBuffer validNamespace = new StringBuffer();
+        for (int i = 0; i < namespace.length(); i++) {
+            char ch = namespace.charAt(i);
+            if (Character.isJavaIdentifierPart(ch)) {
+                validNamespace.append(ch);
+            } else {
+                validNamespace.append('_');
+            }
+        }
+        return validNamespace.toString();
     }
 
     public void setTitle(String title) {
         PortalCallbackService callback = getContainer()
-        		.getRequiredContainerServices()
-        		.getPortalCallbackService();
+            .getRequiredContainerServices()
+            .getPortalCallbackService();
         callback.setTitle(this.getHttpServletRequest(),
-                          getInternalPortletWindow(),
-                          title);
+            getInternalPortletWindow(),
+            title);
     }
 
     public void setContentType(String contentType)
-    throws IllegalArgumentException {
-    	ArgumentUtility.validateNotNull("contentType", contentType);
+        throws IllegalArgumentException {
+        ArgumentUtility.validateNotNull("contentType", contentType);
         String mimeType = StringUtils.getMimeTypeWithoutEncoding(contentType);
         if (!isValidContentType(mimeType)) {
             throw new IllegalArgumentException("Specified content type '"
-            		+ mimeType + "' is not supported.");
+                + mimeType + "' is not supported.");
         }
         getHttpServletResponse().setContentType(mimeType);
         this.currentContentType = mimeType;
@@ -131,23 +134,23 @@
     public String getCharacterEncoding() {
         return getHttpServletResponse().getCharacterEncoding();
     }
-    
+
     /**
      * @see PortletResponseImpl#getOutputStream()
      * @see #getWriter()
      */
     public OutputStream getPortletOutputStream()
-    throws IOException, IllegalStateException {
+        throws IOException, IllegalStateException {
         if (currentContentType == null) {
             String message = EXCEPTIONS.getString("error.contenttype.null");
             if (LOG.isWarnEnabled()) {
-            	LOG.warn("Current content type is not set.");
+                LOG.warn("Current content type is not set.");
             }
             throw new IllegalStateException(message);
         }
         return super.getOutputStream();
     }
-    
+
     /**
      * @see PortletResponseImpl#getWriter()
      * @see #getPortletOutputStream()
@@ -156,7 +159,7 @@
         if (currentContentType == null) {
             String message = EXCEPTIONS.getString("error.contenttype.null");
             if (LOG.isWarnEnabled()) {
-            	LOG.warn("Current content type is not set.");
+                LOG.warn("Current content type is not set.");
             }
             throw new IllegalStateException(message);
         }
@@ -167,14 +170,19 @@
         return getHttpServletRequest().getLocale();
     }
 
-    // TODO: port 1.0.1 setBufferSize fix to 1.1
     public void setBufferSize(int size) {
-        throw new IllegalStateException(
-            "portlet container does not support buffering");
+        if (Configuration.isBufferingSupported()) {
+            getHttpServletResponse().setBufferSize(size);
+        } else {
+            throw new IllegalStateException(
+                "portlet container does not support buffering");
+        }
     }
 
     public int getBufferSize() {
-        // TODO: return this.getHttpServletResponse().getBufferSize();
+        if (Configuration.isBufferingSupported()) {
+            return getHttpServletResponse().getBufferSize();
+        }
         return 0;
     }
 
@@ -194,9 +202,8 @@
         getHttpServletResponse().reset();
     }
 
-    
     // InternalRenderResponse Impl ---------------------------------------------
-    
+
     public void setIncluded(boolean included) {
         this.included = included;
     }
@@ -204,82 +211,82 @@
     public boolean isIncluded() {
         return included;
     }
-    
-    
+
     // Included HttpServletResponse (Limited) Impl -----------------------------
-    
+
     /**
      * TODO
      */
     public String encodeRedirectUrl(String url) {
-    	if (included) {
-    		return null;
-    	} else {
-    		return super.encodeRedirectUrl(url);
-    	}
+        if (included) {
+            return null;
+        } else {
+            return super.encodeRedirectUrl(url);
+        }
     }
-    
+
     /**
      * TODO
      */
     public String encodeRedirectURL(String url) {
-    	if (included) {
-    		return null;
-    	} else {
-    		return super.encodeRedirectURL(url);
-    	}
+        if (included) {
+            return null;
+        } else {
+            return super.encodeRedirectURL(url);
+        }
     }
-    
-    
+
     // Private Methods ---------------------------------------------------------
-    
+
     /**
      * Creates a portlet URL.
      * TODO: make dynamic? as service?
-     * @param isAction  true for an action URL, false for a render URL.
+     *
+     * @param isAction true for an action URL, false for a render URL.
      * @return the created portlet (action/render) URL.
      */
     private PortletURL createURL(boolean isAction) {
         return new PortletURLImpl(getContainer(),
-                                  getInternalPortletWindow(),
-                                  getHttpServletRequest(),
-                                  getHttpServletResponse(),
-                                  isAction);
+            getInternalPortletWindow(),
+            getHttpServletRequest(),
+            getHttpServletResponse(),
+            isAction);
     }
-    
+
     /**
      * Checks if the specified content type is valid (supported by the portlet).
      * The specified content type should be a tripped mime type without any
      * character encoding suffix.
-     * @param contentType  the content type to check.
+     *
+     * @param contentType the content type to check.
      * @return true if the content type is valid, false otherwise.
      */
     private boolean isValidContentType(String contentType) {
-    	boolean valid = false;
-    	
+        boolean valid = false;
+
         PortletDD portletDD = getInternalPortletWindow().getPortletEntity()
-        		.getPortletDefinition();
+            .getPortletDefinition();
         for (Iterator it = portletDD.getSupports().iterator();
-        		!valid && it.hasNext(); ) {
-            
-        	SupportsDD supportsDD = (SupportsDD) it.next();
+             !valid && it.hasNext();) {
+
+            SupportsDD supportsDD = (SupportsDD) it.next();
             String supportedType = supportsDD.getMimeType();
-            
+
             // Content type is supported by an exact match.
             if (supportedType.equals(contentType)) {
-            	valid = true;
+                valid = true;
             }
             // The supported type contains a wildcard.
             else if (supportedType.indexOf("*") >= 0) {
-            	
+
                 int index = supportedType.indexOf("/");
                 String supportedPrefix = supportedType.substring(0, index);
                 String supportedSuffix = supportedType.substring(index + 1);
-                
+
                 index = contentType.indexOf("/");
                 String typePrefix = contentType.substring(0, index);
                 String typeSuffix = contentType.substring(index + 1);
-                
+
                 // Check if the prefixes match AND the suffixes match.
                 if (supportedPrefix.equals("*") || supportedPrefix.equals(typePrefix)) {
                     if (supportedSuffix.equals("*") || supportedSuffix.equals(typeSuffix)) {