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

Modified Files:
      Tag: b1_4
        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.4.2.3
retrieving revision 1.4.2.4
diff -u -b -r1.4.2.3 -r1.4.2.4
--- RelatedContentPortlet.java  12 Jun 2008 14:57:58 -0000      1.4.2.3
+++ RelatedContentPortlet.java  12 Jun 2008 15:39:30 -0000      1.4.2.4
@@ -13,8 +13,7 @@
 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;
 
 import com.finalist.cmsc.beans.om.NavigationItem;
@@ -33,22 +32,11 @@
    @Override
    protected void doView(RenderRequest req, RenderResponse res) throws 
PortletException, IOException {
       String window = req.getPreferences().getValue(WINDOW, null);
-      if (!StringUtil.isEmpty(window)) {
-         String elementId = getElementIdFromRequestParameters(req, window);
-         if (StringUtil.isEmpty(elementId)) {
-            elementId = getElementIdFromScreen(req, window);
-            if (StringUtil.isEmpty(elementId)) {
-               elementId = getElementIdFromContentURL(req);
-               if (StringUtil.isEmpty(elementId)) {
-                  elementId = getElementId(req, window);
-               }
-            }
-         }
+      String elementId = getRelatedElementId(req, window);
 
-         if (!StringUtil.isEmpty(elementId)) {
+      if (StringUtils.isNotEmpty(elementId)) {
             setAttribute(req, ELEMENT_ID, elementId);
          }
-      }
       super.doView(req, res);
    }
 
@@ -67,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>
     *
-    * @param req
-    *           originating RenderRequest
+    * The first one to return a non <code>null</code> value will be returned.
+    *
+    * @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 req, 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) {
@@ -92,16 +101,7 @@
          }
          return elementId;
       }
-      return null;
-   }
 
-   private String getElementIdFromContentURL(RenderRequest req) {
-      String requestURL = getServletRequest(req).getRequestURL().toString();
-      Pattern pattern = Pattern.compile(CONTENTURL_ELEMENTID_PATTERN);
-      Matcher matcher = pattern.matcher(requestURL);
-      if (matcher.find() && matcher.groupCount() >= 1) {
-         return matcher.group(1);
-      }
       return null;
    }
 
@@ -119,6 +119,16 @@
       return null;
    }
 
+   private String getElementIdFromContentURL(RenderRequest req) {
+      String requestURL = getServletRequest(req).getRequestURL().toString();
+      Pattern pattern = Pattern.compile(CONTENTURL_ELEMENTID_PATTERN);
+      Matcher matcher = pattern.matcher(requestURL);
+      if (matcher.find() && matcher.groupCount() >= 1) {
+         return matcher.group(1);
+      }
+      return null;
+   }
+
    private Integer getCurrentPageId(RenderRequest req) {
       String pageId = (String) 
req.getAttribute(PortalConstants.CMSC_OM_PAGE_ID);
       return Integer.valueOf(pageId);
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to