/scalate-core/src/main/scala/org/fusesource/scalate/console/Console.scala

http://github.com/scalate/scalate · Scala · 66 lines · 32 code · 12 blank · 22 comment · 0 complexity · 0a12b9078a6efb1dce3db1807528d25c MD5 · raw file

  1. /**
  2. * Copyright (C) 2009-2011 the original author or authors.
  3. * See the notice.md file distributed with this work for additional
  4. * information regarding copyright ownership.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.fusesource.scalate.console
  19. import _root_.javax.servlet.http.{HttpServletResponse, HttpServletRequest}
  20. import _root_.javax.servlet.ServletContext
  21. import _root_.javax.ws.rs._
  22. import _root_.org.fusesource.scalate.servlet.{ServletRenderContext, ServletTemplateEngine}
  23. import _root_.org.fusesource.scalate.util.Constraints._
  24. import javax.ws.rs.core.Context
  25. import org.fusesource.scalate.util.Log
  26. object Console extends Log; import Console._
  27. /**
  28. * The Scalate development console
  29. *
  30. * @version $Revision : 1.1 $
  31. */
  32. @Path("/scalate")
  33. class Console extends DefaultRepresentations {
  34. @Context
  35. var _servletContext: ServletContext = _
  36. @Context
  37. var _request: HttpServletRequest = _
  38. @Context
  39. var _response: HttpServletResponse = _
  40. def servletContext: ServletContext = assertInjected(_servletContext, "servletContext")
  41. def request: HttpServletRequest = assertInjected(_request, "request")
  42. def response: HttpServletResponse = assertInjected(_response, "response")
  43. def templateEngine = ServletTemplateEngine(servletContext)
  44. def renderContext = new ServletRenderContext(templateEngine, request, response, servletContext)
  45. @Path("archetypes/{name}")
  46. def archetype(@PathParam("name") name: String) = new ArchetypeResource(this, name)
  47. @POST
  48. @Path("invalidateCachedTemplates")
  49. def invalidateCachedTemplates() = {
  50. info("Clearing template cache")
  51. val engine = ServletTemplateEngine(servletContext)
  52. engine.invalidateCachedTemplates
  53. }
  54. }