mirror of https://github.com/apache/lucene.git
move VwR classes to response package
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@924412 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a45422f66a
commit
a5dc94a6c0
|
@ -15,8 +15,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.solr.request;
|
package org.apache.solr.response;
|
||||||
|
|
||||||
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
import org.apache.solr.response.SolrQueryResponse;
|
||||||
import org.apache.solr.search.DocSlice;
|
import org.apache.solr.search.DocSlice;
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
|
@ -15,8 +15,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.solr.request;
|
package org.apache.solr.response;
|
||||||
|
|
||||||
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
||||||
import org.apache.velocity.runtime.resource.Resource;
|
import org.apache.velocity.runtime.resource.Resource;
|
||||||
import org.apache.velocity.exception.ResourceNotFoundException;
|
import org.apache.velocity.exception.ResourceNotFoundException;
|
|
@ -14,7 +14,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.request;
|
package org.apache.solr.response;
|
||||||
|
|
||||||
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
import org.apache.velocity.runtime.resource.loader.ResourceLoader;
|
||||||
import org.apache.velocity.runtime.resource.Resource;
|
import org.apache.velocity.runtime.resource.Resource;
|
|
@ -15,37 +15,32 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.solr.request;
|
package org.apache.solr.response;
|
||||||
|
|
||||||
import org.apache.solr.common.util.NamedList;
|
|
||||||
import org.apache.solr.client.solrj.SolrResponse;
|
import org.apache.solr.client.solrj.SolrResponse;
|
||||||
|
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.client.solrj.response.SolrResponseBase;
|
import org.apache.solr.client.solrj.response.SolrResponseBase;
|
||||||
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.response.QueryResponseWriter;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.response.SolrQueryResponse;
|
|
||||||
import org.apache.velocity.Template;
|
import org.apache.velocity.Template;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
import org.apache.velocity.tools.generic.*;
|
|
||||||
import org.apache.velocity.app.VelocityEngine;
|
import org.apache.velocity.app.VelocityEngine;
|
||||||
|
import org.apache.velocity.tools.generic.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class VelocityResponseWriter implements QueryResponseWriter {
|
public class VelocityResponseWriter implements QueryResponseWriter {
|
||||||
|
|
||||||
|
// TODO: maybe pass this Logger to the template for logging from there?
|
||||||
private static final Logger log = LoggerFactory.getLogger(VelocityResponseWriter.class);
|
private static final Logger log = LoggerFactory.getLogger(VelocityResponseWriter.class);
|
||||||
|
|
||||||
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
|
public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response) throws IOException {
|
||||||
VelocityEngine engine = getEngine(request); // TODO: have HTTP headers available for configuring engine
|
VelocityEngine engine = getEngine(request); // TODO: have HTTP headers available for configuring engine
|
||||||
|
|
||||||
// TODO: Add layout capability, render to string buffer, then render layout
|
|
||||||
Template template = getTemplate(engine, request);
|
Template template = getTemplate(engine, request);
|
||||||
|
|
||||||
VelocityContext context = new VelocityContext();
|
VelocityContext context = new VelocityContext();
|
||||||
|
@ -71,6 +66,7 @@ public class VelocityResponseWriter implements QueryResponseWriter {
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
// known edge case where QueryResponse's extraction assumes "response" is a SolrDocumentList
|
// known edge case where QueryResponse's extraction assumes "response" is a SolrDocumentList
|
||||||
// (AnalysisRequestHandler emits a "response")
|
// (AnalysisRequestHandler emits a "response")
|
||||||
|
e.printStackTrace();
|
||||||
rsp = new SolrResponseBase();
|
rsp = new SolrResponseBase();
|
||||||
rsp.setResponse(parsedResponse);
|
rsp.setResponse(parsedResponse);
|
||||||
}
|
}
|
||||||
|
@ -78,11 +74,12 @@ public class VelocityResponseWriter implements QueryResponseWriter {
|
||||||
|
|
||||||
// Velocity context tools - TODO: make these pluggable
|
// Velocity context tools - TODO: make these pluggable
|
||||||
context.put("esc", new EscapeTool());
|
context.put("esc", new EscapeTool());
|
||||||
context.put("sort", new SortTool());
|
|
||||||
context.put("number", new NumberTool());
|
|
||||||
context.put("list", new ListTool());
|
|
||||||
context.put("date", new ComparisonDateTool());
|
context.put("date", new ComparisonDateTool());
|
||||||
|
context.put("list", new ListTool());
|
||||||
context.put("math", new MathTool());
|
context.put("math", new MathTool());
|
||||||
|
context.put("number", new NumberTool());
|
||||||
|
context.put("sort", new SortTool());
|
||||||
|
|
||||||
context.put("engine", engine); // for $engine.resourceExists(...)
|
context.put("engine", engine); // for $engine.resourceExists(...)
|
||||||
|
|
||||||
String layout_template = request.getParams().get("v.layout");
|
String layout_template = request.getParams().get("v.layout");
|
||||||
|
@ -128,6 +125,8 @@ public class VelocityResponseWriter implements QueryResponseWriter {
|
||||||
SolrVelocityResourceLoader resourceLoader =
|
SolrVelocityResourceLoader resourceLoader =
|
||||||
new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader());
|
new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader());
|
||||||
engine.setProperty("solr.resource.loader.instance", resourceLoader);
|
engine.setProperty("solr.resource.loader.instance", resourceLoader);
|
||||||
|
|
||||||
|
// TODO: Externalize Velocity properties
|
||||||
engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file,solr");
|
engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file,solr");
|
||||||
String propFile = request.getParams().get("v.properties");
|
String propFile = request.getParams().get("v.properties");
|
||||||
try {
|
try {
|
Loading…
Reference in New Issue