Hi,
Paul Davis schrieb:
Using foo.query.json?statement=xpath works great but, I can't use the
results in the esp files with an include.
I'd like to render the output as XML
is there a way to PUT an xml.esp to handle the results of a query so,
if I requested:
foo.query.xml?statement=xpath
the xml.esp could take the results?
Hmm, interesting request. This would probably a rather easy extension of
the JsonQueryServlet: (1) Register the servlet for the .xml extension in
addition to the .json extension and (2) enhance the dumpResult method to
support xml and json depending on the request extension.
Interested in providing a patch for this ?
alternatively, is there a way to include the json so that It can be
used by script instead of rendering?
This is actually possible with some "magic" and using a
SlingHttpServletResponseWrapper:
class WriterResponse extends SlingHttpServletResponseWrapper {
private StringWriter sw;
private PrintWriter pw;
WriterResponse(SlingHttpServletResponse delegatee) {
super(delegatee);
}
public PrintWriter getWriter() {
if (sw == null) {
sw = new StringWriter();
pw = new PrintWriter(sw);
}
return pw;
}
public ServletOutputStream getOutputStream() {
throw new IllegalStateException();
}
String getOuptut() {
if (sw != null) {
pw.flush();
return sw.toString();
}
return "";
}
}
This response you would hand over to the include statement for query
...include() and at the end call getOutput() to get at the result ...
Regards
Felix