<commit_before>/**
 * Copyright (C) 2009-2010 the original author or authors.
 * See the notice.md file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.fusesource.scalate.servlet

import _root_.org.fusesource.scalate.layout.DefaultLayoutStrategy
import org.fusesource.scalate.{Binding, TemplateEngine}
import org.fusesource.scalate.util.ClassPathBuilder
import java.io.File
import scala.tools.nsc.Global
import javax.servlet.{FilterConfig, ServletContext, ServletConfig};

object ServletTemplateEngine {
  val templateEngineKey = classOf[ServletTemplateEngine].getName

  /**
   * Gets the current template engine
   *
   * @throws IllegalArgumentException if no template engine has been registered with the [[javax.servlet.ServletContext]]
   */
  def apply(servletContext: ServletContext): ServletTemplateEngine = {
    val answer = servletContext.getAttribute(templateEngineKey)
    if (answer == null) {
      throw new IllegalArgumentException("No ServletTemplateEngine instance registered on ServletContext for key " +
              templateEngineKey + ". Are you sure your web application has registered the Scalate TemplateEngineServlet?")
    }
    else {
      answer.asInstanceOf[ServletTemplateEngine]
    }
  }

  /**
   * Updates the current template engine - called on initialisation of the [[org.fusesource.scalate.TemplateEngineServlet]]
   */
  def update(servletContext: ServletContext, templateEngine: ServletTemplateEngine) {
    servletContext.setAttribute(templateEngineKey, templateEngine)
  }
}

/**
 * A TemplateEngine which initializes itself using a ServletConfig or a FilterConfig.
 *
 * @author <a href="http://hiramchirino.com"><NAME></a>
 */
class ServletTemplateEngine(val config: Config) extends TemplateEngine {
  bindings = List(Binding("context", classOf[ServletRenderContext].getName, true, isImplicit = true))

  // If the scalate.workingdir is not set, then just configure the working
  // directory under WEB_INF/_scalate
  if ( System.getProperty("scalate.workingdir", "").length == 0 ) {
    val path = config.getServletContext.getRealPath("WEB-INF")
    if (path != null) {
      workingDirectory = new File(path, "_scalate")
    }
  }
  <commit_msg>fixes #104 - typo in system property<commit_after>/**
 * Copyright (C) 2009-2010 the original author or authors.
 * See the notice.md file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.fusesource.scalate.servlet

import _root_.org.fusesource.scalate.layout.DefaultLayoutStrategy
import org.fusesource.scalate.{Binding, TemplateEngine}
import org.fusesource.scalate.util.ClassPathBuilder
import java.io.File
import scala.tools.nsc.Global
import javax.servlet.{FilterConfig, ServletContext, ServletConfig};

object ServletTemplateEngine {
  val templateEngineKey = classOf[ServletTemplateEngine].getName

  /**
   * Gets the current template engine
   *
   * @throws IllegalArgumentException if no template engine has been registered with the [[javax.servlet.ServletContext]]
   */
  def apply(servletContext: ServletContext): ServletTemplateEngine = {
    val answer = servletContext.getAttribute(templateEngineKey)
    if (answer == null) {
      throw new IllegalArgumentException("No ServletTemplateEngine instance registered on ServletContext for key " +
              templateEngineKey + ". Are you sure your web application has registered the Scalate TemplateEngineServlet?")
    }
    else {
      answer.asInstanceOf[ServletTemplateEngine]
    }
  }

  /**
   * Updates the current template engine - called on initialisation of the [[org.fusesource.scalate.TemplateEngineServlet]]
   */
  def update(servletContext: ServletContext, templateEngine: ServletTemplateEngine) {
    servletContext.setAttribute(templateEngineKey, templateEngine)
  }
}

/**
 * A TemplateEngine which initializes itself using a ServletConfig or a FilterConfig.
 *
 * @author <a href="http://hiramchirino.com"><NAME></a>
 */
class ServletTemplateEngine(val config: Config) extends TemplateEngine {
  bindings = List(Binding("context", classOf[ServletRenderContext].getName, true, isImplicit = true))

  // If the scalate.workdir is not set, then just configure the working
  // directory under WEB_INF/_scalate
  if ( System.getProperty("scalate.workdir", "").length == 0 ) {
    val path = config.getServletContext.getRealPath("WEB-INF")
    if (path != null) {
      workingDirectory = new File(path, "_scalate")
    }
  }
  
{'fraction_non_alphanumeric': 0.08766637089618456, 'fraction_numerical': 0.0051464063886424135, 'mean_word_length': 4.3069679849340865, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6893450', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1471, 'n_words': 497}