Permalink
Browse files

replace uses of scalatrabase with scalatra syntax

  • Loading branch information...
casualjim committed Dec 17, 2012
1 parent 16f9b98 commit 849110446fbf1023e729198d4cbbdedb951f99c3
Showing with 74 additions and 127 deletions.
  1. +4 −4 auth/src/main/scala/org/scalatra/auth/Scentry.scala
  2. +1 −1 auth/src/main/scala/org/scalatra/auth/ScentryAuthStore.scala
  3. +2 −2 auth/src/main/scala/org/scalatra/auth/ScentryStrategy.scala
  4. +2 −2 auth/src/main/scala/org/scalatra/auth/ScentrySupport.scala
  5. +2 −2 auth/src/main/scala/org/scalatra/auth/strategy/BasicAuthStrategy.scala
  6. +1 −1 auth/src/test/scala/org/scalatra/auth/ScentrySpec.scala
  7. +2 −2 commands/src/main/scala/org/scalatra/commands/CommandSupport.scala
  8. +1 −12 commands/src/main/scala/org/scalatra/commands/binding.scala
  9. +0 −6 commands/src/main/scala/org/scalatra/commands/json_commands.scala
  10. +1 −1 core/src/main/scala/org/scalatra/ApiFormats.scala
  11. +1 −1 core/src/main/scala/org/scalatra/CORSSupport.scala
  12. +1 −1 core/src/main/scala/org/scalatra/CookieSupport.scala
  13. +1 −1 core/src/main/scala/org/scalatra/CoreDsl.scala
  14. +2 −2 core/src/main/scala/org/scalatra/CsrfTokenSupport.scala
  15. +1 −1 core/src/main/scala/org/scalatra/GZipSupport.scala
  16. +1 −1 core/src/main/scala/org/scalatra/ScalatraBase.scala
  17. +1 −1 core/src/main/scala/org/scalatra/TypedParamSupport.scala
  18. +1 −1 core/src/main/scala/org/scalatra/UrlSupport.scala
  19. +1 −1 core/src/main/scala/org/scalatra/i18n/I18nSupport.scala
  20. +1 −1 core/src/main/scala/org/scalatra/package.scala
  21. +1 −1 core/src/main/scala/org/scalatra/servlet/AsyncSupport.scala
  22. +10 −41 core/src/main/scala/org/scalatra/util/conversion/conversions.scala
  23. +14 −4 core/src/test/scala/org/scalatra/GZipSupportTest.scala
  24. +3 −1 core/src/test/scala/org/scalatra/util/conversion/ConversionsSpecs.scala
  25. +2 −2 example/src/main/scala/org/scalatra/BasicAuthExample.scala
  26. +1 −1 json/src/main/scala/org/scalatra/json/JValueResult.scala
  27. +3 −20 json/src/main/scala/org/scalatra/json/JsonImplicitConversions.scala
  28. +1 −1 scalate/src/main/scala/org/scalatra/scalate/ScalateRenderSupport.scala
  29. +2 −2 slf4j/src/main/scala/org/scalatra/slf4j/ScalatraSlf4jRequestLogging.scala
  30. +2 −2 swagger-ext/src/main/scala/org/scalatra/swagger/SwaggerAuth.scala
  31. +1 −1 swagger-ext/src/main/scala/org/scalatra/swagger/SwaggerCommand.scala
  32. +1 −1 swagger-ext/src/test/scala/org/scalatra/swagger/SwaggerAuthSpec.scala
  33. +1 −1 swagger/src/main/scala/org/scalatra/swagger/JacksonSwaggerBase.scala
  34. +1 −1 swagger/src/main/scala/org/scalatra/swagger/NativeSwaggerBase.scala
  35. +2 −2 swagger/src/main/scala/org/scalatra/swagger/SwaggerBase.scala
  36. +2 −2 swagger/src/main/scala/org/scalatra/swagger/SwaggerSupport.scala
