}
protected XStreamRepresentation createRepresentation(Variant variant)
throws ResourceException
{
XStreamRepresentation representation = null;
try {
// check is this variant a supported one, to avoid calling getText() on potentially huge representations
if (MediaType.APPLICATION_JSON.equals(variant.getMediaType(), true)
|| MediaType.APPLICATION_XML.equals(variant.getMediaType(), true)
|| MediaType.TEXT_HTML.equals(variant.getMediaType(), true)) {
String text = (variant instanceof Representation) ? ((Representation) variant).getText() : "";
XStream xstream;
if (MediaType.APPLICATION_JSON.equals(variant.getMediaType(), true)
|| MediaType.TEXT_HTML.equals(variant.getMediaType(), true)) {
xstream = (XStream) getContext().getAttributes().get(PlexusRestletApplicationBridge.JSON_XSTREAM);
}
else if (MediaType.APPLICATION_XML.equals(variant.getMediaType(), true)) {
xstream = (XStream) getContext().getAttributes().get(PlexusRestletApplicationBridge.XML_XSTREAM);
}
else {
return null;
}
if (text != null) {
CharacterSet charset = variant.getCharacterSet();
if (charset == null) {
charset = CharacterSet.ISO_8859_1;
}
if (!CharacterSet.UTF_8.equals(charset)) {
// must fix text encoding NXCM-2494
text = new String(new String(text.getBytes(), "UTF-8").getBytes(charset.getName()));
}
}
representation = new XStreamRepresentation(xstream, text, variant.getMediaType());
return representation;
}
else {
return null;
}