Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Replace List with Seq: http://twitter.github.com/effectivescala/

  • Loading branch information...
commit 94d44bd3891f84cecf5972fe6fea70867f19a7b1 1 parent 0a3bd37
Ngoc Dao ngocdaothanh authored
4 CHANGELOG
View
@@ -5,9 +5,9 @@
* #76 Improve currentController in Scalate templates
2.0 (planned):
-* Integrate more closely with Akka
+* #104 Integrate more closely with Akka
-1.21 (planned):
+1.21:
* #103 Move Scalate template engine out to a separate project
* #100 Update JSON4S to 3.2.3
* #102 Update slf4j-api to 1.7.5
2  build.sbt
View
@@ -2,7 +2,7 @@ organization := "tv.cntt"
name := "xitrum"
-version := "1.21-SNAPSHOT"
+version := "1.21"
scalaVersion := "2.10.1"
2  src/main/scala/xitrum/SockJsHandler.scala
View
@@ -50,7 +50,7 @@ abstract class SockJsHandler extends Logger {
if (rawWebSocket) {
webSocketController.respondWebSocket(message)
} else {
- val json = Json.generate(List(message))
+ val json = Json.generate(Seq(message))
webSocketController.respondWebSocket("a" + json)
}
}
8 src/main/scala/xitrum/handler/AccessLog.scala
View
@@ -59,10 +59,10 @@ object AccessLog extends Logger {
controller.request.getMethod + " " +
controller.request.getUri + " -> " +
ControllerReflection.controllerActionName(controller.handlerEnv.action) +
- (if (env.uriParams.nonEmpty) ", uriParams: " + RequestEnv.inspectParamsWithFilter(env.uriParams .asInstanceOf[MMap[String, List[Any]]]) else "") +
- (if (env.bodyParams.nonEmpty) ", bodyParams: " + RequestEnv.inspectParamsWithFilter(env.bodyParams .asInstanceOf[MMap[String, List[Any]]]) else "") +
- (if (env.pathParams.nonEmpty) ", pathParams: " + RequestEnv.inspectParamsWithFilter(env.pathParams .asInstanceOf[MMap[String, List[Any]]]) else "") +
- (if (env.fileUploadParams.nonEmpty) ", fileUploadParams: " + RequestEnv.inspectParamsWithFilter(env.fileUploadParams.asInstanceOf[MMap[String, List[Any]]]) else "") +
+ (if (env.uriParams.nonEmpty) ", uriParams: " + RequestEnv.inspectParamsWithFilter(env.uriParams) else "") +
+ (if (env.bodyParams.nonEmpty) ", bodyParams: " + RequestEnv.inspectParamsWithFilter(env.bodyParams) else "") +
+ (if (env.pathParams.nonEmpty) ", pathParams: " + RequestEnv.inspectParamsWithFilter(env.pathParams) else "") +
+ (if (env.fileUploadParams.nonEmpty) ", fileUploadParams: " + RequestEnv.inspectParamsWithFilter(env.fileUploadParams) else "") +
" -> " + controller.response.getStatus.getCode +
", " + dt + " [ms]"
}
2  src/main/scala/xitrum/handler/ChannelPipelineFactory.scala
View
@@ -69,7 +69,7 @@ class ChannelPipelineFactory(https: Boolean) extends CPF {
* Upstream direction: first handler -> last handler
* Downstream direction: last handler -> first handler
*/
- def httpHandlers = List(
+ def httpHandlers = Seq(
// Up
new HttpRequestDecoder,
new HttpChunkAggregator(Config.xitrum.request.maxSizeInMB * 1024 * 1024),
4 src/main/scala/xitrum/handler/down/ResponseCacher.scala
View
@@ -78,7 +78,7 @@ object ResponseCacher extends Logger {
// uploadParams is not included in the key, only textParams is
private def makeCacheKey(controller: Controller): String = {
// See xitrum.scope.request.Params in xitrum/scope/request/package.scala
- val sortedMap = (new TreeMap[String, List[String]]) ++ controller.textParams
+ val sortedMap = (new TreeMap[String, Seq[String]]) ++ controller.textParams
val request = controller.request
val key =
@@ -89,7 +89,7 @@ object ResponseCacher extends Logger {
}
// See RequestEnv.inspectParamsWithFilter
- private def inspectSortedParams(params: SortedMap[String, List[String]]) = {
+ private def inspectSortedParams(params: SortedMap[String, Seq[String]]) = {
val sb = new StringBuilder
sb.append("{")
16 src/main/scala/xitrum/handler/up/BodyParser.scala
View
@@ -60,25 +60,25 @@ class BodyParser extends SimpleChannelUpstreamHandler with BadClientSilencer {
//----------------------------------------------------------------------------
// May throw exception on decode error
- private def decodeRequestBody(request: HttpRequest): (MMap[String, List[String]], MMap[String, List[FileUpload]]) = {
+ private def decodeRequestBody(request: HttpRequest): (MMap[String, Seq[String]], MMap[String, Seq[FileUpload]]) = {
val method = request.getMethod
if (!method.equals(HttpMethod.POST) && !method.equals(HttpMethod.PUT) && !method.equals(HttpMethod.PATCH))
- return (MMap[String, List[String]](), MMap[String, List[FileUpload]]())
+ return (MMap[String, Seq[String]](), MMap[String, Seq[FileUpload]]())
val requestContentType = request.getHeader(HttpHeaders.Names.CONTENT_TYPE)
if (requestContentType == null)
- return (MMap[String, List[String]](), MMap[String, List[FileUpload]]())
+ return (MMap[String, Seq[String]](), MMap[String, Seq[FileUpload]]())
val requestContentTypeLowerCase = requestContentType.toLowerCase
if (!requestContentTypeLowerCase.startsWith(HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED) &&
!requestContentTypeLowerCase.startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA))
- return (MMap[String, List[String]](), MMap[String, List[FileUpload]]())
+ return (MMap.empty[String, Seq[String]], MMap.empty[String, Seq[FileUpload]])
val decoder = new HttpPostRequestDecoder(factory, request)
val datas = decoder.getBodyHttpDatas
- val bodyParams = MMap[String, List[String]]()
- val fileParams = MMap[String, List[FileUpload]]()
+ val bodyParams = MMap[String, Seq[String]]()
+ val fileParams = MMap[String, Seq[FileUpload]]()
val it = datas.iterator
while (it.hasNext()) {
@@ -110,7 +110,7 @@ class BodyParser extends SimpleChannelUpstreamHandler with BadClientSilencer {
private def putOrAppendString(map: Params, key: String, value: String) {
if (!map.contains(key)) {
- map(key) = List(value)
+ map(key) = Seq(value)
} else {
val values = map(key)
map(key) = values :+ value
@@ -119,7 +119,7 @@ class BodyParser extends SimpleChannelUpstreamHandler with BadClientSilencer {
private def putOrAppendFileUpload(map: FileUploadParams, key: String, value: FileUpload) {
if (!map.contains(key)) {
- map(key) = List(value)
+ map(key) = Seq(value)
} else {
val values = map(key)
map(key) = values :+ value
2  src/main/scala/xitrum/handler/up/UriParser.scala
View
@@ -45,7 +45,7 @@ class UriParser extends SimpleChannelUpstreamHandler with BadClientSilencer {
val keySet = params.keySet
val it = keySet.iterator
- val ret = MMap[String, List[String]]()
+ val ret = MMap[String, Seq[String]]()
while (it.hasNext()) {
val key = it.next()
val values = params.get(key)
8 src/main/scala/xitrum/routing/Routes.scala
View
@@ -332,7 +332,7 @@ object Routes extends Logger {
// 0 = max2 <= max1
if (max2 == 0) {
if (max1 == 0) {
- pathParams = MMap[String, List[String]]()
+ pathParams = MMap[String, Seq[String]]()
return true
}
return false
@@ -340,20 +340,20 @@ object Routes extends Logger {
// 0 < max2 <= max1
- pathParams = MMap[String, List[String]]()
+ pathParams = MMap[String, Seq[String]]()
var i = 0 // i will go from 0 until max1
def matchRegex(rt: RouteToken, value: String): Boolean = {
rt.regex match {
case None =>
- pathParams(rt.value) = List(value)
+ pathParams(rt.value) = Seq(value)
true
case Some(r) =>
r.findFirstIn(value) match {
case None =>
false
case _ =>
- pathParams(rt.value) = List(value)
+ pathParams(rt.value) = Seq(value)
true
}
}
8 src/main/scala/xitrum/scope/request/ParamAccess.scala
View
@@ -66,11 +66,11 @@ trait ParamAccess {
}
}
- def params[T: TypeTag](key: String, coll: Params = null)(implicit d: T DefaultsTo String): List[T] = {
+ def params[T: TypeTag](key: String, coll: Params = null)(implicit d: T DefaultsTo String): Seq[T] = {
if (typeOf[T] <:< typeFileUpload) {
fileUploadParams.get(key) match {
case None => throw new MissingParam(key)
- case Some(values) => values.asInstanceOf[List[T]]
+ case Some(values) => values.asInstanceOf[Seq[T]]
}
} else {
val coll2 = if (coll == null) textParams else coll
@@ -79,9 +79,9 @@ trait ParamAccess {
}
}
- def paramso[T: TypeTag](key: String, coll: Params = null)(implicit d: T DefaultsTo String): Option[List[T]] = {
+ def paramso[T: TypeTag](key: String, coll: Params = null)(implicit d: T DefaultsTo String): Option[Seq[T]] = {
if (typeOf[T] <:< typeFileUpload) {
- fileUploadParams.get(key).asInstanceOf[Option[List[T]]]
+ fileUploadParams.get(key).asInstanceOf[Option[Seq[T]]]
} else {
val coll2 = if (coll == null) textParams else coll
coll2.get(key).map { values => values.map(convertText[T](_)) }
4 src/main/scala/xitrum/scope/request/RequestEnv.scala
View
@@ -6,7 +6,7 @@ import xitrum.Config
import xitrum.handler.HandlerEnv
object RequestEnv {
- def inspectParamsWithFilter(params: MMap[String, List[Any]]): String = {
+ def inspectParamsWithFilter(params: MMap[String, _ <: Seq[AnyRef]]): String = {
val sb = new StringBuilder
sb.append("{")
@@ -76,7 +76,7 @@ class RequestEnv {
* textParams.
*/
lazy val textParams: Params = {
- val ret = MMap[String, List[String]]()
+ val ret = MMap[String, Seq[String]]()
// The order is important because we want the later to overwrite the former
ret ++= handlerEnv.uriParams
4 src/main/scala/xitrum/scope/request/package.scala
View
@@ -4,6 +4,6 @@ import scala.collection.mutable.{Map => MMap}
import org.jboss.netty.handler.codec.http.multipart.FileUpload
package object request {
- type Params = MMap[String, List[String]]
- type FileUploadParams = MMap[String, List[FileUpload]]
+ type Params = MMap[String, Seq[String]]
+ type FileUploadParams = MMap[String, Seq[FileUpload]]
}
16 src/main/scala/xitrum/sockjs/NonWebSocketSession.scala
View
@@ -9,16 +9,16 @@ import xitrum.{Controller, SockJsHandler}
import xitrum.routing.Routes
sealed trait MessageToSession
-case object SubscribeByClient extends MessageToSession
-case class SendMessagesByClient(messages: List[String]) extends MessageToSession
-case class SendMessageByHandler(message: String) extends MessageToSession
-case object CloseByHandler extends MessageToSession
+case object SubscribeByClient extends MessageToSession
+case class SendMessagesByClient(messages: Seq[String]) extends MessageToSession
+case class SendMessageByHandler(message: String) extends MessageToSession
+case object CloseByHandler extends MessageToSession
sealed trait SubscribeResultToClient
-case object SubscribeResultToClientAnotherConnectionStillOpen extends SubscribeResultToClient
-case object SubscribeResultToClientClosed extends SubscribeResultToClient
-case class SubscribeResultToClientMessages(messages: List[String]) extends SubscribeResultToClient
-case object SubscribeResultToClientWaitForMessage extends SubscribeResultToClient
+case object SubscribeResultToClientAnotherConnectionStillOpen extends SubscribeResultToClient
+case object SubscribeResultToClientClosed extends SubscribeResultToClient
+case class SubscribeResultToClientMessages(messages: Seq[String]) extends SubscribeResultToClient
+case object SubscribeResultToClientWaitForMessage extends SubscribeResultToClient
sealed trait NotificationToClient
case class NotificationToClientMessage(message: String) extends NotificationToClient
22 src/main/scala/xitrum/sockjs/SockJsController.scala
View
@@ -233,7 +233,7 @@ class SockJsController extends Controller with SkipCSRFCheck {
private def receiveNotification(nonWebSocketSession: ActorRef): Receive = {
case NotificationToClientMessage(message) =>
- val json = Json.generate(List(message))
+ val json = Json.generate(Seq(message))
val quoted = SockJsController.quoteUnicode(json)
respondJs("a" + quoted + "\n")
context.stop(self)
@@ -262,9 +262,9 @@ class SockJsController extends Controller with SkipCSRFCheck {
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR)
respondText("Payload expected.")
} else {
- val messages: List[String] = try {
+ val messages: Seq[String] = try {
// body: ["m1", "m2"]
- Json.parse[List[String]](body)
+ Json.parse[Seq[String]](body)
} catch {
case scala.util.control.NonFatal(e) =>
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR)
@@ -367,7 +367,7 @@ class SockJsController extends Controller with SkipCSRFCheck {
private def receiveNotification(nonWebSocketSession: ActorRef): Receive = {
case NotificationToClientMessage(message) =>
- val json = Json.generate(List(message))
+ val json = Json.generate(Seq(message))
val quoted = SockJsController.quoteUnicode(json)
if (!respondStreamingWithLimit("a" + quoted + "\n")) context.stop(self)
@@ -470,7 +470,7 @@ class SockJsController extends Controller with SkipCSRFCheck {
private def receiveNotification(nonWebSocketSession: ActorRef): Receive = {
case NotificationToClientMessage(message) =>
val buffer = new StringBuilder
- val json = Json.generate(List(message))
+ val json = Json.generate(Seq(message))
val quoted = SockJsController.quoteUnicode(json)
buffer.append("<script>\np(\"a")
buffer.append(jsEscape(quoted))
@@ -566,7 +566,7 @@ class SockJsController extends Controller with SkipCSRFCheck {
private def receiveNotification(nonWebSocketSession: ActorRef): Receive = {
case NotificationToClientMessage(message) =>
val buffer = new StringBuilder
- val json = Json.generate(List(message))
+ val json = Json.generate(Seq(message))
val quoted = SockJsController.quoteUnicode(json)
buffer.append(callback + "(\"a")
buffer.append(jsEscape(quoted))
@@ -613,9 +613,9 @@ class SockJsController extends Controller with SkipCSRFCheck {
} else {
val sessionId = param("sessionId")
- val messages: List[String] = try {
+ val messages: Seq[String] = try {
// body: ["m1", "m2"]
- Json.parse[List[String]](body)
+ Json.parse[Seq[String]](body)
} catch {
case scala.util.control.NonFatal(e) =>
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR)
@@ -706,7 +706,7 @@ class SockJsController extends Controller with SkipCSRFCheck {
private def receiveNotification(nonWebSocketSession: ActorRef): Receive = {
case NotificationToClientMessage(message) =>
- val json = "a" + Json.generate(List(message))
+ val json = "a" + Json.generate(Seq(message))
val quoted = SockJsController.quoteUnicode(json)
if (!respondStreamingWithLimit(quoted, true)) context.stop(self)
@@ -763,11 +763,11 @@ class SockJsController extends Controller with SkipCSRFCheck {
// http://sockjs.github.com/sockjs-protocol/sockjs-protocol-0.3.3.html#section-69
if (body.isEmpty) return
- val messages: List[String] = try {
+ val messages: Seq[String] = try {
// body: can be ["m1", "m2"] or "m1"
// http://sockjs.github.com/sockjs-protocol/sockjs-protocol-0.3.3.html#section-61
val normalizedBody = if (body.startsWith("[")) body else "[" + body + "]"
- Json.parse[List[String]](normalizedBody)
+ Json.parse[Seq[String]](normalizedBody)
} catch {
case scala.util.control.NonFatal(e) =>
// No c frame is sent!
2  src/main/scala/xitrum/view/JS.scala
View
@@ -30,7 +30,7 @@ trait JS {
/**
* Do not use this to escape JSON, because they are different! For example
* JSON does not escape ' character, while JavaScript does. To escape JSON,
- * use JSON4S or xitrum.util.Json, e.g xitrum.util.Json.generate(List(string)).
+ * use JSON4S or xitrum.util.Json, e.g xitrum.util.Json.generate(Seq(string)).
*
* org.apache.commons.lang3.StringEscapeUtils is used internally.
*/
Please sign in to comment.
Something went wrong with that request. Please try again.