2010/1/29 Grégory Joseph <[email protected]>

>
> Hi Rico,
>
> There *should* be a better way; essentially, the component that creates
> this "page-comments" forum should be site-aware, and create a new
> comments-forum for each site.  ("forum" because that's the generic name of
> this structure, whether it's used for commenting or forum discussions, it's
> the exact same backend)
>
> I don't have the sources right here, ping me again if you don't find right
> away where this happens. Patches most welcome as usual ;)
>
>
I have found the spots the forum name is set. I have made changes to use the
site name, my first attempt was
through the site object but that resulted in either the theme name or the
name of the site definition.
I now use the root node of the content the paragraph is placed in. I have
delegated this to a util class that is
used by both paragraphs. I also introduced a parameter called useSiteName to
enable the site awareness
behaviour. It does require someone the create the forum called by this, and
set the corresponding
acl' s for the users.

Attached is the diff containing:
- changes to the bootstrap xml's for the paragraphs (default not using the
site name).
- changes to the java code of PageComments.java and LatestComments.java
- a CommentingUtil class containing the method to determine the forum name

-- 
Rico Jansen ([email protected])
"You call it untidy, I call it LRU ordered" -- Daniel Barlow

----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Index: src/main/java/info/magnolia/module/commenting/frontend/action/LatestComments.java
===================================================================
--- src/main/java/info/magnolia/module/commenting/frontend/action/LatestComments.java	(revision 31597)
+++ src/main/java/info/magnolia/module/commenting/frontend/action/LatestComments.java	(working copy)
@@ -14,22 +14,23 @@
  */
 package info.magnolia.module.commenting.frontend.action;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
 import info.magnolia.cms.beans.config.ContentRepository;
 import info.magnolia.cms.core.Content;
 import info.magnolia.cms.core.HierarchyManager;
 import info.magnolia.context.MgnlContext;
 import info.magnolia.link.LinkUtil;
 import info.magnolia.module.commenting.CommentingModule;
+import info.magnolia.module.commenting.util.CommentingUtil;
 import info.magnolia.module.forum.ForumManager;
 import info.magnolia.module.templating.RenderableDefinition;
 import info.magnolia.module.templating.RenderingModel;
 import info.magnolia.module.templating.RenderingModelImpl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.lang.StringUtils;
@@ -65,7 +66,7 @@
             return "error";
          }
         try {
-            Collection col = ForumManager.Factory.getInstance().getForumMessages((String) getDefinition().getParameters().get("forumName"));
+            Collection col = ForumManager.Factory.getInstance().getForumMessages(CommentingUtil.getForumName(this,getContent()));
             HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE);
             String parentPath = StringUtils.defaultIfEmpty(getContent().getNodeData("parentPath").getString(), "/");
             int count = !getContent().hasNodeData("limit") ? 0 : (int) getContent().getNodeData("limit").getLong();
@@ -84,16 +85,17 @@
         return "success";
     }
     
-    public String getPageLink(String uuid) {
-        if (StringUtils.isEmpty(uuid)) {
-            return null;
+    private String getForumName() throws RepositoryException {
+        String forumName =(String) getDefinition().getParameters().get("forumName");
+        String useSiteName = (String) getDefinition().getParameters().get("useSiteName");
+        
+        if (StringUtils.isNotEmpty(useSiteName) && useSiteName.equals("true") && forumName!=null) {
+            Content site=content.getAncestor(1);
+            if (site != null) {
+                forumName = forumName+"-"+site.getName();
+            }
         }
-        try {
-            return LinkUtil.createAbsoluteLink(ContentRepository.WEBSITE, uuid);
-        } catch (RepositoryException e) {
-            log.error(e.getLocalizedMessage(), e);
-            // let the template handle the fact that referenced page doesn't exist
-            return null;
-        }
+        return forumName;
     }
+    
 }
Index: src/main/java/info/magnolia/module/commenting/frontend/action/PageComments.java
===================================================================
--- src/main/java/info/magnolia/module/commenting/frontend/action/PageComments.java	(revision 31597)
+++ src/main/java/info/magnolia/module/commenting/frontend/action/PageComments.java	(working copy)
@@ -14,11 +14,6 @@
  */
 package info.magnolia.module.commenting.frontend.action;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-
 import info.magnolia.cms.core.Content;
 import info.magnolia.cms.core.search.Query;
 import info.magnolia.cms.core.search.QueryManager;
@@ -26,6 +21,7 @@
 import info.magnolia.context.MgnlContext;
 import info.magnolia.module.ModuleRegistry;
 import info.magnolia.module.commenting.CommentingModule;
+import info.magnolia.module.commenting.util.CommentingUtil;
 import info.magnolia.module.forum.DefaultForumManager;
 import info.magnolia.module.forum.ForumConfiguration;
 import info.magnolia.module.forum.ForumManager;
@@ -35,6 +31,10 @@
 import info.magnolia.module.templating.RenderableDefinition;
 import info.magnolia.module.templating.RenderingModel;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.lang.StringUtils;
@@ -104,11 +104,13 @@
             if (threadId == null) {
                 setupForumIdFromContent();
                 if (forumId == null) {
-                    String forumName =(String) getDefinition().getParameters().get("forumName");
+                    String forumName = CommentingUtil.getForumName(this,content);
+
                     if (forumName == null) {
                         throw new RuntimeException("Define /modules/yourModule/paragraphs/" + getDefinition().getName() + "/parameters/forumName to specify default forum for comments");
                     }
                     forumId = forumManager.getForumId(forumName);
+                    
                 }
                 if (forumId == null) {
                     throw new IllegalStateException("No forum id given");
@@ -174,5 +176,5 @@
             return super.isAllowedToPost();
         }
     }
-
+    
 }
