You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ko...@apache.org on 2009/04/13 03:45:37 UTC

svn commit: r764347 - in /lucene/solr/trunk/contrib/velocity/src/main: java/org/apache/solr/request/VelocityResponseWriter.java solr/conf/solrconfig.xml solr/conf/velocity.properties

Author: koji
Date: Mon Apr 13 01:45:36 2009
New Revision: 764347

URL: http://svn.apache.org/viewvc?rev=764347&view=rev
Log:
SOLR-620: added a feature of applying velocity.properties by v.properties parameter

Added:
    lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity.properties   (with props)
Modified:
    lucene/solr/trunk/contrib/velocity/src/main/java/org/apache/solr/request/VelocityResponseWriter.java
    lucene/solr/trunk/contrib/velocity/src/main/solr/conf/solrconfig.xml

Modified: 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/request/VelocityResponseWriter.java?rev=764347&r1=764346&r2=764347&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/request/VelocityResponseWriter.java Mon Apr 13 01:45:36 2009
@@ -26,13 +26,20 @@
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.tools.generic.*;
 import org.apache.velocity.app.VelocityEngine;
+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.util.Properties;
 
 public class VelocityResponseWriter implements QueryResponseWriter {
+  
+  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
 
@@ -116,9 +123,25 @@
     }
     engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, baseDir.getAbsolutePath());
     engine.setProperty("params.resource.loader.instance", new SolrParamResourceLoader(request));
-    engine.setProperty("solr.resource.loader.instance",
-        new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader()));
+    SolrVelocityResourceLoader resourceLoader =
+      new SolrVelocityResourceLoader(request.getCore().getSolrConfig().getResourceLoader());
+    engine.setProperty("solr.resource.loader.instance", resourceLoader);
     engine.setProperty(VelocityEngine.RESOURCE_LOADER, "params,file,solr");
+    String propFile = request.getParams().get("v.properties");
+    try{
+      if( propFile == null )
+        engine.init();
+      else{
+        InputStream is = resourceLoader.getResourceStream( propFile );
+        Properties props = new Properties();
+        props.load( is );
+        is.close();
+        engine.init( props );
+      }
+    }
+    catch( Exception e ){
+      throw new RuntimeException( e );
+    }
 
     return engine;
   }
@@ -158,8 +181,7 @@
     // wrap it in a JSON object
     return "{\"result\":\"" + replaced + "\"}";
   }
-
+  
   public void init(NamedList args) {
-    
   }
 }

Modified: lucene/solr/trunk/contrib/velocity/src/main/solr/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/solr/conf/solrconfig.xml?rev=764347&r1=764346&r2=764347&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/contrib/velocity/src/main/solr/conf/solrconfig.xml Mon Apr 13 01:45:36 2009
@@ -401,6 +401,7 @@
   <requestHandler name="/itas" class="solr.SearchHandler">
      <lst name="defaults">
        <str name="v.template">browse</str>
+       <str name="v.properties">velocity.properties</str>
        <str name="title">Solritas</str>
 
        <str name="wt">velocity</str>

Added: lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity.properties
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity.properties?rev=764347&view=auto
==============================================================================
--- lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity.properties (added)
+++ lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity.properties Mon Apr 13 01:45:36 2009
@@ -0,0 +1,3 @@
+# if the encoding of your velocity template is other than ISO-8859-1, 
+# set the input.encoding property.
+#input.encoding		= UTF-8

Propchange: lucene/solr/trunk/contrib/velocity/src/main/solr/conf/velocity.properties
------------------------------------------------------------------------------
    svn:eol-style = native