SerializationContext context,
Conventions conventions) {
Type type = Type.TEXT;
Object contentValue = null;
ObjectContext valueContext = null;
AccessibleObject accessor = objectContext.getAccessor(Value.class, conventions);
if (accessor != null && !(source instanceof Element)) {
contentValue = eval(accessor, source);
valueContext = new ObjectContext(contentValue, source, accessor);
Content _content = valueContext.getAnnotation(Content.class);
type = _content != null ? _content.type() : type;
} else {
Content _content = objectContext.getAnnotation(Content.class);
type = _content != null ? _content.type() : type;
contentValue = source;
valueContext = objectContext;
}
StreamWriter sw = context.getStreamWriter();
sw.startContent(type);
writeAttributes(source, objectContext, context, conventions);
if (type == Type.MEDIA || type == Type.XML) {
String mediatype = null;
AccessibleObject mtaccessor = valueContext.getAccessor(MediaType.class, conventions);
if (mtaccessor != null) {
Object mtvalue = eval(mtaccessor, contentValue);
mediatype = mtvalue != null ? toString(mtvalue) : null;
}
if (mediatype == null) {
MediaType mt = valueContext.getAnnotation(MediaType.class);
mediatype = mt != null && !mt.value().equals(DEFAULT) ? mt.value() : null;
}
if (mediatype != null)
sw.writeAttribute("type", mediatype);
}
switch (type) {
case TEXT:
case HTML:
sw.writeElementText(toString(contentValue));
break;
case XHTML:
Div div = null;
if (contentValue instanceof Div)
div = (Div)contentValue;
else {
div = context.getAbdera().getFactory().newDiv();
div.setValue(toString(contentValue));
}
context.serialize(div, new ObjectContext(div));
break;
case XML:
Element el = null;
if (contentValue instanceof Element)
el = (Element)contentValue;
else {
StringReader sr = new StringReader(toString(contentValue));
Document<Element> doc = context.getAbdera().getParser().parse(sr);
el = doc.getRoot();
}
context.serialize(el, new ObjectContext(el));
break;
case MEDIA:
try {
if (contentValue instanceof DataHandler)
sw.writeElementText((DataHandler)contentValue);