add control over the base64 variant

This commit is contained in:
kimchy 2010-03-29 00:39:13 +03:00
parent 913a486f99
commit 651cd78456
2 changed files with 14 additions and 1 deletions
.idea/dictionaries
plugins/attachments/src/main/java/org/elasticsearch/plugin/attachments/index/mapper

@ -30,6 +30,7 @@
<w>joda</w> <w>joda</w>
<w>jsonp</w> <w>jsonp</w>
<w>lifecycle</w> <w>lifecycle</w>
<w>linefeeds</w>
<w>lucene</w> <w>lucene</w>
<w>metadata</w> <w>metadata</w>
<w>millis</w> <w>millis</w>

@ -21,6 +21,8 @@ package org.elasticsearch.plugin.attachments.index.mapper;
import org.apache.tika.exception.TikaException; import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata; import org.apache.tika.metadata.Metadata;
import org.codehaus.jackson.Base64Variant;
import org.codehaus.jackson.Base64Variants;
import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken; import org.codehaus.jackson.JsonToken;
import org.elasticsearch.index.mapper.FieldMapperListener; import org.elasticsearch.index.mapper.FieldMapperListener;
@ -166,6 +168,7 @@ public class JsonAttachmentMapper implements JsonMapper {
byte[] content = null; byte[] content = null;
String contentType = null; String contentType = null;
String name = null; String name = null;
Base64Variant base64Variant = Base64Variants.getDefaultVariant();
JsonParser jp = jsonContext.jp(); JsonParser jp = jsonContext.jp();
JsonToken token = jp.getCurrentToken(); JsonToken token = jp.getCurrentToken();
@ -178,11 +181,20 @@ public class JsonAttachmentMapper implements JsonMapper {
currentFieldName = jp.getCurrentName(); currentFieldName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) { } else if (token == JsonToken.VALUE_STRING) {
if ("content".equals(currentFieldName)) { if ("content".equals(currentFieldName)) {
content = jp.getBinaryValue(); content = jp.getBinaryValue(base64Variant);
} else if ("_content_type".equals(currentFieldName)) { } else if ("_content_type".equals(currentFieldName)) {
contentType = jp.getText(); contentType = jp.getText();
} else if ("_name".equals(currentFieldName)) { } else if ("_name".equals(currentFieldName)) {
name = jp.getText(); name = jp.getText();
} else if ("_base64".equals(currentFieldName)) {
String variant = jp.getText();
if ("mime".equals(variant)) {
base64Variant = Base64Variants.MIME;
} else if ("mime_no_linefeeds".equals(variant)) {
base64Variant = Base64Variants.MIME_NO_LINEFEEDS;
} else {
throw new MapperParsingException("Can't handle base64 [" + variant + "]");
}
} }
} }
} }