lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r924412 - in /lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr: request/ response/
Date Wed, 17 Mar 2010 18:34:51 GMT
Author: ehatcher
Date: Wed Mar 17 18:34:50 2010
New Revision: 924412

URL: http://svn.apache.org/viewvc?rev=924412&view=rev
Log:
move VwR classes to response package

Added:
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/PageTool.java
      - copied, changed from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/PageTool.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrParamResourceLoader.java
      - copied, changed from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrVelocityResourceLoader.java
      - copied, changed from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/VelocityResponseWriter.java
      - copied, changed from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
Removed:
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/PageTool.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java

Copied: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/PageTool.java
(from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/PageTool.java)
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/PageTool.java?p2=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/PageTool.java&p1=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/PageTool.java&r1=921552&r2=924412&rev=924412&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/PageTool.java
(original)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/PageTool.java
Wed Mar 17 18:34:50 2010
@@ -15,8 +15,9 @@
  * 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.search.DocSlice;
 import org.apache.solr.common.SolrDocumentList;

Copied: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrParamResourceLoader.java
(from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java)
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrParamResourceLoader.java?p2=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrParamResourceLoader.java&p1=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java&r1=921552&r2=924412&rev=924412&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrParamResourceLoader.java
(original)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrParamResourceLoader.java
Wed Mar 17 18:34:50 2010
@@ -15,8 +15,9 @@
  * 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.Resource;
 import org.apache.velocity.exception.ResourceNotFoundException;

Copied: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrVelocityResourceLoader.java
(from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java)
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrVelocityResourceLoader.java?p2=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrVelocityResourceLoader.java&p1=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java&r1=921552&r2=924412&rev=924412&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/SolrVelocityResourceLoader.java
(original)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/SolrVelocityResourceLoader.java
Wed Mar 17 18:34:50 2010
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * 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.Resource;

Copied: lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/VelocityResponseWriter.java
(from r921552, lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java)
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/VelocityResponseWriter.java?p2=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/VelocityResponseWriter.java&p1=lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java&r1=921552&r2=924412&rev=924412&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
(original)
+++ lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/response/VelocityResponseWriter.java
Wed Mar 17 18:34:50 2010
@@ -15,37 +15,32 @@
  * 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.embedded.EmbeddedSolrServer;
 import org.apache.solr.client.solrj.response.QueryResponse;
 import org.apache.solr.client.solrj.response.SolrResponseBase;
-import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
-import org.apache.solr.response.QueryResponseWriter;
-import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.request.SolrQueryRequest;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
-import org.apache.velocity.tools.generic.*;
 import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.tools.generic.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
+import java.io.*;
 import java.util.Properties;
 
 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);
 
   public void write(Writer writer, SolrQueryRequest request, SolrQueryResponse response)
throws IOException {
     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);
 
     VelocityContext context = new VelocityContext();
@@ -67,10 +62,11 @@ public class VelocityResponseWriter impl
       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... *sigh*
+      context.put("page", new PageTool(request, response));  // page tool only makes sense
for a SearchHandler request... *sigh*
     } catch (ClassCastException e) {
       // known edge case where QueryResponse's extraction assumes "response" is a SolrDocumentList
       // (AnalysisRequestHandler emits a "response")
+      e.printStackTrace();
       rsp = new SolrResponseBase();
       rsp.setResponse(parsedResponse);
     }
@@ -78,22 +74,23 @@ public class VelocityResponseWriter impl
 
     // Velocity context tools - TODO: make these pluggable
     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("list", new ListTool());
     context.put("math", new MathTool());
+    context.put("number", new NumberTool());
+    context.put("sort", new SortTool());
+
     context.put("engine", engine);  // for $engine.resourceExists(...)
 
     String layout_template = request.getParams().get("v.layout");
     String json_wrapper = request.getParams().get("v.json");
-    boolean wrap_response = (layout_template != null) || (json_wrapper !=null);
-    
+    boolean wrap_response = (layout_template != null) || (json_wrapper != null);
+
     // create output, optionally wrap it into a json object
     if (wrap_response) {
       StringWriter stringWriter = new StringWriter();
       template.merge(context, stringWriter);
-      
+
       if (layout_template != null) {
         context.put("content", stringWriter.toString());
         stringWriter = new StringWriter();
@@ -103,7 +100,7 @@ public class VelocityResponseWriter impl
           throw new IOException(e.getMessage());
         }
       }
-      
+
       if (json_wrapper != null) {
         writer.write(request.getParams().get("v.json") + "(");
         writer.write(getJSONWrap(stringWriter.toString()));
@@ -126,28 +123,30 @@ public class VelocityResponseWriter impl
     engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, baseDir.getAbsolutePath());
     engine.setProperty("params.resource.loader.instance", new SolrParamResourceLoader(request));
     SolrVelocityResourceLoader resourceLoader =
-      new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader());
+        new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader());
     engine.setProperty("solr.resource.loader.instance", resourceLoader);
+
+    // TODO: Externalize Velocity properties
     engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file,solr");
     String propFile = request.getParams().get("v.properties");
-    try{
-      if( propFile == null )
+    try {
+      if (propFile == null)
         engine.init();
-      else{
+      else {
         InputStream is = null;
-        try{
-          is = resourceLoader.getResourceStream( propFile );
+        try {
+          is = resourceLoader.getResourceStream(propFile);
           Properties props = new Properties();
-          props.load( is );
-          engine.init( props );
+          props.load(is);
+          engine.init(props);
         }
-        finally{
-          if( is != null ) is.close();
+        finally {
+          if (is != null) is.close();
         }
       }
     }
-    catch( Exception e ){
-      throw new RuntimeException( e );
+    catch (Exception e) {
+      throw new RuntimeException(e);
     }
 
     return engine;
@@ -176,9 +175,9 @@ public class VelocityResponseWriter impl
   }
 
   public String getContentType(SolrQueryRequest request, SolrQueryResponse response) {
-    return request.getParams().get("v.contentType","text/html");
+    return request.getParams().get("v.contentType", "text/html");
   }
-  
+
   private String getJSONWrap(String xmlResult) {  // TODO: maybe noggit or Solr's JSON utilities
can make this cleaner?
     // escape the double quotes and backslashes
     String replace1 = xmlResult.replaceAll("\\\\", "\\\\\\\\");
@@ -188,7 +187,7 @@ public class VelocityResponseWriter impl
     // wrap it in a JSON object
     return "{\"result\":\"" + replaced + "\"}";
   }
-  
+
   public void init(NamedList args) {
   }
 }



Mime
View raw message