use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.
the class DefaultTemplateSet method renderFieldContent.
protected void renderFieldContent(Context context, Hit hit, String name, XMLWriter writer) throws IOException {
boolean dumpedRaw = false;
if (hit instanceof FastHit && ((FastHit) hit).fieldIsNotDecoded(name)) {
writer.closeStartTag();
if ((writer.getWriter() instanceof ByteWriter) && context.isUtf8Output()) {
dumpedRaw = dumpBytes((ByteWriter) writer.getWriter(), (FastHit) hit, name);
}
if (dumpedRaw) {
// let the xml writer note that this tag had content
writer.content("", false);
}
}
if (!dumpedRaw) {
String xmlval = hit.getFieldXML(name);
if (xmlval == null) {
xmlval = "(null)";
}
writer.escapedContent(xmlval, false);
}
}
use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.
the class DocumentFieldTemplate method hit.
@Override
public void hit(Context context, Writer writer) throws IOException {
DocumentHit hit = (DocumentHit) context.get("hit");
Document doc = hit.getDocument();
// Assume field existence has been checked before we ever get here.
// Also assume that relevant encoding/content type is set
// appropriately according to the request and the field's content
// type, as this is immutable in the template set.
FieldValue value = doc.getFieldValue(field);
if (field.getDataType() == DataType.RAW) {
ByteWriter bw = (ByteWriter) writer;
bw.append(((Raw) value).getByteBuffer().array());
} else {
writer.write(XML.xmlEscape(value.toString(), false));
}
}
use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.
the class Renderer method createWriter.
private Writer createWriter(OutputStream stream, Result result) {
Charset cs = Charset.forName(getCharacterEncoding(result));
CharsetEncoder encoder = cs.newEncoder();
return new ByteWriter(stream, encoder);
}
use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.
the class SyncDefaultRenderer method renderFieldContentPossiblyNotDecoded.
private void renderFieldContentPossiblyNotDecoded(XMLWriter writer, Hit hit, boolean probablyNotDecoded, String fieldName) throws IOException {
boolean dumpedRaw = false;
if (probablyNotDecoded && (hit instanceof FastHit)) {
writer.closeStartTag();
if ((writer.getWriter() instanceof ByteWriter) && context.isUtf8Output()) {
dumpedRaw = UserTemplate.dumpBytes((ByteWriter) writer.getWriter(), (FastHit) hit, fieldName);
}
if (dumpedRaw) {
// let the xml writer note that this tag had content
writer.content("", false);
}
}
if (!dumpedRaw) {
String xmlval = hit.getFieldXML(fieldName);
if (xmlval == null) {
xmlval = "(null)";
}
writer.escapedContent(xmlval, false);
}
}
use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.
the class DefaultRenderer method beginResponse.
@Override
public void beginResponse(OutputStream stream) throws IOException {
Charset cs = Charset.forName(getRequestedEncoding(getResult().getQuery()));
CharsetEncoder encoder = cs.newEncoder();
writer = wrapWriter(new ByteWriter(stream, encoder));
header(writer, getResult());
if (getResult().hits().getError() != null || getResult().hits().getQuery().errors().size() > 0) {
error(writer, getResult());
}
if (getResult().getConcreteHitCount() == 0) {
emptyResult(writer, getResult());
}
if (getResult().getContext(false) != null) {
queryContext(writer, getResult().getContext(false), getResult().getQuery());
}
}
Aggregations