@@ -8,7 +8,7 @@ import org.scalatra.util.RicherString._
object Scentry {
- type StrategyFactory[UserType <: AnyRef] = ScalatraBase ScentryStrategy[UserType]
+ type StrategyFactory[UserType <: AnyRef] = ScalatraSyntax ScentryStrategy[UserType]
private val _globalStrategies = new mutable.HashMap[String, StrategyFactory[_ <: AnyRef]]()
@@ -29,14 +29,14 @@ object Scentry {
}
class Scentry[UserType <: AnyRef](
- app: ScalatraBase,
+ app: ScalatraSyntax,
serialize: PartialFunction[UserType, String],
deserialize: PartialFunction[String, UserType],
private[this] var _store: ScentryAuthStore) {
private[this] lazy val logger = Logger(getClass)
type StrategyType = ScentryStrategy[UserType]
- type StrategyFactory = ScalatraBase StrategyType
+ type StrategyFactory = ScalatraSyntax StrategyType
import Scentry._
@@ -57,7 +57,7 @@ class Scentry[UserType <: AnyRef](
def redirect(uri: String) { app.redirect(uri) }
def register(strategy: => ScentryStrategy[UserType]) {
- register(strategy.name, ((_: ScalatraBase) => strategy))
+ register(strategy.name, ((_: ScalatraSyntax) => strategy))
}
def register(name: String, strategyFactory: StrategyFactory) {
@@ -15,7 +15,7 @@ object ScentryAuthStore {
def invalidate()
}
- class CookieAuthStore(app: ScalatraBase with CookieSupport)(implicit cookieOptions: CookieOptions = CookieOptions(path = "/")) extends ScentryAuthStore {
+ class CookieAuthStore(app: ScalatraSyntax with CookieSupport)(implicit cookieOptions: CookieOptions = CookieOptions(path = "/")) extends ScentryAuthStore {
def get = app.cookies.get(Scentry.scentryAuthKey) getOrElse ""
@@ -7,15 +7,15 @@ import javax.servlet.http.{HttpSession, HttpServletRequest, Cookie}
trait ScentryStrategy[UserType <: AnyRef] {
- protected def app: ScalatraBase
+ protected def app: ScalatraSyntax
def name: String = "NameMe"
def registerWith(registrar: Scentry[UserType]) {
if (name == "NameMe") throwOverrideException
else registrar.register(name, createStrategy _)
}
- def createStrategy(app: ScalatraBase): this.type = {
+ def createStrategy(app: ScalatraSyntax): this.type = {
throwOverrideException
}
@@ -12,7 +12,7 @@ trait ScentryConfig {
}
trait ScentrySupport[UserType <: AnyRef] extends Handler with Initializable with CookieSupport {
- self: ScalatraBase
+ self: ScalatraSyntax
type ScentryConfiguration <: ScentryConfig
@@ -39,7 +39,7 @@ trait ScentrySupport[UserType <: AnyRef] extends Handler with Initializable with
private def initializeScentry = {
val store = self match {
case a: SessionSupport => new ScentryAuthStore.SessionAuthStore(a.session)
- case a: ScalatraBase with CookieSupport => new ScentryAuthStore.CookieAuthStore(a)
+ case a: ScalatraSyntax with CookieSupport => new ScentryAuthStore.CookieAuthStore(a)
case _ => throw new ScalatraException("Scentry needs either SessionSupport or CookieSupport mixed in.")
}
request.setAttribute(Scentry.ScentryRequestKey, new Scentry[UserType](self, toSession, fromSession, store))
@@ -24,7 +24,7 @@ trait RemoteAddress { self: ScentryStrategy[_] =>
* for more details on usage check:
* https://gist.github.com/732347
*/
-trait BasicAuthSupport[UserType <: AnyRef] { self: (ScalatraBase with ScentrySupport[UserType]) =>
+trait BasicAuthSupport[UserType <: AnyRef] { self: (ScalatraSyntax with ScentrySupport[UserType]) =>
def realm: String
@@ -71,7 +71,7 @@ object BasicAuthStrategy {
def password = credentials map { _._2 } getOrElse null
}
}
-abstract class BasicAuthStrategy[UserType <: AnyRef](protected val app: ScalatraBase, realm: String)
+abstract class BasicAuthStrategy[UserType <: AnyRef](protected val app: ScalatraSyntax, realm: String)
extends ScentryStrategy[UserType]
with RemoteAddress {
@@ -79,7 +79,7 @@ object ScentrySpec extends Specification with Mockito {
override def unauthenticated() { unauthenticatedCalled = true }
}
"allow registration of global strategies" in {
- Scentry.register("Bogus", (_: ScalatraBase) => s)
+ Scentry.register("Bogus", (_: ScalatraSyntax) => s)
Scentry.globalStrategies("Bogus").asInstanceOf[Scentry[User]#StrategyFactory](context) must be_==(s)
}
@@ -14,7 +14,7 @@ import grizzled.slf4j.Logger
/**
* Support for [[org.scalatra.commands.Command]] binding and validation.
*/
-trait CommandSupport extends ParamsValueReaderProperties { this: ScalatraBase =>
+trait CommandSupport extends ParamsValueReaderProperties { this: ScalatraSyntax =>
type CommandType <: Command
@@ -70,6 +70,6 @@ trait CommandSupport extends ParamsValueReaderProperties { this: ScalatraBase =>
}
-trait ParamsOnlyCommandSupport extends CommandSupport { this: ScalatraBase =>
+trait ParamsOnlyCommandSupport extends CommandSupport { this: ScalatraSyntax =>
type CommandType = ParamsOnlyCommand
}
@@ -34,7 +34,7 @@ object Binding {
type S = Nothing
implicit def sourceManifest: Manifest[S] = null
implicit def sourceZero: DefaultValue[S] = null
- implicit def typeConverter: (S) => Option[T] = null
+ implicit def typeConverter: TypeConverter[S, T] = null
def apply(toBind: Either[String, Option[S]]): Binding = null
def validateWith(validators:BindingValidator[T]*): Binding =
@@ -173,17 +173,6 @@ trait BindingImplicits extends DefaultImplicitConversions with BindingValidatorI
implicit def stringToSeqDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[String, Seq[Date]] =
stringToSeq(stringToDate)
- implicit def stringSeqToHeadDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], Date] =
- seqHead(stringToDate)
-
- implicit def stringSeqToHeadDateTime(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], DateTime] =
- seqHead(stringToDateTime)
-
- implicit def stringSeqToSeqDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], Seq[Date]] =
- seqToSeq(stringToDate)
-
- implicit def stringSeqToSeqDateTime(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[Seq[String], Seq[DateTime]] =
- seqToSeq(stringToDateTime)
}
object BindingImplicits extends BindingImplicits
@@ -18,12 +18,6 @@ trait JsonBindingImplicits extends BindingImplicits with JsonImplicitConversions
implicit def jsonToDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[JValue, Date] =
safeOption(_.extractOpt[String].flatMap(df.parse).map(_.toDate))
- implicit def jsonToSeqDate(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[JValue, Seq[Date]] =
- jsonToSeq(jsonToDate)
-
- implicit def jsonToSeqDateTime(implicit df: DateParser = JodaDateFormats.Web): TypeConverter[JValue, Seq[DateTime]] =
- jsonToSeq(jsonToDateTime)
-
}
trait JsonTypeConverterFactory[T] extends TypeConverterFactory[T] with JsonBindingImplicits {
@@ -22,7 +22,7 @@ object ApiFormats {
* $ - Maps formats to content types and vice versa
* $ - Augments the content-type inferrer to use the format
*/
-trait ApiFormats extends ScalatraBase {
+trait ApiFormats extends ScalatraSyntax {
/**
* A map of suffixes to content types.
*/
@@ -61,7 +61,7 @@ object CorsSupport {
"Content-Type").mkString(",")
}
-trait CorsSupport extends Handler with Initializable { self: ScalatraBase
+trait CorsSupport extends Handler with Initializable { self: ScalatraSyntax
import CorsSupport._
@@ -115,7 +115,7 @@ object CookieSupport {
val CookieOptionsKey = "org.scalatra.CookieOptions"
}
trait CookieSupport extends Handler with Initializable {
- self: ScalatraBase =>
+ self: ScalatraSyntax =>
import CookieSupport._
implicit def cookieOptions: CookieOptions = servletContext.get(CookieOptionsKey).orNull.asInstanceOf[CookieOptions]
@@ -117,7 +117,7 @@ trait CoreDsl extends Handler with Control with ServletApiImplicits {
* and a block as the action body. The return value of the block is
* rendered through the pipeline and sent to the client as the response body.
*
- * See [[org.scalatra.ScalatraBase#renderResponseBody]] for the detailed
+ * See [[org.scalatra.ScalatraSyntax#renderResponseBody]] for the detailed
* behaviour and how to handle your response body more explicitly, and see
* how different return types are handled.
*
@@ -36,7 +36,7 @@ object CsrfTokenSupport {
* request is prepared with `prepareCsrfToken`.
*/
trait CsrfTokenSupport {
- this: ScalatraBase with SessionSupport =>
+ this: ScalatraSyntax with SessionSupport =>
/**
* The key used to store the token on the session, as well as the parameter
@@ -85,7 +85,7 @@ trait CsrfTokenSupport {
protected def prepareCSRFToken() = prepareCsrfToken()
}
-trait XsrfTokenSupport { this: ScalatraBase with SessionSupport with CookieSupport =>
+trait XsrfTokenSupport { this: ScalatraSyntax with SessionSupport with CookieSupport =>
import XsrfTokenSupport._
/**
@@ -12,7 +12,7 @@ import javax.servlet.http.HttpServletResponseWrapper
* Scalatra handler for gzipped responses.
*/
trait GZipSupport extends Handler with Initializable {
- self: ScalatraBase =>
+ self: ScalatraSyntax =>
abstract override def handle(req: HttpServletRequest, res: HttpServletResponse) {
@@ -31,7 +31,7 @@ object ScalatraBase {
val ForceHttpsKey = "org.scalatra.ForceHttps"
import collection.JavaConverters._
- def getServletRegistration(app: ScalatraBase) = {
+ def getServletRegistration(app: ScalatraSyntax) = {
val registrations = app.servletContext.getServletRegistrations.values().asScala.toList
registrations.find(_.getClassName == app.getClass.getName)
}
@@ -1,4 +1,4 @@
package org.scalatra
@deprecated("This got folded into core, so you can remove the TypeParamSupport trait safely.", "2.2")
-trait TypedParamSupport extends ScalatraBase
+trait TypedParamSupport extends ScalatraSyntax
@@ -4,5 +4,5 @@ package org.scalatra
* Provides utility methods for the creation of URL strings.
* Supports context-relative and session-aware URLs. Should behave similarly to JSTL's <c:url> tag.
*/
-@deprecated("This functionality has been subsumed by ScalatraBase.", "2.1.0") // Since 2.1
+@deprecated("This functionality has been subsumed by ScalatraSyntax.", "2.1.0") // Since 2.1
trait UrlSupport
@@ -13,7 +13,7 @@ object I18nSupport {
trait I18nSupport {
- this: ScalatraBase with CookieSupport =>
+ this: ScalatraSyntax with CookieSupport =>
import I18nSupport._
@@ -22,7 +22,7 @@ package object scalatra
val MultiParamsKey = "org.scalatra.MultiParams"
- @deprecated("Use org.scalatra.servlet.ServletBase if you depend on the Servlet API, or org.scalatra.ScalatraBase if you don't.", "2.1.0")
+ @deprecated("Use org.scalatra.servlet.ServletBase if you depend on the Servlet API, or org.scalatra.ScalatraSyntax if you don't.", "2.1.0")
type ScalatraKernel = servlet.ServletBase
// class OptionDefaults[T](value: Option[T]) {
@@ -36,7 +36,7 @@ trait AsyncSupport extends ServletBase {
* The block of these methods is executed in a lightweight event-driven thread
* from Akka's dispatchers
*
- * See [[org.scalatra.ScalatraBase#renderResponseBody]] for the detailed
+ * See [[org.scalatra.ScalatraSyntax#renderResponseBody]] for the detailed
* behaviour and how to handle your response body more explicitly, and see
* how different return types are handled.
*
@@ -8,15 +8,19 @@ import scala.util.control.Exception.allCatch
import scala._
/**
- * Support types and implicits for [[org.scalatra.common.conversions.TypeConverter]].
+ * Support types and implicits for [[org.scalatra.util.conversion.TypeConverter]].
*/
trait TypeConverterSupport {
- implicit def safe[S, T](f: S => T): TypeConverter[S, T] = (s) => allCatch opt f(s)
+ implicit def safe[S, T](f: S => T): TypeConverter[S, T] = new TypeConverter[S, T] {
+ def apply(s: S): Option[T] = allCatch opt f(s)
+ }
/**
* Implicit convert a `(String) => Option[T]` function into a `TypeConverter[T]`
*/
- implicit def safeOption[S, T](f: S => Option[T]) = (s: S) => allCatch.withApply(_ => None)(f(s))
+ implicit def safeOption[S, T](f: S => Option[T]): TypeConverter[S, T] = new TypeConverter[S, T] {
+ def apply(v1: S): Option[T] = allCatch.withApply(_ => None)(f(v1))
+ }
}
@@ -25,8 +29,6 @@ object TypeConverterSupport extends TypeConverterSupport
trait BigDecimalImplicitConversions extends TypeConverterSupport { self: DefaultImplicitConversions =>
implicit val stringToBigDecimal: TypeConverter[String, BigDecimal] = safe(BigDecimal(_))
implicit val stringToSeqBigDecimal: TypeConverter[String, Seq[BigDecimal]] = stringToSeq(stringToBigDecimal)
- implicit val stringSeqToBigDecimal: TypeConverter[Seq[String], BigDecimal] = seqHead(stringToBigDecimal)
- implicit val stringSeqToSeqBigDecimal: TypeConverter[Seq[String], Seq[BigDecimal]] = seqToSeq(stringToBigDecimal)
}
/**
@@ -36,7 +38,7 @@ trait BigDecimalImplicitConversions extends TypeConverterSupport { self: Default
trait DefaultImplicitConversions extends TypeConverterSupport {
implicit val stringToBoolean: TypeConverter[String, Boolean] = safe { s => s.toUpperCase match {
- case "ON" | "TRUE" | "OK" | "1" | "CHECKED" => true
+ case "ON" | "TRUE" | "OK" | "1" | "CHECKED" | "YES" | "ENABLE" | "ENABLED" => true
case _ => false
} }
@@ -77,45 +79,12 @@ trait DefaultImplicitConversions extends TypeConverterSupport {
def stringToSeq[T:Manifest](elementConverter: TypeConverter[String, T], separator: String = ","): TypeConverter[String, Seq[T]] =
safe(s => s.split(separator).toSeq.flatMap(e => elementConverter(e.trim)))
- def seqHead[T:Manifest](elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], T] =
+ implicit def seqHead[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[Seq[String], T] =
safeOption(_.headOption.flatMap(elementConverter(_)))
- def seqToSeq[T:Manifest](elementConverter: TypeConverter[String, T]): TypeConverter[Seq[String], Seq[T]] =
+ implicit def seqToSeq[T](implicit elementConverter: TypeConverter[String, T], mf: Manifest[T]): TypeConverter[Seq[String], Seq[T]] =
safe(_.flatMap(elementConverter(_)))
- implicit val stringSeqToBoolean: TypeConverter[Seq[String], Boolean] = seqHead(stringToBoolean)
-
- implicit val stringSeqToFloat: TypeConverter[Seq[String], Float] = seqHead(stringToFloat)
-
- implicit val stringSeqToDouble: TypeConverter[Seq[String], Double] = seqHead(stringToDouble)
-
-
- implicit val stringSeqToByte: TypeConverter[Seq[String], Byte] = seqHead(stringToByte)
-
- implicit val stringSeqToShort: TypeConverter[Seq[String], Short] = seqHead(stringToShort)
-
- implicit val stringSeqToInt: TypeConverter[Seq[String], Int] = seqHead(stringToInt)
-
- implicit val stringSeqToLong: TypeConverter[Seq[String], Long] = seqHead(stringToLong)
-
- implicit val stringSeqToString: TypeConverter[Seq[String], String] = seqHead(stringToSelf)
-
- implicit val stringSeqToSeqBoolean: TypeConverter[Seq[String], Seq[Boolean]] = seqToSeq(stringToBoolean)
-
- implicit val stringSeqToSeqFloat: TypeConverter[Seq[String], Seq[Float]] = seqToSeq(stringToFloat)
-
- implicit val stringSeqToSeqDouble: TypeConverter[Seq[String], Seq[Double]] = seqToSeq(stringToDouble)
-
- implicit val stringSeqToSeqByte: TypeConverter[Seq[String], Seq[Byte]] = seqToSeq(stringToByte)
-
- implicit val stringSeqToSeqShort: TypeConverter[Seq[String], Seq[Short]] = seqToSeq(stringToShort)
-
- implicit val stringSeqToSeqInt: TypeConverter[Seq[String], Seq[Int]] = seqToSeq(stringToInt)
-
- implicit val stringSeqToSeqLong: TypeConverter[Seq[String], Seq[Long]] = seqToSeq(stringToLong)
-
- implicit val stringSeqToSeqString: TypeConverter[Seq[String], Seq[String]] = seqToSeq(stringToSelf)
-
}
object Conversions extends DefaultImplicitConversions {
Oops, something went wrong.

0 comments on commit 8491104

Please sign in to comment.