Update of 
/var/cvs/contributions/CMSContainer/cmsc/portlets/src/java/com/finalist/cmsc/portlets
In directory 
james.mmbase.org:/tmp/cvs-serv18585/cmsc/portlets/src/java/com/finalist/cmsc/portlets

Modified Files:
        RelatedContentPortlet.java 
Log Message:
CMSC-959 - Better version, extendable etc.


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/portlets/src/java/com/finalist/cmsc/portlets
See also: http://www.mmbase.org/jira/browse/CMSC-959


Index: RelatedContentPortlet.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/portlets/src/java/com/finalist/cmsc/portlets/RelatedContentPortlet.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- RelatedContentPortlet.java  12 Jun 2008 15:12:21 -0000      1.8
+++ RelatedContentPortlet.java  12 Jun 2008 15:38:15 -0000      1.9
@@ -13,8 +13,6 @@
 import javax.portlet.RenderResponse;
 import javax.servlet.http.HttpServletRequest;
 
-import net.sf.mmapps.commons.util.StringUtil;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.pluto.core.impl.PortletRequestImpl;
 
@@ -34,22 +32,11 @@
    @Override
    protected void doView(RenderRequest req, RenderResponse res) throws 
PortletException, IOException {
       String window = req.getPreferences().getValue(WINDOW, null);
-      if (StringUtils.isNotEmpty(window)) {
-         String elementId = getElementIdFromRequestParameters(req, window);
-         if (StringUtils.isEmpty(elementId)) {
-            elementId = getElementIdFromScreen(req, window);
-            if (StringUtil.isEmpty(elementId)) {
-               elementId = getElementIdFromContentURL(req);
-               if (StringUtils.isEmpty(elementId)) {
-                  elementId = getElementId(req, window);
-               }
-            }
-         }
+      String elementId = getRelatedElementId(req, window);
 
          if (StringUtils.isNotEmpty(elementId)) {
             setAttribute(req, ELEMENT_ID, elementId);
          }
-      }
       super.doView(req, res);
    }
 
@@ -68,17 +55,38 @@
    }
 
    /**
-    * This method can be overridden to provide your own mechanism for getting 
an
-    * elementId. The default implementation returns <code>null</code>.
+    * Retrieves the related elementId as a String. The default implementation
+    * tries to retrieve the element in the following order:
+    *
+    * <ol>
+    * <li>From the parameter of the current request</li>
+    * <li>From contentelement node parameter of the specified portlet</li>
+    * <li>From a given contentURL (assumes that the elementId we want is
+    * exactly that elementId)</li>
+    * </ol>
+    *
+    * The first one to return a non <code>null</code> value will be returned.
     *
-    * @param req
-    *           originating RenderRequest
+    * @param request
+    *           the render request
     * @param window
-    *           the passed 'window' parameter.
-    * @return the elementId
+    *           the specified window (might be <code>null</code>)
+    * @return elementId if an elementId could be found, <code>null</code>
+    *         otherwise.
     */
-   protected String getElementId(RenderRequest request, String window) {
-      return null;
+   protected String getRelatedElementId(RenderRequest request, String window) {
+      String elementId = null;
+      if (StringUtils.isNotEmpty(window)) {
+         elementId = getElementIdFromRequestParameters(request, window);
+         if (StringUtils.isEmpty(elementId)) {
+            elementId = getElementIdFromScreen(request, window);
+            if (StringUtils.isEmpty(elementId)) {
+               elementId = getElementIdFromContentURL(request);
+            }
+         }
+      }
+
+      return elementId;
    }
 
    private String getElementIdFromRequestParameters(RenderRequest req, String 
window) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to