You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by eh...@apache.org on 2020/09/04 01:11:26 UTC
[lucene-solr] 01/10: remove solr/contrib/velocity
This is an automated email from the ASF dual-hosted git repository.
ehatcher pushed a commit to branch jira/solr-14792
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 1a72db7215ed606d78cbf3dbd67af356deec3330
Author: Erik Hatcher <er...@lucidworks.com>
AuthorDate: Thu Sep 3 14:16:21 2020 -0400
remove solr/contrib/velocity
---
solr/contrib/velocity/build.gradle | 33 --
.../java/org/apache/solr/response/PageTool.java | 92 ----
.../solr/response/SolrVelocityResourceLoader.java | 61 ---
.../solr/response/VelocityResponseWriter.java | 468 ---------------------
.../src/java/org/apache/solr/response/package.html | 23 -
solr/contrib/velocity/src/java/overview.html | 21 -
.../velocity/src/resources/VM_global_library.vm | 4 -
solr/contrib/velocity/src/resources/_macros.vm | 70 ---
solr/contrib/velocity/src/resources/macros.vm | 3 -
.../velocity/src/resources/velocity/_default.vm | 14 -
.../velocity/src/resources/velocity/browse.vm | 73 ----
.../velocity/src/resources/velocity/error.vm | 4 -
.../velocity/src/resources/velocity/facets.vm | 23 -
.../velocity/src/resources/velocity/footer.vm | 19 -
.../velocity/src/resources/velocity/head.vm | 185 --------
.../contrib/velocity/src/resources/velocity/hit.vm | 27 --
.../velocity/src/resources/velocity/layout.vm | 19 -
.../src/resources/velocity/resources.properties | 6 -
.../src/resources/velocity/results_list.vm | 3 -
.../velocity/src/test-files/velocity/file.vm | 1 -
.../velocity/solr/collection1/conf/schema.xml | 26 --
.../velocity/solr/collection1/conf/solrconfig.xml | 52 ---
.../solr/collection1/conf/velocity-init.properties | 18 -
.../collection1/conf/velocity/VM_global_library.vm | 3 -
.../solr/collection1/conf/velocity/encoding.vm | 1 -
.../solr/collection1/conf/velocity/layout.vm | 1 -
.../solr/collection1/conf/velocity/locale.vm | 1 -
.../collection1/conf/velocity/locale_number.vm | 1 -
.../solr/collection1/conf/velocity/macros.vm | 3 -
.../solr/collection1/conf/velocity/numFound.vm | 1 -
.../collection1/conf/velocity/outside_the_box.vm | 4 -
.../solr/collection1/conf/velocity/resource_get.vm | 1 -
.../conf/velocity/sandbox_intersection.vm | 5 -
.../conf/velocity/test_macro_legacy_support.vm | 1 -
.../conf/velocity/test_macro_overridden.vm | 1 -
.../conf/velocity/test_macro_visible.vm | 1 -
solr/contrib/velocity/src/test/custom_tool.vm | 19 -
solr/contrib/velocity/src/test/foreach.vm | 14 -
.../test/org/apache/solr/velocity/MockTool.java | 34 --
.../solr/velocity/VelocityResponseWriterTest.java | 318 --------------
.../src/test/velocity/resources.properties | 18 -
.../src/test/velocity/resources_en_UK.properties | 18 -
42 files changed, 1690 deletions(-)
diff --git a/solr/contrib/velocity/build.gradle b/solr/contrib/velocity/build.gradle
deleted file mode 100644
index b17b38b..0000000
--- a/solr/contrib/velocity/build.gradle
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-
-apply plugin: 'java-library'
-
-description = 'Solr Velocity Response Writer'
-
-dependencies {
- implementation project(':solr:core')
-
- implementation('org.apache.velocity.tools:velocity-tools-view-jsp', {
- exclude group: "commons-beanutils", module: "commons-beanutils"
- exclude group: "org.apache.commons", module: "commons-digester3"
- exclude group: "com.github.cliftonlabs", module: "json-simple"
- })
-
- testImplementation project(':solr:test-framework')
-}
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/PageTool.java b/solr/contrib/velocity/src/java/org/apache/solr/response/PageTool.java
deleted file mode 100644
index 193c89b..0000000
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/PageTool.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.solr.response;
-
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.search.DocList;
-import org.apache.solr.search.DocSlice;
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.SolrException;
-
-/**
- * This class is used by the Velocity response writer to provide a consistent paging tool for use by templates.
- *
- * TODO: add more details
- */
-public class PageTool {
- private long start;
- private int results_per_page = 10;
- private long results_found;
- private int page_count;
- private int current_page_number;
-
- public PageTool(SolrQueryRequest request, SolrQueryResponse response) {
- String rows = request.getParams().get("rows");
-
- if (rows != null) {
- results_per_page = Integer.parseInt(rows);
- }
- //TODO: Handle group by results
- Object docs = response.getResponse();
- if (docs != null) {
- if (docs instanceof DocSlice) {
- results_found = ((DocSlice) docs).matches();
- start = ((DocSlice) docs).offset();
- } else if(docs instanceof ResultContext) {
- DocList dl = ((ResultContext) docs).getDocList();
- results_found = dl.matches();
- start = dl.offset();
- } else if(docs instanceof SolrDocumentList) {
- SolrDocumentList doc_list = (SolrDocumentList) docs;
- results_found = doc_list.getNumFound();
- start = doc_list.getStart();
- } else {
- throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Unknown response type "+docs+". Expected one of DocSlice, ResultContext or SolrDocumentList");
- }
- }
-
- page_count = (int) Math.ceil(results_found / (double) results_per_page);
- current_page_number = (int) Math.ceil(start / (double) results_per_page) + (page_count > 0 ? 1 : 0);
- }
-
- public long getStart() {
- return start;
- }
-
- public int getResults_per_page() {
- return results_per_page;
- }
-
- public long getResults_found() {
- return results_found;
- }
-
- public int getPage_count() {
- return page_count;
- }
-
- public int getCurrent_page_number() {
- return current_page_number;
- }
-
- @Override
- public String toString() {
- return "Found " + results_found +
- " Page " + current_page_number + " of " + page_count +
- " Starting at " + start + " per page " + results_per_page;
- }
-}
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
deleted file mode 100644
index bf778e1..0000000
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.solr.response;
-
-import java.io.IOException;
-import java.io.Reader;
-
-import org.apache.solr.core.SolrResourceLoader;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.runtime.resource.loader.ResourceLoader;
-import org.apache.velocity.util.ExtProperties;
-
-/**
- * Velocity resource loader wrapper around Solr resource loader
- */
-public class SolrVelocityResourceLoader extends ResourceLoader {
- private SolrResourceLoader loader;
-
- public SolrVelocityResourceLoader(SolrResourceLoader loader) {
- super();
- this.loader = loader;
- }
-
- @Override
- public void init(ExtProperties extendedProperties) {
- }
-
- @Override
- public Reader getResourceReader(String source, String encoding) throws ResourceNotFoundException {
- try {
- return buildReader(loader.openResource("velocity/" + source), encoding);
- } catch (IOException ioe) {
- throw new ResourceNotFoundException(ioe);
- }
- }
-
- @Override
- public boolean isSourceModified(Resource resource) {
- return false;
- }
-
- @Override
- public long getLastModified(Resource resource) {
- return 0;
- }
-}
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
deleted file mode 100644
index 58d8b2b..0000000
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.solr.response;
-
-import java.io.File;
-import java.io.FilePermission;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.invoke.MethodHandles;
-import java.nio.charset.StandardCharsets;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.Permissions;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.PropertyPermission;
-import java.util.ResourceBundle;
-
-import org.apache.solr.client.solrj.SolrResponse;
-import org.apache.solr.client.solrj.response.QueryResponse;
-import org.apache.solr.client.solrj.response.SolrResponseBase;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.util.plugin.SolrCoreAware;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-import org.apache.velocity.tools.generic.CollectionTool;
-import org.apache.velocity.tools.generic.ComparisonDateTool;
-import org.apache.velocity.tools.generic.DisplayTool;
-import org.apache.velocity.tools.generic.EscapeTool;
-import org.apache.velocity.tools.generic.LocaleConfig;
-import org.apache.velocity.tools.generic.MathTool;
-import org.apache.velocity.tools.generic.NumberTool;
-import org.apache.velocity.tools.generic.ResourceTool;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.solr.common.params.CommonParams.SORT;
-
-public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAware {
- // init param names, these are _only_ loaded at init time (no per-request control of these)
- // - multiple different named writers could be created with different init params
- public static final String TEMPLATE_BASE_DIR = "template.base.dir";
- public static final String PROPERTIES_FILE = "init.properties.file";
-
- // System property names, these are _only_ loaded at node startup (no per-request control of these)
- public static final String SOLR_RESOURCE_LOADER_ENABLED = "velocity.resourceloader.solr.enabled";
-
- // request param names
- public static final String TEMPLATE = "v.template";
- public static final String LAYOUT = "v.layout";
- public static final String LAYOUT_ENABLED = "v.layout.enabled";
- public static final String CONTENT_TYPE = "v.contentType";
- public static final String JSON = "v.json";
- public static final String LOCALE = "v.locale";
-
- public static final String TEMPLATE_EXTENSION = ".vm";
- public static final String DEFAULT_CONTENT_TYPE = "text/html;charset=UTF-8";
- public static final String JSON_CONTENT_TYPE = "application/json;charset=UTF-8";
-
- private File fileResourceLoaderBaseDir;
- private String initPropertiesFileName; // used just to hold from init() to inform()
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private Properties velocityInitProps = new Properties();
- private Map<String,String> customTools = new HashMap<String,String>();
-
- @Override
- public void init(@SuppressWarnings({"rawtypes"})NamedList args) {
- log.warn("VelocityResponseWriter is deprecated. This may be removed in future Solr releases. Please SOLR-14065.");
- fileResourceLoaderBaseDir = null;
- String templateBaseDir = (String) args.get(TEMPLATE_BASE_DIR);
-
- if (templateBaseDir != null && !templateBaseDir.isEmpty()) {
- fileResourceLoaderBaseDir = new File(templateBaseDir).getAbsoluteFile();
- if (!fileResourceLoaderBaseDir.exists()) { // "*not* exists" condition!
- log.warn("{} specified does not exist: {}", TEMPLATE_BASE_DIR, fileResourceLoaderBaseDir);
- fileResourceLoaderBaseDir = null;
- } else {
- if (!fileResourceLoaderBaseDir.isDirectory()) { // "*not* a directory" condition
- log.warn("{} specified is not a directory: {}", TEMPLATE_BASE_DIR, fileResourceLoaderBaseDir);
- fileResourceLoaderBaseDir = null;
- }
- }
- }
-
- initPropertiesFileName = (String) args.get(PROPERTIES_FILE);
-
- @SuppressWarnings({"rawtypes"})
- NamedList tools = (NamedList)args.get("tools");
- if (tools != null) {
- for(Object t : tools) {
- @SuppressWarnings({"rawtypes"})
- Map.Entry tool = (Map.Entry)t;
- customTools.put(tool.getKey().toString(), tool.getValue().toString());
- }
- }
- }
-
- @Override
- public void inform(SolrCore core) {
- // need to leverage SolrResourceLoader, so load init.properties.file here instead of init()
- if (initPropertiesFileName != null) {
- try {
- velocityInitProps.load(new InputStreamReader(core.getResourceLoader().openResource(initPropertiesFileName), StandardCharsets.UTF_8));
- } catch (IOException e) {
- log.warn("Error loading {} specified property file: {}", PROPERTIES_FILE, initPropertiesFileName, e);
- }
- }
- }
-
- @Override
- public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
- String contentType = request.getParams().get(CONTENT_TYPE);
-
- // Use the v.contentType specified, or either of the default content types depending on the presence of v.json
- return (contentType != null) ? contentType : ((request.getParams().get(JSON) == null) ? DEFAULT_CONTENT_TYPE : JSON_CONTENT_TYPE);
- }
-
- @Override
- public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
- // run doWrite() with the velocity sandbox
- try {
- AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
- @Override
- public Void run() throws IOException {
- doWrite(writer, request, response);
- return null;
- }
- }, VELOCITY_SANDBOX);
- } catch (PrivilegedActionException e) {
- throw (IOException) e.getException();
- }
- }
-
- // sandbox for velocity code
- // TODO: we could read in a policy file instead, in case someone needs to tweak it?
- private static final AccessControlContext VELOCITY_SANDBOX;
- static {
- Permissions permissions = new Permissions();
- // TODO: restrict the scope of this! we probably only need access to classpath
- permissions.add(new FilePermission("<<ALL FILES>>", "read,readlink"));
- // properties needed by SolrResourceLoader (called from velocity code)
- permissions.add(new PropertyPermission("jetty.testMode", "read"));
- permissions.add(new PropertyPermission("solr.allow.unsafe.resourceloading", "read"));
- // properties needed by log4j (called from velocity code)
- permissions.add(new PropertyPermission("java.version", "read"));
- // needed by velocity duck-typing
- permissions.add(new RuntimePermission("accessDeclaredMembers"));
- permissions.setReadOnly();
- VELOCITY_SANDBOX = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, permissions) });
- }
-
- private void doWrite(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
- VelocityEngine engine = createEngine(request); // TODO: have HTTP headers available for configuring engine
-
- Template template = getTemplate(engine, request);
-
- VelocityContext context = createContext(request, response);
- context.put("engine", engine); // for $engine.resourceExists(...)
-
- String layoutTemplate = request.getParams().get(LAYOUT);
- boolean layoutEnabled = request.getParams().getBool(LAYOUT_ENABLED, true) && layoutTemplate != null;
-
- String jsonWrapper = request.getParams().get(JSON);
- boolean wrapResponse = layoutEnabled || jsonWrapper != null;
-
- // create output
- if (!wrapResponse) {
- // straight-forward template/context merge to output
- template.merge(context, writer);
- }
- else {
- // merge to a string buffer, then wrap with layout and finally as JSON
- StringWriter stringWriter = new StringWriter();
- template.merge(context, stringWriter);
-
- if (layoutEnabled) {
- context.put("content", stringWriter.toString());
- stringWriter = new StringWriter();
- try {
- engine.getTemplate(layoutTemplate + TEMPLATE_EXTENSION).merge(context, stringWriter);
- } catch (Exception e) {
- throw new IOException(e.getMessage());
- }
- }
-
- if (jsonWrapper != null) {
- for (int i=0; i<jsonWrapper.length(); i++) {
- if (!Character.isJavaIdentifierPart(jsonWrapper.charAt(i))) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Invalid function name for " + JSON + ": '" + jsonWrapper + "'");
- }
- }
- writer.write(jsonWrapper + "(");
- writer.write(getJSONWrap(stringWriter.toString()));
- writer.write(')');
- } else { // using a layout, but not JSON wrapping
- writer.write(stringWriter.toString());
- }
- }
- }
-
- @SuppressWarnings({"unchecked"})
- private VelocityContext createContext(SolrQueryRequest request, SolrQueryResponse response) {
- VelocityContext context = new VelocityContext();
-
- // Register useful Velocity "tools"
- String locale = request.getParams().get(LOCALE);
- @SuppressWarnings({"rawtypes"})
- Map toolConfig = new HashMap();
- toolConfig.put("locale", locale);
-
-
- context.put("log", log); // TODO: add test; TODO: should this be overridable with a custom "log" named tool?
- context.put("esc", new EscapeTool());
- context.put("date", new ComparisonDateTool());
- context.put(SORT, new CollectionTool());
-
- MathTool mathTool = new MathTool();
- mathTool.configure(toolConfig);
- context.put("math", mathTool);
-
- NumberTool numberTool = new NumberTool();
- numberTool.configure(toolConfig);
- context.put("number", numberTool);
-
-
- DisplayTool displayTool = new DisplayTool();
- displayTool.configure(toolConfig);
- context.put("display", displayTool);
-
- ResourceTool resourceTool = new SolrVelocityResourceTool(request.getCore().getSolrConfig().getResourceLoader().getClassLoader());
- resourceTool.configure(toolConfig);
- context.put("resource", resourceTool);
-
- if (request.getCore().getCoreDescriptor().isConfigSetTrusted()) {
- // Load custom tools, only if in a trusted configset
-
- /*
- // Custom tools, specified in config as:
- <queryResponseWriter name="velocityWithCustomTools" class="solr.VelocityResponseWriter">
- <lst name="tools">
- <str name="mytool">com.example.solr.velocity.MyTool</str>
- </lst>
- </queryResponseWriter>
- */
- // Custom tools can override any of the built-in tools provided above, by registering one with the same name
- if (request.getCore().getCoreDescriptor().isConfigSetTrusted()) {
- for (Map.Entry<String, String> entry : customTools.entrySet()) {
- String name = entry.getKey();
- // TODO: at least log a warning when one of the *fixed* tools classes is same name with a custom one, currently silently ignored
- Object customTool = SolrCore.createInstance(entry.getValue(), Object.class, "VrW custom tool: " + name, request.getCore(), request.getCore().getResourceLoader());
- if (customTool instanceof LocaleConfig) {
- ((LocaleConfig) customTool).configure(toolConfig);
- }
- context.put(name, customTool);
- }
- }
-
- // custom tools _cannot_ override context objects added below, like $request and $response
- }
-
-
- // Turn the SolrQueryResponse into a SolrResponse.
- // QueryResponse has lots of conveniences suitable for a view
- // Problem is, which SolrResponse class to use?
- // One patch to SOLR-620 solved this by passing in a class name as
- // as a parameter and using reflection and Solr's class loader to
- // create a new instance. But for now the implementation simply
- // uses QueryResponse, and if it chokes in a known way, fall back
- // to bare bones SolrResponseBase.
- // Can this writer know what the handler class is? With echoHandler=true it can get its string name at least
- SolrResponse rsp = new QueryResponse();
- NamedList<Object> parsedResponse = BinaryResponseWriter.getParsedResponse(request, response);
- try {
- rsp.setResponse(parsedResponse);
-
- // page only injected if QueryResponse works
- context.put("page", new PageTool(request, response)); // page tool only makes sense for a SearchHandler request
- context.put("debug",((QueryResponse)rsp).getDebugMap());
- } catch (ClassCastException e) {
- // known edge case where QueryResponse's extraction assumes "response" is a SolrDocumentList
- // (AnalysisRequestHandler emits a "response")
- rsp = new SolrResponseBase();
- rsp.setResponse(parsedResponse);
- }
-
- context.put("request", request);
- context.put("response", rsp);
-
- return context;
- }
-
- private VelocityEngine createEngine(SolrQueryRequest request) {
-
- boolean trustedMode = request.getCore().getCoreDescriptor().isConfigSetTrusted();
-
-
- VelocityEngine engine = new VelocityEngine();
-
- // load the built-in _macros.vm first, then load VM_global_library.vm for legacy (pre-5.0) support,
- // and finally allow macros.vm to have the final say and override anything defined in the preceding files.
- engine.setProperty(RuntimeConstants.VM_LIBRARY, "_macros.vm,VM_global_library.vm,macros.vm");
-
- // Standard templates autoload, but not the macro one(s), by default, so let's just make life
- // easier, and consistent, for macro development too.
- engine.setProperty(RuntimeConstants.VM_LIBRARY_AUTORELOAD, "true");
-
- /*
- Set up Velocity resource loader(s)
- terminology note: "resource loader" is overloaded here, there is Solr's resource loader facility for plugins,
- and there are Velocity template resource loaders. It's confusing, they overlap: there is a Velocity resource
- loader that loads templates from Solr's resource loader (SolrVelocityResourceLoader).
-
- The Velocity resource loader order is `[file,][solr],builtin` intentionally ordered in this manner.
- The "file" resource loader, enabled when the configset is trusted and `template.base.dir` is specified as a
- response writer init property.
-
- The "solr" resource loader, enabled when the configset is trusted, and provides templates from a velocity/
- sub-tree in either the classpath or under conf/.
-
- By default, only "builtin" resource loader is enabled, providing tenplates from builtin Solr .jar files.
-
- The basic browse templates are built into
- this plugin, but can be individually overridden by placing a same-named template in the template.base.dir specified
- directory, or within a trusted configset's velocity/ directory.
- */
- ArrayList<String> loaders = new ArrayList<String>();
- if ((fileResourceLoaderBaseDir != null) && trustedMode) {
- loaders.add("file");
- engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, fileResourceLoaderBaseDir.getAbsolutePath());
- }
- if (trustedMode) {
- // The solr resource loader serves templates under a velocity/ subtree from <lib>, conf/,
- // or SolrCloud's configuration tree. Or rather the other way around, other resource loaders are rooted
- // from the top, whereas this is velocity/ sub-tree rooted.
- loaders.add("solr");
- engine.setProperty("solr.resource.loader.instance", new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader()));
- }
-
- // Always have the built-in classpath loader. This is needed when using VM_LIBRARY macros, as they are required
- // to be present if specified, and we want to have a nice macros facility built-in for users to use easily, and to
- // extend in custom ways.
- loaders.add("builtin");
- engine.setProperty("builtin.resource.loader.instance", new ClasspathResourceLoader());
-
- engine.setProperty(RuntimeConstants.RESOURCE_LOADER, String.join(",", loaders));
-
-
- engine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
- engine.setProperty(RuntimeConstants.SPACE_GOBBLING, RuntimeConstants.SpaceGobbling.LINES.toString());
-
- // install a class/package restricting uberspector
- engine.setProperty(RuntimeConstants.UBERSPECT_CLASSNAME,"org.apache.velocity.util.introspection.SecureUberspector");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_PACKAGES,"java.lang.reflect");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.Class");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.ClassLoader");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.Compiler");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.InheritableThreadLocal");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.Package");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.Process");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.Runtime");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.RuntimePermission");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.SecurityManager");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.System");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.Thread");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.ThreadGroup");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"java.lang.ThreadLocal");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"org.apache.solr.core.SolrResourceLoader");
- engine.addProperty(RuntimeConstants.INTROSPECTOR_RESTRICT_CLASSES,"org.apache.solr.core.CoreContainer");
-
- if (trustedMode) {
- // Work around VELOCITY-908 with Velocity not handling locales properly
- Object spaceGobblingInitProperty = velocityInitProps.get(RuntimeConstants.SPACE_GOBBLING);
- if (spaceGobblingInitProperty != null) {
- // If there is an init property, uppercase it before Velocity.
- velocityInitProps.put(RuntimeConstants.SPACE_GOBBLING,
- String.valueOf(spaceGobblingInitProperty).toUpperCase(Locale.ROOT));
- }
- // bring in any custom properties too
- engine.setProperties(velocityInitProps);
- }
-
- engine.init();
-
- return engine;
- }
-
- private Template getTemplate(VelocityEngine engine, SolrQueryRequest request) throws IOException {
- Template template;
-
- String templateName = request.getParams().get(TEMPLATE);
-
- String qt = request.getParams().get(CommonParams.QT);
- String path = (String) request.getContext().get("path");
- if (templateName == null && path != null) {
- templateName = path;
- } // TODO: path is never null, so qt won't get picked up maybe special case for '/select' to use qt, otherwise use path?
- if (templateName == null && qt != null) {
- templateName = qt;
- }
- if (templateName == null) templateName = "index";
- try {
- template = engine.getTemplate(templateName + TEMPLATE_EXTENSION);
- } catch (Exception e) {
- throw new IOException(e.getMessage());
- }
-
- return template;
- }
-
- private String getJSONWrap(String xmlResult) { // maybe noggit or Solr's JSON utilities can make this cleaner?
- // escape the double quotes and backslashes
- String replace1 = xmlResult.replaceAll("\\\\", "\\\\\\\\");
- replace1 = replace1.replaceAll("\\n", "\\\\n");
- replace1 = replace1.replaceAll("\\r", "\\\\r");
- String replaced = replace1.replaceAll("\"", "\\\\\"");
- // wrap it in a JSON object
- return "{\"result\":\"" + replaced + "\"}";
- }
-
- // see: https://github.com/apache/velocity-tools/blob/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
- private static class SolrVelocityResourceTool extends ResourceTool {
-
- private ClassLoader solrClassLoader;
-
- public SolrVelocityResourceTool(ClassLoader cl) {
- this.solrClassLoader = cl;
- }
-
- @Override
- protected ResourceBundle getBundle(String baseName, Object loc) {
- // resource bundles for this tool must be in velocity "package"
- return ResourceBundle.getBundle(
- "velocity." + baseName,
- (loc == null) ? this.getLocale() : this.toLocale(loc),
- solrClassLoader);
- }
- }
-}
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/package.html b/solr/contrib/velocity/src/java/org/apache/solr/response/package.html
deleted file mode 100644
index b36606c..0000000
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/package.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
--->
-<!-- not a package-info.java, because we already defined this package in core/ -->
-<html>
-<body>
-{@link org.apache.solr.response.VelocityResponseWriter} and related code.
-</body>
-</html>
diff --git a/solr/contrib/velocity/src/java/overview.html b/solr/contrib/velocity/src/java/overview.html
deleted file mode 100644
index 2168639..0000000
--- a/solr/contrib/velocity/src/java/overview.html
+++ /dev/null
@@ -1,21 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
--->
-<html>
-<body>
-Apache Solr Search Server: Velocity Response Writer contrib
-</body>
-</html>
diff --git a/solr/contrib/velocity/src/resources/VM_global_library.vm b/solr/contrib/velocity/src/resources/VM_global_library.vm
deleted file mode 100644
index fd3699b..0000000
--- a/solr/contrib/velocity/src/resources/VM_global_library.vm
+++ /dev/null
@@ -1,4 +0,0 @@
-## legacy support, the writer will load this as a macro library as it used to
-## but best not to have your own file called VM_global_library.vm; put them in macros.vm instead.
-## This file is needed for the "builtin" resource loader as Velocity requires all macro library files exist, but
-## we don't want users to have to have a macro library file in their template directories.
diff --git a/solr/contrib/velocity/src/resources/_macros.vm b/solr/contrib/velocity/src/resources/_macros.vm
deleted file mode 100644
index 406c4a9..0000000
--- a/solr/contrib/velocity/src/resources/_macros.vm
+++ /dev/null
@@ -1,70 +0,0 @@
-#macro(param $key)$request.params.get($key)#end
-
-#macro(url_root)/solr#end
-
-#macro(core_name)$request.core.name#end
-#macro(url_for_solr)#{url_root}#if($request.core.name != "")/$request.core.name#end#end
-#macro(url_for_home)#url_for_solr$request.context.path#end
-
-#macro(q)&q=$!{esc.url($request.params.get('q'))}#end
-
-#macro(fqs $p)#foreach($fq in $p)#if($velocityCount>1)&#{end}fq=$esc.url($fq)#end#end
-
-#macro(debug)#if($debug)&debug=true#end#end
-
-#macro(sort $p)#if($p)#foreach($s in $p)&sort=$esc.url($s)#end#end#end
-
-#macro(lensNoQ)?#if($request.params.getParams('fq') and $request.params.getParams('fq').size() > 0)&#fqs($request.params.getParams('fq'))#end#sort($request.params.getParams('sort'))#debug#end
-#macro(lens)#lensNoQ#q#end
-
-#macro(url_for_lens)#{url_for_home}#lens#end
-
-#macro(url_for_start $start)#url_for_home#lens&start=$start#end
-
-#macro(url_for_filters $p)#url_for_home?#q#if($p.size() > 0)&#fqs($p)#end#debug#end
-
-#macro(url_for_nested_facet_query $field)#url_for_home#lens&fq=$esc.url($field)#end
-
-#macro(url_for_facet_filter $field $value)#url_for_home#lens&fq=#if($value!=$null)$esc.url($field):%22$esc.url($value)%22#else-$esc.url($field):[*+TO+*]#end#end
-
-#macro(url_for_facet_date_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end
-
-#macro(url_for_facet_range_filter $field $value)#url_for_home#lens&fq=$esc.url($field):$esc.url($value)#end
-
-# TODO: make this parameterized fully, no context sensitivity
-#macro(field $f)
- #if($response.response.highlighting.get($docId).get($f).get(0))
- #set($pad = "")
- #foreach($v in $response.response.highlighting.get($docId).get($f))
- $pad$v## #TODO: $esc.html() or maybe make that optional?
- #set($pad = " ... ")
- #end
- #else
- $esc.html($display.list($doc.getFieldValues($f), ", "))
- #end
-#end
-
-#macro(link_to_previous_page)
- #if($page.current_page_number > 1)
- #set($prev_start = $page.start - $page.results_per_page)
- <a class="prev-page" href="#url_for_start($prev_start)">$resource.previous</a>
- #end
-#end
-
-#macro(link_to_next_page)
- #if($page.current_page_number < $page.page_count)
- #set($next_start = $page.start + $page.results_per_page)
- <a class="next-page" href="#url_for_start($next_start)">$resource.next</a>
- #end
-#end
-
-#macro(link_to_page $page_number $text)
- #if($page_number == $page.current_page_number)
- $text
- #else
- #if($page_number <= $page.page_count)
- #set($page_start = $page_number * $page.results_per_page - $page.results_per_page)
- <a class="page" href="#url_for_start($page_start)">$text</a>
- #end
- #end
-#end
diff --git a/solr/contrib/velocity/src/resources/macros.vm b/solr/contrib/velocity/src/resources/macros.vm
deleted file mode 100644
index 0018c5f..0000000
--- a/solr/contrib/velocity/src/resources/macros.vm
+++ /dev/null
@@ -1,3 +0,0 @@
-## placeholder for users to specify their own macros
-## This file is needed for the "builtin" resource loader as Velocity requires all macro library files exist.
-## This is the file we want users to override to add their own macros.
diff --git a/solr/contrib/velocity/src/resources/velocity/_default.vm b/solr/contrib/velocity/src/resources/velocity/_default.vm
deleted file mode 100644
index 71cac96..0000000
--- a/solr/contrib/velocity/src/resources/velocity/_default.vm
+++ /dev/null
@@ -1,14 +0,0 @@
-<h1>Request</h1>
-<ul>
- <li>context.path = $request.context.path</li>
- <li>params.qt = $!request.params.qt</li>
-</ul>
-
-<pre>
- $esc.html($request)
-</pre>
-
-<h1>Response</h1>
-<pre>
- $esc.html($response)
-</pre>
diff --git a/solr/contrib/velocity/src/resources/velocity/browse.vm b/solr/contrib/velocity/src/resources/velocity/browse.vm
deleted file mode 100644
index b651295..0000000
--- a/solr/contrib/velocity/src/resources/velocity/browse.vm
+++ /dev/null
@@ -1,73 +0,0 @@
-#*
- - Make search box bigger
- - Add in pivot and other facets?
- - Work on template default selection logic
-*#
-
-## Show Error Message, if any
-<div class="error">
- #parse("error.vm")
-</div>
-
-<div class="query-box">
- <form id="query-form" action="#{url_for_home}" method="GET">
- $resource.find:
- <input type="text" id="q" name="q" value="$!esc.html($request.params.get('q'))"/>
- <input type="submit"/>
-
- #if($debug) ## TODO: this would automatically happen when arbitrary parameters are kept on URLs
- <input type="hidden" name="debug" value="true"/>
- #end
- #foreach($fq in $request.params.getParams('fq'))
- <input type="hidden" name="fq" id="allFQs" value="$esc.html($fq)"/>
- #end
-
- <div class="constraints">
- #foreach($fq in $request.params.getParams('fq'))
- #set($previous_fq_count=$velocityCount - 1)
- #if($fq != '')
- >
- <a href="#url_for_filters($request.params.getParams('fq').subList(0,$previous_fq_count))">$fq</a>
- #end
- #end
- </div>
-
- <div class="parsed_query_header">
- #if($debug)
- <a href="#" onclick='jQuery(this).siblings("div").toggle(); return false;'>toggle parsed query</a>
- <div class="parsed_query" style="display:none">$response.response.debug.parsedquery</div>
- #end
- </div>
-
- </form>
-</div>
-
-<div class="facets">
- #parse("facets.vm")
-</div>
-
-<div class="pagination">
- <span>
- <span class="results-found">$page.results_found</span>
- results found in
- ${response.responseHeader.QTime}ms
- </span>
-
- $resource.page_of.insert($page.current_page_number,$page.page_count)
-</div>
-
-## Render Results, actual matching docs
-<div class="results">
- #parse("results_list.vm")
-</div>
-
-<div class="pagination">
- #link_to_previous_page
-
- <span class="results-found">$page.results_found</span>
- results found.
-
- $resource.page_of.insert($page.current_page_number,$page.page_count)
-
- #link_to_next_page
-</div>
diff --git a/solr/contrib/velocity/src/resources/velocity/error.vm b/solr/contrib/velocity/src/resources/velocity/error.vm
deleted file mode 100644
index 1c4d1dc..0000000
--- a/solr/contrib/velocity/src/resources/velocity/error.vm
+++ /dev/null
@@ -1,4 +0,0 @@
-#if( $response.response.error.code )
- <h1>ERROR $response.response.error.code</h1>
- $response.response.error.msg
-#end
diff --git a/solr/contrib/velocity/src/resources/velocity/facets.vm b/solr/contrib/velocity/src/resources/velocity/facets.vm
deleted file mode 100644
index e832704..0000000
--- a/solr/contrib/velocity/src/resources/velocity/facets.vm
+++ /dev/null
@@ -1,23 +0,0 @@
-#**
- * Display facets based on field values
- * e.g.: fields specified by &facet.field=
- *#
-
-#if($response.facetFields.size() > 0)
- <h2>Field Facets</h2>
-
- #foreach($field in $response.facetFields)
- ## Hide facets without value
- #if($field.values.size() > 0)
- <span class="facet-field">$field.name</span>
- <ul>
- #foreach($facet in $field.values)
- <li>
- <a href="#url_for_facet_filter($field.name, $facet.name)" title="$esc.html($facet.name)">
- #if($facet.name!=$null)$esc.html($display.truncate($facet.name,20))#else<em>missing</em>#end</a> ($facet.count)
- </li>
- #end
- </ul>
- #end ## end if > 0
- #end ## end for each facet field
-#end ## end if response has facet fields
diff --git a/solr/contrib/velocity/src/resources/velocity/footer.vm b/solr/contrib/velocity/src/resources/velocity/footer.vm
deleted file mode 100644
index be9c687..0000000
--- a/solr/contrib/velocity/src/resources/velocity/footer.vm
+++ /dev/null
@@ -1,19 +0,0 @@
-<hr/>
-<div>
- <span>Options:</span>
-
- #if($debug)
- <a href="#url_for_home?#q#if($request.params.getParams('fq').size() > 0)&#fqs($request.params.getParams('fq'))#end">
- disable debug</a>
- #else
- <a href="#url_for_lens&debug=true&fl=*,score">enable debug</a>
- #end
- -
- <a href="#url_for_lens&wt=xml#if($debug)&debug=true#end">XML results</a> ## TODO: Add links for other formats, maybe dynamically?
-
-</div>
-
-<div>
- <a href="http://lucene.apache.org/solr">Solr Home Page</a>
-</div>
-
diff --git a/solr/contrib/velocity/src/resources/velocity/head.vm b/solr/contrib/velocity/src/resources/velocity/head.vm
deleted file mode 100644
index dbcfb31..0000000
--- a/solr/contrib/velocity/src/resources/velocity/head.vm
+++ /dev/null
@@ -1,185 +0,0 @@
-#**
- * Provide elements for the <head> section of the HTML document
- *#
-
- <title>Solr browse: #core_name</title>
-
- <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
-
- <link rel="icon" type="image/x-icon" href="#{url_root}/img/favicon.ico"/>
- <link rel="shortcut icon" type="image/x-icon" href="#{url_root}/img/favicon.ico"/>
-
- <script type="text/javascript" src="#{url_root}/libs/jquery-3.4.1.min.js"></script>
-
- <style>
- #admin{
- text-align: right;
- vertical-align: top;
- }
-
- #head{
- width: 100%;
- }
-
- .parsed_query_header {
- font-family: Helvetica, Arial, sans-serif;
- font-size: 10pt;
- font-weight: bold;
- }
-
- .parsed_query {
- font-family: Courier, Courier New, monospaced;
- font-size: 10pt;
- font-weight: normal;
- }
-
- body {
- font-family: Helvetica, Arial, sans-serif;
- font-size: 10pt;
- }
-
- a {
- color: #305CB3;
- }
-
- em {
- color: #FF833D;
- }
-
- .facets {
- float: left;
- margin: 5px;
- margin-top: 0px;
- width: 185px;
- padding: 5px;
- top: -20px;
- position: relative;
- }
-
- .facets h2 {
- background: #D9411E;
- padding: 2px 5px;
- }
-
- .facets ul {
- list-style: none;
- margin: 0;
- margin-bottom: 5px;
- margin-top: 5px;
- padding-left: 10px;
- }
-
- .facets ul li {
- color: #999;
- padding: 2px;
- }
-
- .facet-field {
- font-weight: bold;
- }
-
- .field-name {
- font-weight: bold;
- // align="right" valign="top"
- }
-
- .highlighted-facet-field {
- background: white;
- }
-
- .constraints {
- margin-top: 10px;
- }
-
- #query-form{
- width: 80%;
- }
-
- .query-box, .constraints {
- padding: 5px;
- margin: 5px;
- font-weight: normal;
- font-size: 24px;
- letter-spacing: 0.08em;
- }
-
- .query-box #q {
- margin-left: 8px;
- width: 60%;
- height: 50px;
- border: 1px solid #999;
- font-size: 1em;
- padding: 0.4em;
- }
-
- .query-box {
-
- }
-
- .query-box .inputs{
- left: 180px;
- position: relative;
-
- }
-
- #logo {
- width: 115px;
- margin: 0px 0px 20px 12px;
- border-style: none;
- }
-
- .pagination {
- padding-left: 33%;
- background: #eee;
- margin: 5px;
- margin-left: 210px;
- padding-top: 5px;
- padding-bottom: 5px;
- }
-
- .result-document {
- border: 1px solid #999;
- padding: 5px;
- margin: 5px;
- margin-left: 210px;
- margin-bottom: 15px;
- }
-
- .result-document div{
- padding: 5px;
- }
-
- .result-title{
- width:60%;
- }
-
- .result-body{
- background: #ddd;
- }
-
- .mlt{
-
- }
-
- .result-document:nth-child(2n+1) {
- background-color: #eee;
- }
-
-
- .selected-facet-field {
- font-weight: bold;
- }
-
- li.show {
- list-style: disc;
- }
-
- .error {
- color: white;
- background-color: red;
- left: 210px;
- width:80%;
- position: relative;
-
- }
- </style>
diff --git a/solr/contrib/velocity/src/resources/velocity/hit.vm b/solr/contrib/velocity/src/resources/velocity/hit.vm
deleted file mode 100644
index ec4dfd8..0000000
--- a/solr/contrib/velocity/src/resources/velocity/hit.vm
+++ /dev/null
@@ -1,27 +0,0 @@
-#set($docId = $doc.getFirstValue($request.schema.uniqueKeyField.name))
-
-
-<div class="result-document">
-
- <table>
- #foreach( $fieldName in $doc.fieldNames )
- <tr>
- <th align="right" valign="top" style="field-name">
- $esc.html($fieldName):
- </th>
-
- <td align="left" valign="top">
- #field($fieldName)
- </td>
- </tr>
- #end
- </table>
-
- #if($debug)
- <a href="#" onclick='jQuery(this).siblings("pre").toggle(); return false;'>toggle explain</a>
-
- <pre style="display:none">
- $response.getExplainMap().get($docId)
- </pre>
- #end
-</div>
diff --git a/solr/contrib/velocity/src/resources/velocity/layout.vm b/solr/contrib/velocity/src/resources/velocity/layout.vm
deleted file mode 100644
index aa68ffc..0000000
--- a/solr/contrib/velocity/src/resources/velocity/layout.vm
+++ /dev/null
@@ -1,19 +0,0 @@
-<html>
-<head>
- #parse("head.vm")
-</head>
- <body>
- <div id="admin"><a href="#url_root/#/#core_name">Solr Admin</a></div>
- <div id="head">
- <a href="#url_for_home#if($debug)?debug=true#end"><img src="#{url_root}/img/solr.svg" id="logo"/></a>
- </div>
-
- <div id="content">
- $content
- </div>
-
- <div id="footer">
- #parse("footer.vm")
- </div>
- </body>
-</html>
diff --git a/solr/contrib/velocity/src/resources/velocity/resources.properties b/solr/contrib/velocity/src/resources/velocity/resources.properties
deleted file mode 100644
index dff221c..0000000
--- a/solr/contrib/velocity/src/resources/velocity/resources.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-find=Find
-page_of=Page <span class="page-num">{0}</span> of <span class="page-count">{1}</span>
-previous=previous
-next=next
-
-
diff --git a/solr/contrib/velocity/src/resources/velocity/results_list.vm b/solr/contrib/velocity/src/resources/velocity/results_list.vm
deleted file mode 100644
index 91ae6ea..0000000
--- a/solr/contrib/velocity/src/resources/velocity/results_list.vm
+++ /dev/null
@@ -1,3 +0,0 @@
-#foreach($doc in $response.results)
- #parse("hit.vm")
-#end
diff --git a/solr/contrib/velocity/src/test-files/velocity/file.vm b/solr/contrib/velocity/src/test-files/velocity/file.vm
deleted file mode 100644
index 9a2c773..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/file.vm
+++ /dev/null
@@ -1 +0,0 @@
-testing
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/schema.xml b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/schema.xml
deleted file mode 100644
index 5b12cda..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/schema.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
--->
-
-<schema name="minimal-velocity" version="1.6">
- <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
-
- <field name="id" type="string" indexed="true" stored="true" required="true"/>
- <dynamicField name="*_s" type="string" indexed="true" stored="true"/>
-
- <uniqueKey>id</uniqueKey>
-</schema>
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/solrconfig.xml b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/solrconfig.xml
deleted file mode 100644
index 35ce52b..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/solrconfig.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
--->
-
-<config>
- <luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion>
-
- <!--<lib dir="../../contrib/velocity/lib" />-->
- <!--<lib dir="../../dist/" regex="solr-velocity-\d.*\.jar" />-->
-
- <schemaFactory class="ClassicIndexSchemaFactory"/>
-
- <requestHandler name="search" class="solr.SearchHandler" default="true">
- <lst name="defaults">
- <str name="echoParams">explicit</str>
- <int name="rows">10</int>
- </lst>
- </requestHandler>
-
- <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter"/>
-
- <queryResponseWriter name="velocityWithInitProps" class="solr.VelocityResponseWriter">
- <str name="init.properties.file">velocity-init.properties</str>
- </queryResponseWriter>
-
- <queryResponseWriter name="velocityWithCustomTools" class="solr.VelocityResponseWriter">
- <lst name="tools">
- <!-- how someone would typically add a custom tool, with a custom, non-clashing name -->
- <str name="mytool">org.apache.solr.velocity.MockTool</str>
-
- <!-- override the $log context object -->
- <str name="log">org.apache.solr.velocity.MockTool</str>
-
- <!-- Try to override response, but ignored -->
- <str name="response">org.apache.solr.velocity.MockTool</str>
- </lst>
- </queryResponseWriter>
-</config>
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity-init.properties b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity-init.properties
deleted file mode 100644
index 853e5fc..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity-init.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-#
-
-foreach.provide.scope.control=false
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/VM_global_library.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/VM_global_library.vm
deleted file mode 100644
index 7bd767e..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/VM_global_library.vm
+++ /dev/null
@@ -1,3 +0,0 @@
-#macro(legacy_macro)legacy_macro_SUCCESS#end
-
-#macro(url_root)Loaded from: VM_global_library.vm#end
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/encoding.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/encoding.vm
deleted file mode 100644
index 419f3f2..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/encoding.vm
+++ /dev/null
@@ -1 +0,0 @@
-éñçø∂îñg
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/layout.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/layout.vm
deleted file mode 100644
index 39136e1..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/layout.vm
+++ /dev/null
@@ -1 +0,0 @@
-{{{$content}}}
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale.vm
deleted file mode 100644
index a85fd05..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale.vm
+++ /dev/null
@@ -1 +0,0 @@
-$resource.color
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale_number.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale_number.vm
deleted file mode 100644
index 9994022..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/locale_number.vm
+++ /dev/null
@@ -1 +0,0 @@
-$number.format(2112)
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/macros.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/macros.vm
deleted file mode 100644
index 46a508f..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/macros.vm
+++ /dev/null
@@ -1,3 +0,0 @@
-#macro(test_macro)test_macro_SUCCESS#end
-
-#macro(url_root)Loaded from: macros.vm#end
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/numFound.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/numFound.vm
deleted file mode 100644
index 7bafdcd..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/numFound.vm
+++ /dev/null
@@ -1 +0,0 @@
-$response.response.response.numFound
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/outside_the_box.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/outside_the_box.vm
deleted file mode 100644
index c52c94b..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/outside_the_box.vm
+++ /dev/null
@@ -1,4 +0,0 @@
-#set($x='')
-#set($sys=$x.class.forName('java.lang.System'))
-#set($ex=$sys.getProperty('os.name'))
-$ex
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/resource_get.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/resource_get.vm
deleted file mode 100644
index 8a4890f..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/resource_get.vm
+++ /dev/null
@@ -1 +0,0 @@
-$resource.get("color","resources","en_UK")
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/sandbox_intersection.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/sandbox_intersection.vm
deleted file mode 100644
index 80c7422..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/sandbox_intersection.vm
+++ /dev/null
@@ -1,5 +0,0 @@
-#set($x='')
-#set($sys=$x.class.forName('java.nio.file.Paths'))
-#set($path=$sys.get('/dumbass/denied_location'))
-#set($ex=$path.resolve($path).toRealPath())
-$ex
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_legacy_support.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_legacy_support.vm
deleted file mode 100644
index 30f32fe..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_legacy_support.vm
+++ /dev/null
@@ -1 +0,0 @@
-#legacy_macro
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_overridden.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_overridden.vm
deleted file mode 100644
index f06b28f..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_overridden.vm
+++ /dev/null
@@ -1 +0,0 @@
-#url_root
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_visible.vm b/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_visible.vm
deleted file mode 100644
index 7a5baed..0000000
--- a/solr/contrib/velocity/src/test-files/velocity/solr/collection1/conf/velocity/test_macro_visible.vm
+++ /dev/null
@@ -1 +0,0 @@
-#test_macro
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test/custom_tool.vm b/solr/contrib/velocity/src/test/custom_tool.vm
deleted file mode 100644
index 3efff7d..0000000
--- a/solr/contrib/velocity/src/test/custom_tool.vm
+++ /dev/null
@@ -1,19 +0,0 @@
-#* Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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. *#
-
-mytool.star=$!mytool.star("LATERALUS")
-mytool.locale=$!mytool.locale
-log.star=$!log.star("log overridden")
-response.star=$!response.star("response overridden??")
diff --git a/solr/contrib/velocity/src/test/foreach.vm b/solr/contrib/velocity/src/test/foreach.vm
deleted file mode 100644
index 5d7d1e9..0000000
--- a/solr/contrib/velocity/src/test/foreach.vm
+++ /dev/null
@@ -1,14 +0,0 @@
-#* Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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. *##foreach($x in ["a","b"])$!foreach.index#end
diff --git a/solr/contrib/velocity/src/test/org/apache/solr/velocity/MockTool.java b/solr/contrib/velocity/src/test/org/apache/solr/velocity/MockTool.java
deleted file mode 100644
index c6287fd..0000000
--- a/solr/contrib/velocity/src/test/org/apache/solr/velocity/MockTool.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.solr.velocity;
-
-import org.apache.solr.core.SolrCore;
-import org.apache.velocity.tools.generic.LocaleConfig;
-
-public class MockTool extends LocaleConfig {
- private final SolrCore core;
-
- public MockTool(SolrCore core) {
- this.core = core;
- }
-
- public String star(String str) {
- return "** " + str + " **";
- }
-
- public SolrCore getCore() { return core; }
-}
diff --git a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java
deleted file mode 100644
index 1aa3dfa..0000000
--- a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.solr.velocity;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.security.AccessControlException;
-import java.util.Properties;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.QueryResponseWriter;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.response.VelocityResponseWriter;
-import org.apache.velocity.exception.MethodInvocationException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class VelocityResponseWriterTest extends SolrTestCaseJ4 {
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solrconfig.xml", "schema.xml", getFile("velocity/solr").getAbsolutePath());
- }
-
- @AfterClass
- public static void afterClass() throws Exception {
- }
-
- @Override
- public void setUp() throws Exception {
- // This test case toggles the configset used from trusted to untrusted - return to default of trusted for each test
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(true);
- super.setUp();
- }
-
- @Test
- public void testVelocityResponseWriterRegistered() {
- QueryResponseWriter writer = h.getCore().getQueryResponseWriter("velocity");
- assertTrue("VrW registered check", writer instanceof VelocityResponseWriter);
- }
-
- @Test
- public void testSecureUberspector() throws Exception {
- VelocityResponseWriter vrw = new VelocityResponseWriter();
- NamedList<String> nl = new NamedList<>();
- nl.add("template.base.dir", getFile("velocity").getAbsolutePath());
- vrw.init(nl);
- SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE,"outside_the_box");
- SolrQueryResponse rsp = new SolrQueryResponse();
- StringWriter buf = new StringWriter();
- vrw.write(buf, req, rsp);
- assertEquals("$ex",buf.toString()); // $ex rendered literally because it is null, and thus did not succeed to break outside the box
- }
-
- @Test
- @Ignore("SOLR-14025: Velocity's SecureUberspector addresses this")
- public void testTemplateSandbox() throws Exception {
- assumeTrue("This test only works with security manager", System.getSecurityManager() != null);
- VelocityResponseWriter vrw = new VelocityResponseWriter();
- NamedList<String> nl = new NamedList<>();
- nl.add("template.base.dir", getFile("velocity").getAbsolutePath());
- vrw.init(nl);
- SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE,"outside_the_box");
- SolrQueryResponse rsp = new SolrQueryResponse();
- StringWriter buf = new StringWriter();
- try {
- vrw.write(buf, req, rsp);
- fail("template broke outside the box, retrieved: " + buf);
- } catch (MethodInvocationException e) {
- assertNotNull(e.getCause());
- assertEquals(AccessControlException.class, e.getCause().getClass());
- // expected failure, can't get outside the box
- }
- }
-
- @Test
- @Ignore("SOLR-14025: Velocity's SecureUberspector addresses this")
- public void testSandboxIntersection() throws Exception {
- assumeTrue("This test only works with security manager", System.getSecurityManager() != null);
- VelocityResponseWriter vrw = new VelocityResponseWriter();
- NamedList<String> nl = new NamedList<>();
- nl.add("template.base.dir", getFile("velocity").getAbsolutePath());
- vrw.init(nl);
- SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE,"sandbox_intersection");
- SolrQueryResponse rsp = new SolrQueryResponse();
- StringWriter buf = new StringWriter();
- try {
- vrw.write(buf, req, rsp);
- fail("template broke outside the box, retrieved: " + buf);
- } catch (MethodInvocationException e) {
- assertNotNull(e.getCause());
- assertEquals(AccessControlException.class, e.getCause().getClass());
- // expected failure, can't get outside the box
- }
- }
-
- @Test
- public void testFileResourceLoader() throws Exception {
- VelocityResponseWriter vrw = new VelocityResponseWriter();
- NamedList<String> nl = new NamedList<>();
- nl.add("template.base.dir", getFile("velocity").getAbsolutePath());
- vrw.init(nl);
- SolrQueryRequest req = req(VelocityResponseWriter.TEMPLATE,"file");
- SolrQueryResponse rsp = new SolrQueryResponse();
- StringWriter buf = new StringWriter();
- vrw.write(buf, req, rsp);
- assertEquals("testing", buf.toString());
- }
-
- @Test
- public void testTemplateTrust() throws Exception {
- // Try on trusted configset....
- assertEquals("0", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"numFound")));
-
- // Turn off trusted configset, which disables the Solr resource loader
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(false);
- assertFalse(h.getCoreContainer().getCoreDescriptor(coreName).isConfigSetTrusted());
-
- try {
- assertEquals("0", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"numFound")));
- fail("template rendering should have failed, from an untrusted configset");
- } catch (IOException e) {
- // expected exception
- assertEquals(IOException.class, e.getClass());
- }
-
- // set the harness back to the default of trusted
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(true);
- }
-
-
- @Test
- public void testSolrResourceLoaderTemplate() throws Exception {
- assertEquals("0", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"numFound")));
- }
-
- @Test
- public void testEncoding() throws Exception {
- assertEquals("éñçø∂îñg", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"encoding")));
- }
-
- @Test
- public void testMacros() throws Exception {
- // tests that a macro in a custom macros.vm is visible
- assertEquals("test_macro_SUCCESS", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"test_macro_visible")));
-
- // tests that a builtin (_macros.vm) macro, #url_root in this case, can be overridden in a custom macros.vm
- // the macro is also defined in VM_global_library.vm, which should also be overridden by macros.vm
- assertEquals("Loaded from: macros.vm", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"test_macro_overridden")));
-
- // tests that macros defined in VM_global_library.vm are visible. This file was where macros in pre-5.0 versions were defined
- assertEquals("legacy_macro_SUCCESS", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"test_macro_legacy_support")));
- }
-
- @Test
- public void testInitProps() throws Exception {
- // The test init properties file turns off being able to use $foreach.index (the implicit loop counter)
- // The foreach.vm template uses $!foreach.index, with ! suppressing the literal "$foreach.index" output
-
- assertEquals("01", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"foreach")));
- assertEquals("", h.query(req("q","*:*", "wt","velocityWithInitProps",VelocityResponseWriter.TEMPLATE,"foreach")));
-
- // Turn off trusted configset, which disables the init properties
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(false);
- assertFalse(h.getCoreContainer().getCoreDescriptor(coreName).isConfigSetTrusted());
-
- assertEquals("01", h.query(req("q","*:*", "wt","velocityWithInitProps",VelocityResponseWriter.TEMPLATE,"foreach")));
-
- // set the harness back to the default of trusted
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(true);
- }
-
- @Test
- public void testCustomTools() throws Exception {
- // Render this template once without a custom tool defined, and once with it defined. The tool has a `.star` method.
- // The tool added as `mytool`, `log`, and `response`. `log` is designed to be overridable, but not `response`
- // mytool.star=$!mytool.star("LATERALUS")
- // mytool.locale=$!mytool.locale
- // log.star=$!log.star("log overridden")
- // response.star=$!response.star("response overridden??")
-
- // First without the tool defined, with `$!` turning null object/method references into empty string
- Properties rendered_props = new Properties();
- String rsp = h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"custom_tool"));
- rendered_props.load(new StringReader(rsp));
- // ignore mytool.locale here, as it will be the random test one
- assertEquals("",rendered_props.getProperty("mytool.star"));
- assertEquals("",rendered_props.getProperty("log.star"));
- assertEquals("",rendered_props.getProperty("response.star"));
-
- // Now with custom tools defined:
- rsp = h.query(req("q","*:*", "wt","velocityWithCustomTools",VelocityResponseWriter.TEMPLATE,"custom_tool",VelocityResponseWriter.LOCALE, "de_DE"));
- rendered_props.clear();
- rendered_props.load(new StringReader(rsp));
- assertEquals("** LATERALUS **",rendered_props.getProperty("mytool.star"));
- assertEquals("** log overridden **",rendered_props.getProperty("log.star"));
- assertEquals("",rendered_props.getProperty("response.star"));
- assertEquals("de_DE",rendered_props.getProperty("mytool.locale"));
-
-
- // Turn off trusted configset, which disables the custom tool injection
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(false);
- assertFalse(h.getCoreContainer().getCoreDescriptor(coreName).isConfigSetTrusted());
-
- rsp = h.query(req("q","*:*", "wt","velocityWithCustomTools",VelocityResponseWriter.TEMPLATE,"custom_tool",VelocityResponseWriter.LOCALE, "de_DE"));
- rendered_props.clear();
- rendered_props.load(new StringReader(rsp));
- assertEquals("",rendered_props.getProperty("mytool.star"));
- assertEquals("",rendered_props.getProperty("log.star"));
- assertEquals("",rendered_props.getProperty("response.star"));
- assertEquals("",rendered_props.getProperty("mytool.locale"));
-
- // set the harness back to the default of trusted
- h.getCoreContainer().getCoreDescriptor(h.coreName).setConfigSetTrusted(true);
-
-
- // Custom tools can also have a SolrCore-arg constructor because they are instantiated with SolrCore.createInstance
- // TODO: do we really need to support this? no great loss, as a custom tool could take a SolrCore object as a parameter to
- // TODO: any method, so one could do $mytool.my_method($request.core)
- // I'm currently inclined to make this feature undocumented/unsupported, as we may want to instantiate classes
- // in a different manner that only supports no-arg constructors, commented (passing) test case out
- // assertEquals("collection1", h.query(req("q","*:*", "wt","velocityWithCustomTools",VelocityResponseWriter.TEMPLATE,"t",
- // SolrParamResourceLoader.TEMPLATE_PARAM_PREFIX+"t", "$mytool.core.name")))
- // - NOTE: example uses removed inline param; convert to external template as needed
- }
-
- @Test
- public void testLocaleFeature() throws Exception {
- assertEquals("Color", h.query(req("q", "*:*", "wt", "velocity", VelocityResponseWriter.TEMPLATE, "locale",
- VelocityResponseWriter.LOCALE,"en_US")));
- assertEquals("Colour", h.query(req("q", "*:*", "wt", "velocity", VelocityResponseWriter.TEMPLATE, "locale",
- VelocityResponseWriter.LOCALE,"en_UK")));
-
- // Test that $resource.get(key,baseName,locale) works with specified locale
- assertEquals("Colour", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"resource_get")));
-
- // Test that $number tool uses the specified locale
- assertEquals("2,112", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"locale_number",
- VelocityResponseWriter.LOCALE, "en_US")));
- assertEquals("2.112", h.query(req("q","*:*", "wt","velocity",VelocityResponseWriter.TEMPLATE,"locale_number",
- VelocityResponseWriter.LOCALE, "de_DE")));
- }
-
- @Test
- public void testLayoutFeature() throws Exception {
- assertEquals("{{{0}}}", h.query(req("q","*:*", "wt","velocity",
- VelocityResponseWriter.TEMPLATE,"numFound", VelocityResponseWriter.LAYOUT,"layout")));
-
- // even with v.layout specified, layout can be disabled explicitly
- assertEquals("0", h.query(req("q","*:*", "wt","velocity",
- VelocityResponseWriter.TEMPLATE,"numFound",
- VelocityResponseWriter.LAYOUT,"layout",
- VelocityResponseWriter.LAYOUT_ENABLED,"false")));
- }
-
- @Test
- public void testJSONWrapper() throws Exception {
- assertEquals("foo({\"result\":\"0\"})", h.query(req("q", "*:*", "wt", "velocity",
- VelocityResponseWriter.TEMPLATE, "numFound",
- VelocityResponseWriter.JSON,"foo")));
-
- // Now with layout, for good measure
- assertEquals("foo({\"result\":\"{{{0}}}\"})", h.query(req("q", "*:*", "wt", "velocity",
- VelocityResponseWriter.TEMPLATE, "numFound",
- VelocityResponseWriter.JSON,"foo",
- VelocityResponseWriter.LAYOUT,"layout")));
-
- assertQEx("Bad function name should throw exception", req("q", "*:*", "wt", "velocity",
- VelocityResponseWriter.TEMPLATE, "numFound",
- VelocityResponseWriter.JSON,"<foo>"), SolrException.ErrorCode.BAD_REQUEST
- );
- }
-
- @Test
- public void testContentType() {
- VelocityResponseWriter vrw = new VelocityResponseWriter();
- NamedList<String> nl = new NamedList<>();
- vrw.init(nl);
- SolrQueryResponse rsp = new SolrQueryResponse();
-
- // with v.json=wrf, content type should default to application/json
- assertEquals("application/json;charset=UTF-8",
- vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound",
- VelocityResponseWriter.JSON, "wrf"), rsp));
-
- // with no v.json specified, the default text/html should be returned
- assertEquals("text/html;charset=UTF-8",
- vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound"), rsp));
-
- // if v.contentType is specified, that should be used, even if v.json is specified
- assertEquals("text/plain",
- vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound",
- VelocityResponseWriter.CONTENT_TYPE,"text/plain"), rsp));
- assertEquals("text/plain",
- vrw.getContentType(req(VelocityResponseWriter.TEMPLATE, "numFound",
- VelocityResponseWriter.JSON,"wrf",
- VelocityResponseWriter.CONTENT_TYPE,"text/plain"), rsp));
- }
-}
diff --git a/solr/contrib/velocity/src/test/velocity/resources.properties b/solr/contrib/velocity/src/test/velocity/resources.properties
deleted file mode 100644
index ec6320f..0000000
--- a/solr/contrib/velocity/src/test/velocity/resources.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-#
-
-color=Color
\ No newline at end of file
diff --git a/solr/contrib/velocity/src/test/velocity/resources_en_UK.properties b/solr/contrib/velocity/src/test/velocity/resources_en_UK.properties
deleted file mode 100644
index 21a476f..0000000
--- a/solr/contrib/velocity/src/test/velocity/resources_en_UK.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You 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.
-#
-
-color=Colour
\ No newline at end of file