esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r1099082 - in /esme/trunk/server/src/main/scala/org/apache/esme: lib/MsgParser.scala model/Message.scala
Date Tue, 03 May 2011 14:42:08 GMT
Author: vdichev
Date: Tue May  3 14:42:08 2011
New Revision: 1099082

URL: http://svn.apache.org/viewvc?rev=1099082&view=rev
Log:
Integrate Textile and ESME urls

Modified:
    esme/trunk/server/src/main/scala/org/apache/esme/lib/MsgParser.scala
    esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala

Modified: esme/trunk/server/src/main/scala/org/apache/esme/lib/MsgParser.scala
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/scala/org/apache/esme/lib/MsgParser.scala?rev=1099082&r1=1099081&r2=1099082&view=diff
==============================================================================
--- esme/trunk/server/src/main/scala/org/apache/esme/lib/MsgParser.scala (original)
+++ esme/trunk/server/src/main/scala/org/apache/esme/lib/MsgParser.scala Tue May  3 14:42:08
2011
@@ -69,7 +69,7 @@ object MsgParser extends TextileParsers(
                        cite |  span | code | delete | insert |
                        sup | sub | strong | html |
                        single_quote | quote | acronym | 
-                       shortUrl | atName | hashTag | charBlock)
+                       atName | hashTag | charBlock)
   }
 
   val punctRegex = java.util.regex.Pattern.compile("""\p{Punct}""")
@@ -80,8 +80,6 @@ object MsgParser extends TextileParsers(
 
   lazy val startSpace = rep(' ')
 
-  lazy val shortUrl: Parser[URL] = fragmentAddress ^^ {url => URL(UrlStore.make(url))}
-
   lazy val userNameStr: Parser[String] = alpha ~ rep(alpha | digit | '_') ^^ {
     case first ~ more => first + more.mkString
   }
@@ -168,11 +166,26 @@ object MsgParser extends TextileParsers(
 
   lazy val scheme: Parser[String] = (accept("http://") | accept("https://")) ^^ {_ mkString}
 
-  lazy val fragmentAddress: Parser[String] = httpUrl ~ opt( '#' ~> fragmentid ) ^^ {
+  override lazy val httpStr: Parser[String] = httpUrl ~ opt( '#' ~> fragmentid ) ^^ {
     case uri ~ None => uri
     case uri ~ Some(fragmentid) => uri + "#" + fragmentid
   }
-  
+
+  def truncateUrl(urlString: String, len: Int) =
+    if (urlString.length <= len)
+      urlString
+    else
+      urlString.substring(0, len - 3) + "..."
+
+  override lazy val url: Parser[Textile] = httpStr ^^ { u =>
+    URL(UrlStore.make(u), truncateUrl(u, 20))
+  }
+
+  override lazy val quote_url: Parser[Textile] = ('"' ~> rep(attribute) ~ chrsExcept('"',
'\n')) ~ ('"' ~> ':' ~> httpStr) ^^ {
+    case attr ~ fs ~ url =>
+      URL(UrlStore.make(url), fs)
+  }
+
   lazy val fragmentid: Parser[String] = rep( uchar ) ^^ {_ mkString}
   
   lazy val httpUrl: Parser[String] = scheme ~ login ~ urlpart ^^ {
@@ -462,10 +475,11 @@ case class HashTag(tag: Tag) extends Msg
   def toHtml = tag.toXml
 }
 
-case class URL(url: UrlStore) extends MsgInfo {
+case class URL(url: UrlStore, name: String) extends MsgInfo {
   def toHtml: NodeSeq =
     <url id={url.id.toString}
          url={url.url.toString}
+         name={name}
          uniqueId={url.uniqueId.is} >{url.url.toString}</url>
 }
 

Modified: esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala?rev=1099082&r1=1099081&r2=1099082&view=diff
==============================================================================
--- esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala (original)
+++ esme/trunk/server/src/main/scala/org/apache/esme/model/Message.scala Tue May  3 14:42:08
2011
@@ -401,20 +401,17 @@ class Message extends LongKeyedMapper[Me
 
         case e: Elem if e.label == "url" =>
           e.attribute("url").flatMap(url =>
-            e.attribute("uniqueId").map { id =>
-              val href =
-                if (pool.defined_?)
-                  // disable shortener to avoid popularity statistics
-                  url.toString
-                else
-                  "/u/" + id
-              def truncateUrl(urlString: String, len: Int) =
-                if (urlString.length <= len)
-                  urlString
-                else
-                  urlString.substring(0, len - 3) + "..."
-              <xml:group> <a class="tiplelement" href={root+href} target="_blank"
title={url}>{truncateUrl(url.toString, 20)}</a> </xml:group>
-            }
+            e.attribute("name").flatMap(name =>
+              e.attribute("uniqueId").map { id =>
+                val href =
+                  if (pool.defined_?)
+                    // disable shortener to avoid popularity statistics
+                    url.toString
+                  else
+                    root + "/u/" + id
+                <xml:group> <a class="tiplelement" href={href} target="_blank" title={name}>{name}</a>
</xml:group>
+              }
+            )
           ).getOrElse(Text("") )
 
         case x => x



Mime
View raw message