incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r955728 - in /incubator/esme/trunk/server/src/main/scala/org/apache/esme: external/Feed.scala model/Message.scala
Date Thu, 17 Jun 2010 20:20:09 GMT
Author: vdichev
Date: Thu Jun 17 20:20:09 2010
New Revision: 955728

URL: http://svn.apache.org/viewvc?rev=955728&view=rev
Log:
Fix potential XML parsing performance and stability issues.

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/external/Feed.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/external/Feed.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/external/Feed.scala?rev=955728&r1=955727&r2=955728&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/external/Feed.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/external/Feed.scala Thu Jun
17 20:20:09 2010
@@ -39,11 +39,14 @@ abstract class Feed(val user: User, val 
   import scala.xml._
 
   protected def dateFormats: List[SimpleDateFormat]
-  var dateFormat: SimpleDateFormat = _
+  // var dateFormat: SimpleDateFormat = _
 
   override def apply() = {
     
-    ( for (node <- (getEntries(XML.loadString(responseString))))
+    ( for {
+           xml <- PCDataXmlParser(responseString).toList
+           node <- xml.flatMap{ case e: Elem => List(e) case _ => Nil}
+         }
         yield UserCreatedMessage(
           if (user != null) {user.id} else 0,
           getText(node) + " " + getLink(node),
@@ -81,16 +84,9 @@ abstract class Feed(val user: User, val 
   
   protected def parseInternetDate(dateString: String): Date = {
     val fixedDateString = fixDateString(dateString)
-    if (dateFormat == null) dateFormats.find { df =>
-      try {
-        dateFormat = df
-        return df.parse(fixedDateString)
-        // true
-      } catch {
-        case pe: ParseException => false
-      }
-    }
-    dateFormat.parse(fixedDateString)
+    dateFormats.projection.flatMap(df => Helpers.tryo {
+      df.parse(fixedDateString)
+    }).head
   }
   
   protected def fixDateString(dateString: String) = {

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=955728&r1=955727&r2=955728&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 Thu Jun
17 20:20:09 2010
@@ -405,7 +405,7 @@ class Message extends LongKeyedMapper[Me
       })
   }
 
-  private lazy val originalXml = XML.loadString(text.is)
+  private lazy val originalXml = PCDataXmlParser(text.is).openOr(<message/>)
   
   lazy val toXHTML = transformBody(digestedXHTML)
     



Mime
View raw message