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 yo...@apache.org on 2006/10/18 22:58:28 UTC

svn commit: r465369 - in /incubator/solr/trunk: CHANGES.txt src/java/org/apache/solr/request/JSONResponseWriter.java

Author: yonik
Date: Wed Oct 18 13:58:27 2006
New Revision: 465369

URL: http://svn.apache.org/viewvc?view=rev&rev=465369
Log:
added json.wrf, wrapper function: SOLR-56

Modified:
    incubator/solr/trunk/CHANGES.txt
    incubator/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java

Modified: incubator/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/CHANGES.txt?view=diff&rev=465369&r1=465368&r2=465369
==============================================================================
--- incubator/solr/trunk/CHANGES.txt (original)
+++ incubator/solr/trunk/CHANGES.txt Wed Oct 18 13:58:27 2006
@@ -59,6 +59,9 @@
     In the process, an init(NamedList) method was added to QueryResponseWriter
     which works the same way as SolrRequestHandler.
     (Bertrand Delacretaz / SOLR-49 / hossman)
+28. json.wrf parameter adds a wrapper-function around the JSON response,
+    useful in AJAX with dynamic script tags for specifying a JavaScript
+    callback function. (Bertrand Delacretaz via yonik, SOLR-56)
     
 Changes in runtime behavior
  1. classes reorganized into different packages, package names changed to Apache

Modified: incubator/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java?view=diff&rev=465369&r1=465368&r2=465369
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java Wed Oct 18 13:58:27 2006
@@ -41,17 +41,20 @@
   private Calendar cal;
 
   private String namedListStyle;
+  private String wrapperFunction;
 
   private static final String JSON_NL_STYLE="json.nl";
   private static final String JSON_NL_MAP="map";
   private static final String JSON_NL_ARROFARR="arrarr";
   private static final String JSON_NL_ARROFMAP="arrmap";
+  private static final String JSON_WRAPPER_FUNCTION="json.wrf";
 
 
   public JSONWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
     super(writer, req, rsp);
     namedListStyle = req.getParam(JSON_NL_STYLE);
     namedListStyle = namedListStyle==null ? JSON_NL_MAP : namedListStyle.intern();
+    wrapperFunction = req.getParam(JSON_WRAPPER_FUNCTION);
   }
 
   public void writeResponse() throws IOException {
@@ -65,7 +68,13 @@
     if (nl.size()>1 && nl.getVal(1) instanceof DocList && nl.getName(1)==null) {
       nl.setName(1,"response");
     }
+    if(wrapperFunction!=null) {
+        writer.write(wrapperFunction + "(");
+    }
     writeNamedList(null, nl);
+    if(wrapperFunction!=null) {
+        writer.write(")");
+    }
   }
 
   protected void writeKey(String fname, boolean needsEscaping) throws IOException {