use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class SearchRendererAdaptor method simpleRenderErrorHit.
/**
* Renders this hit as XML, disregarding the given template.
* The main error will be rendered first, the all the following errors.
*/
public boolean simpleRenderErrorHit(Writer writer, com.yahoo.search.result.ErrorHit errorHit) throws IOException {
XMLWriter xmlWriter = (writer instanceof XMLWriter) ? (XMLWriter) writer : new XMLWriter(writer, 10, -1);
xmlWriter.openTag("errordetails");
for (Iterator i = errorHit.errorIterator(); i.hasNext(); ) {
ErrorMessage error = (ErrorMessage) i.next();
rendererErrorHitMessageMessage(xmlWriter, errorHit, error);
}
xmlWriter.closeTag();
return true;
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class SyncDefaultRenderer method render.
/**
* Renders this result
*/
public void render(Writer writer, Result result) throws IOException {
XMLWriter xmlWriter = wrapWriter(writer);
context.put("context", context);
context.put("result", result);
context.setBoldOpenTag(defaultTemplate.getBoldOpenTag());
context.setBoldCloseTag(defaultTemplate.getBoldCloseTag());
context.setSeparatorTag(defaultTemplate.getSeparatorTag());
try {
header(xmlWriter, result);
} catch (Exception e) {
handleException(e);
}
if (result.hits().getError() != null || result.hits().getQuery().errors().size() > 0) {
error(xmlWriter, result);
}
if (result.getConcreteHitCount() == 0) {
emptyResult(xmlWriter, result);
}
if (result.getContext(false) != null) {
queryContext(xmlWriter, result.getContext(false), result.getQuery());
}
renderHitGroup(xmlWriter, result.hits(), result.hits().getQuery().getOffset() + 1);
endResult(xmlWriter, result);
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class SyncDefaultRenderer method queryContext.
public void queryContext(XMLWriter writer, QueryContext queryContext, Query owner) throws IOException {
try {
if (owner.getTraceLevel() != 0) {
XMLWriter xmlWriter = XMLWriter.from(writer);
xmlWriter.openTag("meta").attribute("type", QueryContext.ID);
TraceNode traceRoot = owner.getModel().getExecution().trace().traceNode().root();
traceRoot.accept(new RenderingVisitor(xmlWriter, owner.getStartTime()));
xmlWriter.closeTag();
}
} catch (Exception e) {
handleException(e);
}
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class StatusResponse method render.
@Override
public void render(OutputStream stream) throws IOException {
XMLWriter writer = new XMLWriter(new OutputStreamWriter(stream));
writer.openTag("status");
if (verbosity >= 2) {
writer.attribute(new Utf8String("description"), "Metrics since start");
}
if (snapshotTime == 0) {
MetricSnapshot snapshot = (new MetricSnapshot("Total metrics from start until current time", 0, manager.getActiveMetrics().getMetrics(), false));
manager.getTotalMetricSnapshot().addToSnapshot(snapshot, (int) (System.currentTimeMillis() / 1000), false);
snapshot.printXml(manager, "", verbosity, writer);
} else {
try {
manager.getMetricSnapshotSet(snapshotTime).getSnapshot().printXml(manager, "", verbosity, writer);
} catch (Exception e) {
writer.openTag("error");
writer.attribute(new Utf8String("details"), "No metric snapshot with period " + snapshotTime + " was found. Legal snapshot periods are: " + manager.getSnapshotPeriods());
writer.closeTag();
}
}
writer.closeTag();
writer.flush();
}
use of com.yahoo.text.XMLWriter in project vespa by vespa-engine.
the class FeedResponse method render.
@Override
public void render(OutputStream outputStream) throws IOException {
if (!errorMessages.isEmpty())
setStatus(VespaHeaders.getStatus(false, errorMessages.get(0), errorMessages.iterator()));
XMLWriter writer = new XMLWriter(new OutputStreamWriter(outputStream));
writer.openTag("result");
if (metrics != null) {
metrics.printXml(writer, 0, 0);
}
if (traces.length() > 0) {
writer.openTag("trace");
writer.append(traces);
writer.closeTag();
}
if (!errors.isEmpty()) {
writer.openTag("errors");
writer.attribute(new Utf8String("count"), errors.size());
for (int i = 0; i < errors.size() && i < 10; ++i) {
writer.openTag("error");
writer.attribute(new Utf8String("message"), errors.get(i));
writer.closeTag();
}
writer.closeTag();
}
writer.closeTag();
writer.flush();
outputStream.close();
}
Aggregations