Index: src/main/java/info/magnolia/module/commenting/util/CommentingUtil.java
===================================================================
--- src/main/java/info/magnolia/module/commenting/util/CommentingUtil.java	(revision 0)
+++ src/main/java/info/magnolia/module/commenting/util/CommentingUtil.java	(revision 0)
@@ -0,0 +1,40 @@
+/**
+ * This file Copyright (c) 2009 Magnolia International
+ * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
+ *
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Magnolia Network Agreement
+ * which accompanies this distribution, and is available at
+ * http://www.magnolia-cms.com/mna.html
+ *
+ * Any modifications to this file must keep this entire header
+ * intact.
+ *
+ */
+package info.magnolia.module.commenting.util;
+
+import info.magnolia.cms.core.Content;
+import info.magnolia.cms.security.AccessDeniedException;
+import info.magnolia.module.templating.RenderingModel;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.commons.lang.StringUtils;
+
+public class CommentingUtil {
+
+    public static String getForumName(RenderingModel model, Content content) throws PathNotFoundException, RepositoryException, AccessDeniedException {
+        String forumName = (String) model.getDefinition().getParameters().get("forumName");
+        String useSiteName = (String) model.getDefinition().getParameters().get("useSiteName");
+        
+        if (StringUtils.isNotEmpty(useSiteName) && useSiteName.equals("true") && forumName!=null) {
+            Content site=content.getAncestor(1);
+            if (site != null) {
+                forumName = forumName+"-"+site.getName();
+            }
+        }
+        return forumName;
+    }
+}
Index: src/main/resources/mgnl-bootstrap/commenting/config.modules.forum.paragraphs.latestComments.xml
===================================================================
--- src/main/resources/mgnl-bootstrap/commenting/config.modules.forum.paragraphs.latestComments.xml	(revision 31597)
+++ src/main/resources/mgnl-bootstrap/commenting/config.modules.forum.paragraphs.latestComments.xml	(working copy)
@@ -1,9 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<sv:node sv:name="latestComments" xmlns:jcr="http://www.jcp.org/jcr/1.0"; xmlns:mgnl="http://www.magnolia.info/jcr/mgnl";
-  xmlns:rep="internal" xmlns:mix="http://www.jcp.org/jcr/mix/1.0"; xmlns:nt="http://www.jcp.org/jcr/nt/1.0";
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:fn="http://www.w3.org/2005/xpath-functions";
-  xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions";
-  xmlns:sv="http://www.jcp.org/jcr/sv/1.0"; xmlns:jcrfn="http://www.jcp.org/jcr/xpath-functions/1.0";>
+<sv:node sv:name="latestComments" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <sv:property sv:name="jcr:primaryType" sv:type="Name">
     <sv:value>mgnl:contentNode</sv:value>
   </sv:property>
@@ -79,6 +75,9 @@
     <sv:property sv:name="headingLevel" sv:type="String">
       <sv:value/>
     </sv:property>
+    <sv:property sv:name="useSiteName" sv:type="String">
+      <sv:value>false</sv:value>
+    </sv:property>
     <sv:node sv:name="MetaData">
       <sv:property sv:name="jcr:primaryType" sv:type="Name">
         <sv:value>mgnl:metaData</sv:value>
@@ -90,7 +89,7 @@
         <sv:value>2009-02-10T12:14:50.641+01:00</sv:value>
       </sv:property>
       <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
-        <sv:value>2009-10-09T12:50:26.848+02:00</sv:value>
+        <sv:value>2010-02-08T11:18:53.310+01:00</sv:value>
       </sv:property>
     </sv:node>
   </sv:node>
Index: src/main/resources/mgnl-bootstrap/commenting/config.modules.forum.paragraphs.comments.xml
===================================================================
--- src/main/resources/mgnl-bootstrap/commenting/config.modules.forum.paragraphs.comments.xml	(revision 31597)
+++ src/main/resources/mgnl-bootstrap/commenting/config.modules.forum.paragraphs.comments.xml	(working copy)
@@ -1,9 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<sv:node sv:name="comments" xmlns:jcr="http://www.jcp.org/jcr/1.0"; xmlns:mgnl="http://www.magnolia.info/jcr/mgnl";
-  xmlns:rep="internal" xmlns:mix="http://www.jcp.org/jcr/mix/1.0"; xmlns:nt="http://www.jcp.org/jcr/nt/1.0";
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:fn="http://www.w3.org/2005/xpath-functions";
-  xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns:sv="http://www.jcp.org/jcr/sv/1.0";
-  xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"; xmlns:jcrfn="http://www.jcp.org/jcr/xpath-functions/1.0";>
+<sv:node sv:name="comments" xmlns:sv="http://www.jcp.org/jcr/sv/1.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
   <sv:property sv:name="jcr:primaryType" sv:type="Name">
     <sv:value>mgnl:contentNode</sv:value>
   </sv:property>
@@ -73,6 +69,9 @@
     <sv:property sv:name="forumName" sv:type="String">
       <sv:value>pagecomments</sv:value>
     </sv:property>
+    <sv:property sv:name="useSiteName" sv:type="String">
+      <sv:value>false</sv:value>
+    </sv:property>
     <sv:node sv:name="MetaData">
       <sv:property sv:name="jcr:primaryType" sv:type="Name">
         <sv:value>mgnl:metaData</sv:value>
@@ -84,7 +83,7 @@
         <sv:value>2009-02-10T12:14:50.641+01:00</sv:value>
       </sv:property>
       <sv:property sv:name="mgnl:lastmodified" sv:type="Date">
-        <sv:value>2009-03-06T17:51:15.004+01:00</sv:value>
+        <sv:value>2010-02-08T11:18:30.164+01:00</sv:value>
       </sv:property>
     </sv:node>
   </sv:node>

Reply via email to