Search in sources :

Example 1 with ByteWriter

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);
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) ByteWriter(com.yahoo.io.ByteWriter) Utf8String(com.yahoo.text.Utf8String)

Example 2 with ByteWriter

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));
    }
}
Also used : ByteWriter(com.yahoo.io.ByteWriter) Raw(com.yahoo.document.datatypes.Raw) FieldValue(com.yahoo.document.datatypes.FieldValue) Document(com.yahoo.document.Document)

Example 3 with ByteWriter

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);
}
Also used : Charset(java.nio.charset.Charset) ByteWriter(com.yahoo.io.ByteWriter) CharsetEncoder(java.nio.charset.CharsetEncoder)

Example 4 with ByteWriter

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);
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) ByteWriter(com.yahoo.io.ByteWriter) Utf8String(com.yahoo.text.Utf8String)

Example 5 with ByteWriter

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());
    }
}
Also used : Charset(java.nio.charset.Charset) ByteWriter(com.yahoo.io.ByteWriter) CharsetEncoder(java.nio.charset.CharsetEncoder)

Aggregations

ByteWriter (com.yahoo.io.ByteWriter)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Utf8String (com.yahoo.text.Utf8String)3 Charset (java.nio.charset.Charset)2 CharsetEncoder (java.nio.charset.CharsetEncoder)2 Document (com.yahoo.document.Document)1 FieldValue (com.yahoo.document.datatypes.FieldValue)1 Raw (com.yahoo.document.datatypes.Raw)1