Search in sources :

Example 11 with UnsupportedElementException

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());
    }
}
Also used : UnsupportedElementException(org.opencastproject.mediapackage.UnsupportedElementException) Checksum(org.opencastproject.util.Checksum) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MimeType(org.opencastproject.util.MimeType) Catalog(org.opencastproject.mediapackage.Catalog)

Aggregations

UnsupportedElementException (org.opencastproject.mediapackage.UnsupportedElementException)11 URI (java.net.URI)6 XPathExpressionException (javax.xml.xpath.XPathExpressionException)6 MimeType (org.opencastproject.util.MimeType)6 NodeList (org.w3c.dom.NodeList)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)4 Checksum (org.opencastproject.util.Checksum)4 FileInputStream (java.io.FileInputStream)3 MediaInspectionException (org.opencastproject.inspection.api.MediaInspectionException)3 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)3 NotFoundException (org.opencastproject.util.NotFoundException)3 Node (org.w3c.dom.Node)3 File (java.io.File)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 MediaAnalyzerException (org.opencastproject.inspection.ffmpeg.api.MediaAnalyzerException)2