added jsonp option to yjson result writer

pull/1/head
Michael Peter Christen 12 years ago
parent de58043205
commit 3a6097966d

@ -29,7 +29,6 @@ import javax.servlet.ServletException;
import net.yacy.cora.document.UTF8;
import net.yacy.cora.federate.solr.SolrServlet;
import net.yacy.cora.federate.solr.YaCySchema;
import net.yacy.cora.federate.solr.connector.EmbeddedSolrConnector;
import net.yacy.cora.federate.solr.responsewriter.EnhancedXMLResponseWriter;
import net.yacy.cora.federate.solr.responsewriter.GSAResponseWriter;

@ -107,6 +107,12 @@ public class JsonResponseWriter implements QueryResponseWriter {
resHead.offset = response.offset(); // equal to 'start'
resHead.numFound = response.matches();
String jsonp = request.getParams().get("jsonp"); // check for JSONP
if (jsonp != null) {
writer.write(jsonp.toCharArray());
writer.write("([".toCharArray());
}
// write header
writer.write(("{\"channels\": [{\n").toCharArray());
solitaireTag(writer, "totalResults", Integer.toString(resHead.numFound));
@ -269,6 +275,10 @@ public class JsonResponseWriter implements QueryResponseWriter {
writer.write("]},\n".toCharArray());
}
writer.write("]}]}\n".toCharArray());
if (jsonp != null) {
writer.write("])".toCharArray());
}
}
public static void solitaireTag(final Writer writer, final String tagname, String value) throws IOException {

Loading…
Cancel
Save