PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
18package org.fusesource.scalate.console
19
20import _root_.javax.servlet.http.{HttpServletResponse, HttpServletRequest}
21import _root_.javax.servlet.ServletContext
22import _root_.javax.ws.rs._
23import _root_.org.fusesource.scalate.servlet.{ServletRenderContext, ServletTemplateEngine}
24import _root_.org.fusesource.scalate.util.Constraints._
25import javax.ws.rs.core.Context
26import org.fusesource.scalate.util.Log
27
28object Console extends Log; import Console._
29
30/**
31 * The Scalate development console
32 *
33 * @version $Revision : 1.1 $
34 */
35@Path("/scalate")
36class Console extends DefaultRepresentations {
37
38  @Context
39  var _servletContext: ServletContext = _
40  @Context
41  var _request: HttpServletRequest = _
42  @Context
43  var _response: HttpServletResponse = _
44
45  def servletContext: ServletContext = assertInjected(_servletContext, "servletContext")
46
47  def request: HttpServletRequest = assertInjected(_request, "request")
48
49  def response: HttpServletResponse = assertInjected(_response, "response")
50
51  def templateEngine = ServletTemplateEngine(servletContext)
52  def renderContext = new ServletRenderContext(templateEngine, request, response, servletContext)
53
54
55  @Path("archetypes/{name}")
56  def archetype(@PathParam("name") name: String) = new ArchetypeResource(this, name)
57
58
59  @POST
60  @Path("invalidateCachedTemplates")
61  def invalidateCachedTemplates() = {
62    info("Clearing template cache")
63    val engine = ServletTemplateEngine(servletContext)
64    engine.invalidateCachedTemplates
65  }
66}