You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2006/12/12 13:24:19 UTC

svn commit: r486110 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/publication/ modules/notification/ modules/notification/config/cocoon-xconf/ modules/notification/java/src/org/apache/lenya/inbox/ modules/notification/java/src/org/apache/lenya/...

Author: andreas
Date: Tue Dec 12 04:24:18 2006
New Revision: 486110

URL: http://svn.apache.org/viewvc?view=rev&rev=486110
Log:
Moved translation functionality up to AbstractNotifier, fixed i18n for notification, don't check if document exists before reading resource type meta data

Modified:
    lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
    lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf
    lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java
    lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/AbstractNotifier.java
    lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/EmailNotifier.java
    lenya/trunk/src/modules/notification/sitemap.xmap
    lenya/trunk/src/targets/init-build.xml
    lenya/trunk/src/webapp/lenya/config/sitemap/generators.xmap

Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentImpl.java Tue Dec 12 04:24:18 2006
@@ -411,11 +411,6 @@
      * @see Document#getResourceType()
      */
     public ResourceType getResourceType() throws DocumentException {
-        
-        if (!exists()) {
-            throw new DocumentException("The document [" + this + "] doesn't exist!");
-        }
-        
         if (this.resourceType == null) {
             ServiceSelector selector = null;
             try {

Modified: lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf (original)
+++ lenya/trunk/src/modules/notification/config/cocoon-xconf/notifier.xconf Tue Dec 12 04:24:18 2006
@@ -18,12 +18,18 @@
 
 <!-- $Id: doctypes.xconf 164635 2005-04-25 20:01:43Z tschlabach $ -->
 
-<xconf xpath="/cocoon" unless="/cocoon/notifier">
+<xconf xpath="/cocoon" unless="/cocoon/component[@role = 'org.apache.lenya.notification.Notifier']">
 
   <component logger="lenya.notification"
     role="org.apache.lenya.notification.Notifier"
     class="org.apache.lenya.notification.EmailNotifier">
-    <smtp-host>mail.yourdomain.com</smtp-host>
+    
+    <smtp host="localhost"/>
+    
+    <!-- use this for authentication
+    <smtp host="localhost" username="john" password="swordfish" />
+    -->
+    
   </component>
   
 </xconf>

Modified: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java (original)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/inbox/InboxNotifier.java Tue Dec 12 04:24:18 2006
@@ -17,14 +17,7 @@
  */
 package org.apache.lenya.inbox;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
 import org.apache.avalon.framework.service.ServiceException;
-import org.apache.lenya.ac.Group;
-import org.apache.lenya.ac.Groupable;
-import org.apache.lenya.ac.Identifiable;
 import org.apache.lenya.ac.User;
 import org.apache.lenya.notification.AbstractNotifier;
 import org.apache.lenya.notification.Message;
@@ -35,35 +28,13 @@
  */
 public class InboxNotifier extends AbstractNotifier {
 
-    public void notify(Message message) throws NotificationException {
-        Identifiable[] recipients = message.getRecipients();
-
-        Set users = new HashSet();
-        for (int i = 0; i < recipients.length; i++) {
-            if (recipients[i] instanceof User) {
-                users.add(recipients[i]);
-            } else if (recipients[i] instanceof Group) {
-                Group group = (Group) recipients[i];
-                Groupable[] members = group.getMembers();
-                for (int m = 0; m < members.length; m++) {
-                    if (members[m] instanceof User) {
-                        users.add(members[m]);
-                    }
-                }
-            } else {
-                throw new NotificationException("Unsupported recipient type ["
-                        + recipients[i].getClass() + "]");
-            }
-        }
-
+    protected void notify(User user, Message message) throws NotificationException {
+        
         InboxManager inboxManager = null;
         try {
             inboxManager = (InboxManager) this.manager.lookup(InboxManager.ROLE);
-            for (Iterator i = users.iterator(); i.hasNext();) {
-                User user = (User) i.next();
-                Inbox inbox = inboxManager.getInbox(user);
-                inbox.add(message);
-            }
+            Inbox inbox = inboxManager.getInbox(user);
+            inbox.add(message);
         } catch (ServiceException e) {
             throw new NotificationException(e);
         } finally {

Modified: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/AbstractNotifier.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/AbstractNotifier.java?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/AbstractNotifier.java (original)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/AbstractNotifier.java Tue Dec 12 04:24:18 2006
@@ -17,8 +17,10 @@
  */
 package org.apache.lenya.notification;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
@@ -33,6 +35,9 @@
 import org.apache.cocoon.transformation.I18nTransformer;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.ac.Group;
+import org.apache.lenya.ac.Identifiable;
+import org.apache.lenya.ac.User;
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
 import org.w3c.dom.Document;
@@ -44,6 +49,35 @@
 public abstract class AbstractNotifier extends AbstractLogEnabled implements Notifier, Serviceable,
         Contextualizable {
 
+    public void notify(Message message) throws NotificationException {
+
+        Set noDuplicates = new HashSet();
+
+        Identifiable[] recipients = message.getRecipients();
+
+        for (int i = 0; i < recipients.length; i++) {
+            if (recipients[i] instanceof Group) {
+                Group group = (Group) recipients[i];
+                noDuplicates.addAll(Arrays.asList(group.getMembers()));
+            } else {
+                noDuplicates.add(recipients[i]);
+            }
+        }
+
+        for (Iterator i = noDuplicates.iterator(); i.hasNext();) {
+            Identifiable identifiable = (Identifiable) i.next();
+            if (identifiable instanceof User) {
+                User user = (User) identifiable;
+                Message translatedMessage = translateMessage(user.getDefaultMenuLocale(), message);
+                notify(user, translatedMessage);
+            }
+        }
+
+    }
+
+    protected abstract void notify(User user, Message translatedMessage)
+            throws NotificationException;
+
     protected Message translateMessage(String locale, Message message) throws NotificationException {
 
         SourceResolver resolver = null;
@@ -86,25 +120,27 @@
             Session session = this.request.getSession();
             session.setAttribute("notification.dom", doc);
 
-            Map parameters = new HashMap();
-
-            parameters.put("locale", locale);
-
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
-            source = resolver.resolveURI("cocoon://modules/notification/message.xml", null,
-                    parameters);
-
-            doc = DocumentHelper.readDocument(source.getInputStream());
-            helper = new NamespaceHelper(NAMESPACE, "not", doc);
+            source = resolver.resolveURI("cocoon://modules/notification/message/" + locale, null,
+                    null);
 
-            subjectElement = helper.getFirstChild(doc.getDocumentElement(), "subject");
-            String subject = DocumentHelper.getSimpleElementText(subjectElement);
-
-            bodyElement = helper.getFirstChild(doc.getDocumentElement(), "body");
-            String body = DocumentHelper.getSimpleElementText(bodyElement);
-
-            return new Message(subject, new String[0], body, new String[0], message.getSender(),
-                    message.getRecipients());
+            if (source.exists()) {
+                doc = DocumentHelper.readDocument(source.getInputStream());
+                helper = new NamespaceHelper(NAMESPACE, "not", doc);
+
+                subjectElement = helper.getFirstChild(doc.getDocumentElement(), "subject");
+                String subject = DocumentHelper.getSimpleElementText(subjectElement);
+
+                bodyElement = helper.getFirstChild(doc.getDocumentElement(), "body");
+                String body = DocumentHelper.getSimpleElementText(bodyElement);
+
+                return new Message(subject, new String[0], body, new String[0],
+                        message.getSender(), message.getRecipients());
+            } else {
+                // this happens in the test
+                getLogger().info("cocoon protocol not available, not translating message");
+                return message;
+            }
         } catch (Exception e) {
             throw new NotificationException(e);
         } finally {

Modified: lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/EmailNotifier.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/EmailNotifier.java?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/EmailNotifier.java (original)
+++ lenya/trunk/src/modules/notification/java/src/org/apache/lenya/notification/EmailNotifier.java Tue Dec 12 04:24:18 2006
@@ -17,16 +17,10 @@
  */
 package org.apache.lenya.notification;
 
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.cocoon.mail.MailSender;
-import org.apache.lenya.ac.Group;
 import org.apache.lenya.ac.Identifiable;
 import org.apache.lenya.ac.User;
 import org.apache.lenya.inbox.InboxNotifier;
@@ -36,55 +30,30 @@
  */
 public class EmailNotifier extends InboxNotifier implements Configurable {
 
-    public void notify(Message message)
-            throws NotificationException {
-        
-        super.notify(message);
-
-        Set noDuplicates = new HashSet();
+    protected void notify(User recipient, Message translatedMessage) throws NotificationException {
         
-        Identifiable[] recipients = message.getRecipients();
-
-        for (int i = 0; i < recipients.length; i++) {
-            if (recipients[i] instanceof Group) {
-                Group group = (Group) recipients[i];
-                noDuplicates.addAll(Arrays.asList(group.getMembers()));
-            } else {
-                noDuplicates.add(recipients[i]);
-            }
-        }
-
-        for (Iterator i = noDuplicates.iterator(); i.hasNext();) {
-            Identifiable identifiable = (Identifiable) i.next();
-            if (identifiable instanceof User) {
-                notify((User) identifiable, message);
-            }
-        }
-
-    }
-
-    protected void notify(User recipient, Message message)
-            throws NotificationException {
-
-        Identifiable sender = message.getSender();
+        super.notify(recipient, translatedMessage);
         
         if (!this.manager.hasService(MailSender.ROLE)) {
             getLogger().error("Can't send mails - no MailSender service found.");
             return;
         }
-        
+
+        Identifiable sender = translatedMessage.getSender();
         MailSender mailer = null;
         try {
             mailer = (MailSender) this.manager.lookup(MailSender.ROLE);
-            mailer.setSmtpHost(this.smtpHost);
+            if (this.username == null) {
+                mailer.setSmtpHost(this.smtpHost);
+            } else {
+                mailer.setSmtpHost(this.smtpHost, this.username, this.password);
+            }
 
             mailer.setTo(recipient.getEmail());
             if (sender instanceof User) {
                 mailer.setFrom(((User) sender).getEmail());
             }
 
-            Message translatedMessage = translateMessage(recipient.getDefaultMenuLocale(), message);
-
             mailer.setSubject(translatedMessage.getSubject());
             mailer.setBody(translatedMessage.getBody(), "text/plain");
             mailer.setCharset("UTF-8");
@@ -97,15 +66,19 @@
                 this.manager.release(mailer);
             }
         }
-
     }
 
     private String smtpHost;
-
-    protected static final String ELEMENT_SMTP_HOST = "smtp-host";
+    private String username;
+    private String password;
 
     public void configure(Configuration config) throws ConfigurationException {
-        this.smtpHost = config.getChild(ELEMENT_SMTP_HOST).getValue();
+        Configuration smtp = config.getChild("smtp");
+        this.smtpHost = smtp.getAttribute("host");
+        this.username = smtp.getAttribute("username", null);
+        if (this.username != null) {
+            this.password = smtp.getAttribute("password");
+        }
     }
 
 }

Modified: lenya/trunk/src/modules/notification/sitemap.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/notification/sitemap.xmap?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/modules/notification/sitemap.xmap (original)
+++ lenya/trunk/src/modules/notification/sitemap.xmap Tue Dec 12 04:24:18 2006
@@ -21,9 +21,17 @@
   <map:pipelines>
 
     <map:pipeline>
-      <map:match pattern="message.xml">
+      <map:match pattern="message/*">
       
+      <!--
         <map:generate src="fallback://lenya/modules/notification/content/message.xml"/>
+        -->
+        <map:generate type="session-attr">
+          <map:parameter name="attr-name" value="notification.dom"/>
+        </map:generate>
+        <map:transform type="i18n">
+          <map:parameter name="locale" value="{1}"/>
+        </map:transform>
         <map:serialize type="xml"/>
         
       </map:match>

Modified: lenya/trunk/src/targets/init-build.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/src/targets/init-build.xml?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/targets/init-build.xml (original)
+++ lenya/trunk/src/targets/init-build.xml Tue Dec 12 04:24:18 2006
@@ -103,6 +103,8 @@
         <exclude name="legal/**"/>
         <exclude name="WEB-INF/db/**"/>
         <exclude name="WEB-INF/xconf/**"/>
+        <!-- exclude the geronimo libraries, see http://issues.apache.org/bugzilla/show_bug.cgi?id=38587 -->
+        <exclude name="WEB-INF/lib/geronimo-*.jar"/>
         <exclude name="**/javac.jar"/>
       </fileset>
     </copy>

Modified: lenya/trunk/src/webapp/lenya/config/sitemap/generators.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya/config/sitemap/generators.xmap?view=diff&rev=486110&r1=486109&r2=486110
==============================================================================
--- lenya/trunk/src/webapp/lenya/config/sitemap/generators.xmap (original)
+++ lenya/trunk/src/webapp/lenya/config/sitemap/generators.xmap Tue Dec 12 04:24:18 2006
@@ -22,6 +22,10 @@
 
   <map:generator label="content" logger="sitemap.generator.lenyaMetaData"
     name="lenyaMetaData" pool-max="16"
-    src="org.apache.lenya.cms.cocoon.generation.LenyaMetaDataGenerator"/>
+    src="org.apache.lenya.cms.cocoon.generation.LenyaMetaDataGenerator"/>
+    
+  <map:generator label="content" logger="sitemap.generator.sessionattr"
+    name="session-attr" pool-max="16"
+    src="org.apache.cocoon.generation.SessionAttributeGenerator"/>
   
 </xmap>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org