* @throws FeedServerClientException if the XML parse fails.
*/
private Map<String, Object> getMapFromEntry(FeedServerEntry entry)
throws FeedServerClientException {
// Get XML and convert to primitive Object map.
Content content = entry.getContent();
if (content instanceof OtherContent) {
OtherContent otherContent = (OtherContent) content;
log.info("Entry info " + otherContent.getXml().getBlob());
XmlUtil xmlUtil = new XmlUtil();
try {
String xmlText = otherContent.getXml().getBlob();
// TODO : This is a temporary work-around till a solution for escaping the
// '>' by the GData client library is worked
xmlText = xmlText.replaceAll("]]>", "]]>");
Map<String, Object> entity = xmlUtil.convertXmlToProperties(xmlText);
if (entity == null) {
entity = new HashMap<String, Object>();
}
// copy id which is the same as self and edit link
entity.put(ContentUtil.ID, entry.getId());
return entity;
} catch (SAXException e) {
throw new FeedServerClientException(e);
} catch (IOException e) {
throw new FeedServerClientException(e);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
}
} else if (content instanceof TextContent) {
TextContent textContent = (TextContent) content;
TextConstruct textConstruct = textContent.getContent();
int type = textContent.getContent().getType();
String typeName;
String text;
switch (type) {
case TextConstruct.Type.HTML:
typeName = "html";
text = ((HtmlTextConstruct) textConstruct).getHtml();
break;
case TextConstruct.Type.TEXT:
typeName = "text";
text = ((PlainTextConstruct) textConstruct).getPlainText();
break;
case TextConstruct.Type.XHTML:
typeName = "xhtml";
text = ((XhtmlTextConstruct) textConstruct).getXhtml().getBlob();
break;
default:
typeName = "unknown";
text = textConstruct.toString();
}
Map<String, Object> entity = new HashMap<String, Object>();
entity.put("content", text);
entity.put("type", typeName);
String lang = textContent.getContent().getLang();
if (lang != null) {
entity.put("lang", lang);
}
return entity;
} else {
throw new FeedServerClientException("Unsupported content class " +
content.getClass().getName());
}
}