incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r885445 - in /incubator/esme/trunk/server/src/main/scala/org/apache/esme: api/RestAPI.scala model/Message.scala
Date Mon, 30 Nov 2009 15:17:30 GMT
Author: vdichev
Date: Mon Nov 30 15:17:30 2009
New Revision: 885445

URL: http://svn.apache.org/viewvc?rev=885445&view=rev
Log:
ESME-128 Provide API for messages in text or XHTML format

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala?rev=885445&r1=885444&r2=885445&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/RestAPI.scala Mon Nov 30
15:17:30 2009
@@ -41,7 +41,7 @@
 import model._
 import org.apache.esme.actor._
 
-import scala.xml.{NodeSeq, Text, Elem, XML}
+import scala.xml.{NodeSeq, Text, Elem, Node, XML}
 
 import scala.collection.mutable.ListBuffer
 import java.util.logging._
@@ -53,7 +53,12 @@
     case Req("api" :: "status" :: Nil, "", GetRequest) => status
     case Req("api" :: "login" :: Nil, "", PostRequest) => login
     case Req("api" :: "logout" :: Nil, "", GetRequest) => logout
-    case Req("api" :: "get_msgs" :: Nil, "", GetRequest) => getMsgs
+    case Req("api" :: "get_msgs" :: Nil, "", GetRequest) =>
+      () => getMsgs(_.toXml)
+    case Req("api" :: "get_xhtml_msgs" :: Nil, "", GetRequest) =>
+      () => getMsgs(_.toXHTML)
+    case Req("api" :: "get_text_msgs" :: Nil, "", GetRequest) =>
+      () => getMsgs(_.toPlainTextBody)
     case Req("api" :: "wait_for_msgs" :: Nil, "", GetRequest) =>
       waitForMsgs
       
@@ -313,7 +318,7 @@
     r
   }
 
-  def getMsgs(): LiftResponse = {
+  def getMsgs(format: Message => Node): LiftResponse = {
     val t: Box[NodeSeq] =
     for (tagName <- S.param("tag");
          tag <- Tag.find(By(Tag.name, tagName)))
@@ -322,7 +327,12 @@
     val r: Box[NodeSeq] = 
     t or (for (user <- calcUser ?~  S.?("base_rest_api_err_param_not_found", "User");
                val lst = Mailbox.mostRecentMessagesFor(user.id, 40))
-          yield lst.flatMap{ case (msg, why, _) => msg.toXml % why.attr})
+          yield lst.flatMap{ case (msg, why, _) =>
+            format(msg) match {
+              case e: Elem => e % why.attr
+              case x => x
+            }
+          })
     
     r
   }

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala?rev=885445&r1=885444&r2=885445&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala Mon Nov
30 15:17:30 2009
@@ -350,6 +350,20 @@
   }
 
   private lazy val originalXml = XML.loadString(text.is)
+  
+  def transformBody(ns: NodeSeq) = {
+    import scala.xml.transform.{RuleTransformer, RewriteRule}
+    toXml.map(new RuleTransformer(new RewriteRule{
+      override def transform(n: Node) = n match {
+        case e: Elem if "body" == e.label => <body>{ns}</body>
+        case _ => n
+      }
+    })).first
+  }
+  
+  lazy val toXHTML = transformBody(digestedXHTML)
+    
+  lazy val toPlainTextBody = transformBody(Text(getText))
 
   private [model] def saveTheTags() = synchronized {
     for (tag <- tagIds) {



Mime
View raw message