use of org.opencastproject.mediapackage.UnsupportedElementException in project opencast by opencast.
the class CatalogBuilderPlugin method elementFromManifest.
/**
* {@inheritDoc}
*
* @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromManifest(org.w3c.dom.Node,
* org.opencastproject.mediapackage.MediaPackageSerializer)
*/
@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer) throws UnsupportedElementException {
String id = null;
String flavor = null;
URI url = null;
long size = -1;
Checksum checksum = null;
MimeType mimeType = null;
String reference = null;
try {
// id
id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);
// url
url = serializer.decodeURI(new URI(xpath.evaluate("url/text()", elementNode).trim()));
// flavor
flavor = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
// reference
reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);
// size
String documentSize = xpath.evaluate("size/text()", elementNode).trim();
if (!"".equals(documentSize))
size = Long.parseLong(documentSize);
// checksum
String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
checksum = Checksum.create(checksumType.trim(), checksumValue.trim());
// mimetype
String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
if (StringUtils.isNotEmpty(mimeTypeValue))
mimeType = MimeTypes.parseMimeType(mimeTypeValue);
// create the catalog
Catalog dc = CatalogImpl.fromURI(url);
if (StringUtils.isNotEmpty(id))
dc.setIdentifier(id);
// Add url
dc.setURI(url);
// Add flavor
if (flavor != null)
dc.setFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
// Add reference
if (StringUtils.isNotEmpty(reference))
dc.referTo(MediaPackageReferenceImpl.fromString(reference));
// Set size
if (size > 0)
dc.setSize(size);
// Set checksum
if (checksum != null)
dc.setChecksum(checksum);
// Set Mimetype
if (mimeType != null)
dc.setMimeType(mimeType);
// Tags
NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
for (int i = 0; i < tagNodes.getLength(); i++) {
dc.addTag(tagNodes.item(i).getTextContent());
}
return dc;
} catch (XPathExpressionException e) {
throw new UnsupportedElementException("Error while reading catalog information from manifest: " + e.getMessage());
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
} catch (URISyntaxException e) {
throw new UnsupportedElementException("Error while reading dublin core catalog " + url + ": " + e.getMessage());
}
}
Aggregations