Replace CustomMustacheFactory constant with same constant from Script (CONTENT_TYPE_OPTION)

This commit is contained in:
javanna 2017-02-22 11:52:29 +01:00 committed by Luca Cavanna
parent 5c1924ad19
commit 9391c6ffa9
3 changed files with 8 additions and 11 deletions

View File

@ -51,8 +51,6 @@ import java.util.regex.Pattern;
public class CustomMustacheFactory extends DefaultMustacheFactory {
static final String CONTENT_TYPE_PARAM = "content_type";
static final String JSON_MIME_TYPE_WITH_CHARSET = "application/json; charset=UTF-8";
static final String JSON_MIME_TYPE = "application/json";
static final String PLAIN_TEXT_MIME_TYPE = "text/plain";

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.GeneralScriptException;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.SearchScript;
import org.elasticsearch.search.lookup.SearchLookup;
@ -43,8 +44,6 @@ import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Map;
import static org.elasticsearch.script.mustache.CustomMustacheFactory.CONTENT_TYPE_PARAM;
/**
* Main entry point handling template registration, compilation and
* execution.
@ -94,10 +93,10 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme
}
private CustomMustacheFactory createMustacheFactory(Map<String, String> params) {
if (params == null || params.isEmpty() || params.containsKey(CONTENT_TYPE_PARAM) == false) {
if (params == null || params.isEmpty() || params.containsKey(Script.CONTENT_TYPE_OPTION) == false) {
return new CustomMustacheFactory();
}
return new CustomMustacheFactory(params.get(CONTENT_TYPE_PARAM));
return new CustomMustacheFactory(params.get(Script.CONTENT_TYPE_OPTION));
}
@Override
@ -142,7 +141,7 @@ public final class MustacheScriptEngineService extends AbstractComponent impleme
**/
MustacheExecutableScript(CompiledScript template, Map<String, Object> vars) {
this.template = template;
this.vars = vars == null ? Collections.<String, Object>emptyMap() : vars;
this.vars = vars == null ? Collections.emptyMap() : vars;
}
@Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.test.ESTestCase;
@ -32,7 +33,6 @@ import java.util.Map;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.script.ScriptType.INLINE;
import static org.elasticsearch.script.mustache.CustomMustacheFactory.CONTENT_TYPE_PARAM;
import static org.elasticsearch.script.mustache.CustomMustacheFactory.JSON_MIME_TYPE;
import static org.elasticsearch.script.mustache.CustomMustacheFactory.PLAIN_TEXT_MIME_TYPE;
import static org.elasticsearch.script.mustache.CustomMustacheFactory.X_WWW_FORM_URLENCODED_MIME_TYPE;
@ -63,7 +63,7 @@ public class CustomMustacheFactoryTests extends ESTestCase {
public void testJsonEscapeEncoder() {
final ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
final Map<String, String> params = randomBoolean() ? singletonMap(CONTENT_TYPE_PARAM, JSON_MIME_TYPE) : emptyMap();
final Map<String, String> params = randomBoolean() ? singletonMap(Script.CONTENT_TYPE_OPTION, JSON_MIME_TYPE) : emptyMap();
Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);
@ -75,7 +75,7 @@ public class CustomMustacheFactoryTests extends ESTestCase {
public void testDefaultEncoder() {
final ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
final Map<String, String> params = singletonMap(CONTENT_TYPE_PARAM, PLAIN_TEXT_MIME_TYPE);
final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, PLAIN_TEXT_MIME_TYPE);
Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);
@ -87,7 +87,7 @@ public class CustomMustacheFactoryTests extends ESTestCase {
public void testUrlEncoder() {
final ScriptEngineService engine = new MustacheScriptEngineService(Settings.EMPTY);
final Map<String, String> params = singletonMap(CONTENT_TYPE_PARAM, X_WWW_FORM_URLENCODED_MIME_TYPE);
final Map<String, String> params = singletonMap(Script.CONTENT_TYPE_OPTION, X_WWW_FORM_URLENCODED_MIME_TYPE);
Mustache script = (Mustache) engine.compile(null, "{\"field\": \"{{value}}\"}", params);
CompiledScript compiled = new CompiledScript(INLINE, null, MustacheScriptEngineService.NAME, script);