001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet.view.script; 018 019import java.nio.charset.Charset; 020import java.util.function.Supplier; 021 022import javax.script.Bindings; 023import javax.script.ScriptEngine; 024 025import org.springframework.lang.Nullable; 026 027/** 028 * Interface to be implemented by objects that configure and manage a 029 * JSR-223 {@link ScriptEngine} for automatic lookup in a web environment. 030 * Detected and used by {@link ScriptTemplateView}. 031 * 032 * @author Sebastien Deleuze 033 * @since 4.2 034 */ 035public interface ScriptTemplateConfig { 036 037 /** 038 * Return the {@link ScriptEngine} to use by the views. 039 */ 040 @Nullable 041 ScriptEngine getEngine(); 042 043 /** 044 * Return the engine supplier that will be used to instantiate the {@link ScriptEngine}. 045 * @since 5.2 046 */ 047 @Nullable 048 Supplier<ScriptEngine> getEngineSupplier(); 049 050 /** 051 * Return the engine name that will be used to instantiate the {@link ScriptEngine}. 052 */ 053 @Nullable 054 String getEngineName(); 055 056 /** 057 * Return whether to use a shared engine for all threads or whether to create 058 * thread-local engine instances for each thread. 059 */ 060 @Nullable 061 Boolean isSharedEngine(); 062 063 /** 064 * Return the scripts to be loaded by the script engine (library or user provided). 065 */ 066 @Nullable 067 String[] getScripts(); 068 069 /** 070 * Return the object where the render function belongs (optional). 071 */ 072 @Nullable 073 String getRenderObject(); 074 075 /** 076 * Return the render function name (optional). If not specified, the script templates 077 * will be evaluated with {@link ScriptEngine#eval(String, Bindings)}. 078 */ 079 @Nullable 080 String getRenderFunction(); 081 082 /** 083 * Return the content type to use for the response. 084 * @since 4.2.1 085 */ 086 @Nullable 087 String getContentType(); 088 089 /** 090 * Return the charset used to read script and template files. 091 */ 092 @Nullable 093 Charset getCharset(); 094 095 /** 096 * Return the resource loader path(s) via a Spring resource location. 097 */ 098 @Nullable 099 String getResourceLoaderPath(); 100 101}