use of fi.otavanopisto.muikku.plugins.dnm.parser.structure.model.Binary in project muikku by otavanopisto.
the class DeusNexStructureParser method parseBinary.
private Binary parseBinary(Element resourceElement) throws DeusNexSyntaxException, XPathExpressionException, DeusNexInternalException {
Binary binary = new Binary();
parseBasicResourceProperties(resourceElement, binary);
Element contentElement = (Element) DeusNexXmlUtils.findNodeByXPath(resourceElement, "content");
Node contentChild = contentElement.getFirstChild();
String textContent = null;
if (contentChild instanceof CDATASection) {
textContent = ((CDATASection) contentChild).getTextContent();
} else if (contentChild instanceof Text) {
textContent = ((Text) contentChild).getTextContent();
}
byte[] content;
try {
content = decodeDeusNexBinary(textContent);
} catch (UnsupportedEncodingException | DOMException e) {
throw new DeusNexInternalException("Could not retrieve binary content", e);
}
binary.setContent(content);
binary.setContentType(DeusNexXmlUtils.getChildValue(resourceElement, "contentType"));
return binary;
}
Aggregations