1/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.clearsilver.jsilver.interpreter;
18
19import com.google.clearsilver.jsilver.autoescape.AutoEscapeOptions;
20import com.google.clearsilver.jsilver.autoescape.EscapeMode;
21import com.google.clearsilver.jsilver.functions.FunctionExecutor;
22import com.google.clearsilver.jsilver.resourceloader.ResourceLoader;
23import com.google.clearsilver.jsilver.template.DelegatingTemplateLoader;
24import com.google.clearsilver.jsilver.template.Template;
25import com.google.clearsilver.jsilver.template.TemplateLoader;
26
27/**
28 * TemplateLoader that loads InterpretedTemplates.
29 */
30public class InterpretedTemplateLoader implements DelegatingTemplateLoader {
31
32  private final TemplateFactory templateFactory;
33
34  private final FunctionExecutor globalFunctionExecutor;
35  private final AutoEscapeOptions autoEscapeOptions;
36  private TemplateLoader templateLoaderDelegate = this;
37
38  public InterpretedTemplateLoader(TemplateFactory templateFactory,
39      FunctionExecutor globalFunctionExecutor, AutoEscapeOptions autoEscapeOptions) {
40    this.templateFactory = templateFactory;
41    this.globalFunctionExecutor = globalFunctionExecutor;
42    this.autoEscapeOptions = autoEscapeOptions;
43  }
44
45  @Override
46  public void setTemplateLoaderDelegate(TemplateLoader templateLoaderDelegate) {
47    this.templateLoaderDelegate = templateLoaderDelegate;
48  }
49
50  @Override
51  public Template load(String templateName, ResourceLoader resourceLoader, EscapeMode escapeMode) {
52    return new InterpretedTemplate(templateLoaderDelegate, templateFactory.find(templateName,
53        resourceLoader, escapeMode), templateName, globalFunctionExecutor, autoEscapeOptions,
54        escapeMode);
55  }
56
57  @Override
58  public Template createTemp(String name, String content, EscapeMode escapingMode) {
59    return new InterpretedTemplate(templateLoaderDelegate, templateFactory.createTemp(content,
60        escapingMode), name, globalFunctionExecutor, autoEscapeOptions, escapingMode);
61  }
62}
63