added json.wrf, wrapper function: SOLR-56

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@465369 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-10-18 20:58:27 +00:00
parent 1a12258057
commit d2fbaf889f
2 changed files with 12 additions and 0 deletions

View File

@ -59,6 +59,9 @@ New Features
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

View File

@ -41,17 +41,20 @@ class JSONWriter extends TextResponseWriter {
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 @@ class JSONWriter extends TextResponseWriter {
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 {