Search in sources :

Example 1 with ConfigurationException

use of org.opencastproject.util.ConfigurationException in project opencast by opencast.

the class HandleBuilderFactory method newHandleBuilder.

/**
 * Factory method that returns an instance of a handle builder.
 * <p>
 * It uses the following ordered lookup procedure to determine which implementation of the {@link HandleBuilder}
 * interface to use:
 * <ul>
 * <li>Implementation specified using the <code>opencast.handlebuilder</code> system property</li>
 * <li>Platform default implementation</li>
 * </ul>
 *
 * @return the handle builder
 * @throws ConfigurationException
 *           If the builder cannot be instantiated
 */
public HandleBuilder newHandleBuilder() throws ConfigurationException {
    if (builder == null) {
        try {
            Class<?> builderClass = Class.forName(builderClassName);
            builder = (HandleBuilder) builderClass.newInstance();
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("Class not found while creating handle builder: " + e.getMessage(), e);
        } catch (InstantiationException e) {
            throw new ConfigurationException("Instantiation exception while creating handle builder: " + e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Access exception while creating handle builder: " + e.getMessage(), e);
        }
    }
    return builder;
}
Also used : ConfigurationException(org.opencastproject.util.ConfigurationException)

Example 2 with ConfigurationException

use of org.opencastproject.util.ConfigurationException in project opencast by opencast.

the class MediaPackageReferenceTest method testMediaPackageReference.

/**
 * Test method for {@link org.opencastproject.mediapackage.MediaPackageImpl#add(java.net.URI)}.
 */
@Test
public void testMediaPackageReference() {
    try {
        // Add first catalog without any reference
        URI catalogXTestFile = MediaPackageReferenceTest.class.getResource("/dublincore.xml").toURI();
        MediaPackageElement catalogX = mediaPackage.add(catalogXTestFile);
        catalogX.setIdentifier("catalog-x");
        // Add second catalog with media package reference
        URI catalogYTestFile = MediaPackageReferenceTest.class.getResource("/dublincore.xml").toURI();
        MediaPackageElement catalogY = mediaPackage.add(catalogYTestFile);
        catalogY.referTo(new MediaPackageReferenceImpl(mediaPackage));
        catalogY.setIdentifier("catalog-y");
        // Add third catalog with track reference
        URI catalogZTestFile = MediaPackageReferenceTest.class.getResource("/dublincore.xml").toURI();
        MediaPackageElement catalogZ = mediaPackage.add(catalogZTestFile);
        catalogZ.referTo(new MediaPackageReferenceImpl("track", "track-1"));
        catalogZ.setIdentifier("catalog-z");
    } catch (UnsupportedElementException e) {
        fail("Adding of catalog failed: " + e.getMessage());
    } catch (URISyntaxException e) {
        fail("Adding of catalog failed: " + e.getMessage());
    }
    // Re-read the media package and test the references
    try {
        MediaPackageElement catalogX = mediaPackage.getElementById("catalog-x");
        assertTrue(catalogX.getReference() == null);
        MediaPackageElement catalogY = mediaPackage.getElementById("catalog-y");
        assertNotNull(catalogY.getReference());
        MediaPackageElement catalogZ = mediaPackage.getElementById("catalog-z");
        assertNotNull(catalogZ.getReference());
        assertTrue(catalogZ.getReference().matches(new MediaPackageReferenceImpl("track", "track-1")));
    } catch (ConfigurationException e) {
        fail("Configuration error while loading media package from manifest: " + e.getMessage());
    }
}
Also used : ConfigurationException(org.opencastproject.util.ConfigurationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.Test)

Example 3 with ConfigurationException

use of org.opencastproject.util.ConfigurationException in project opencast by opencast.

the class MediaPackageSerializerTest method testRelativeNativePaths.

@Test
public void testRelativeNativePaths() {
    try {
        XPath xPath = XPathFactory.newInstance().newXPath();
        // Create a media package and add an element
        MediaPackage mediaPackage = mediaPackageBuilder.createNew();
        mediaPackage.add(dcFile.toURI());
        // Test relative path, using serializer
        MediaPackageSerializer serializer = null;
        serializer = new DefaultMediaPackageSerializerImpl(manifestFile.getParentFile());
        Document xml = MediaPackageParser.getAsXml(mediaPackage, serializer);
        // Test linux file relative to media package root
        String expected = dcFile.getAbsolutePath().substring(packageDir.getAbsolutePath().length() + 1);
        assertEquals(expected, xPath.evaluate("//url", xml));
    } catch (MediaPackageException e) {
        fail("Media package excpetion while reading media package from manifest: " + e.getMessage());
    } catch (ConfigurationException e) {
        fail("Configuration exception while reading media package from manifest: " + e.getMessage());
    } catch (MalformedURLException e) {
        fail("Exception while creating url: " + e.getMessage());
    } catch (UnsupportedElementException e) {
        fail("Error while creating media package: " + e.getMessage());
    } catch (XPathExpressionException e) {
        fail("Selecting node form xml document failed: " + e.getMessage());
    }
}
Also used : XPath(javax.xml.xpath.XPath) MalformedURLException(java.net.MalformedURLException) ConfigurationException(org.opencastproject.util.ConfigurationException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 4 with ConfigurationException

use of org.opencastproject.util.ConfigurationException in project opencast by opencast.

the class MediaPackageBuilderFactory method newMediaPackageBuilder.

/**
 * Factory method that returns an instance of a media package builder.
 * <p>
 * It uses the following ordered lookup procedure to determine which implementation of the {@link MediaPackageBuilder}
 * interface to use:
 * <ul>
 * <li>Implementation specified using the <code>org.opencastproject.mediapackage.builder</code> system property</li>
 * <li>Platform default implementation</li>
 * </ul>
 *
 * @return the media package builder
 * @throws ConfigurationException
 *           If the builder cannot be instantiated
 */
public MediaPackageBuilder newMediaPackageBuilder() throws ConfigurationException {
    MediaPackageBuilder builder = null;
    try {
        Class<?> builderClass = Class.forName(builderClassName);
        builder = (MediaPackageBuilder) builderClass.newInstance();
    } catch (ClassNotFoundException e) {
        throw new ConfigurationException("Class not found while creating media package builder: " + e.getMessage(), e);
    } catch (InstantiationException e) {
        throw new ConfigurationException("Instantiation exception while creating media package builder: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException("Access exception while creating media package builder: " + e.getMessage(), e);
    }
    return builder;
}
Also used : ConfigurationException(org.opencastproject.util.ConfigurationException)

Example 5 with ConfigurationException

use of org.opencastproject.util.ConfigurationException in project opencast by opencast.

the class MediaPackageElementBuilderFactory method newElementBuilder.

/**
 * Factory method that returns an instance of a media package element builder.
 * <p>
 * It uses the following ordered lookup procedure to determine which implementation of the
 * {@link MediaPackageElementBuilder} interface to use:
 * <ul>
 * <li>Implementation specified using the <code>org.opencastproject.mediapackage.elementbuilder</code> system property
 * </li>
 * <li>Platform default implementation</li>
 * </ul>
 *
 * @return the media package element builder
 * @throws ConfigurationException
 *           If the builder cannot be instantiated
 */
public MediaPackageElementBuilder newElementBuilder() throws ConfigurationException {
    if (builder == null) {
        try {
            Class<?> builderClass = Class.forName(builderClassName, true, MediaPackageElementBuilderFactory.class.getClassLoader());
            builder = (MediaPackageElementBuilder) builderClass.newInstance();
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("Class not found while creating element builder: " + e.getMessage(), e);
        } catch (InstantiationException e) {
            throw new ConfigurationException("Instantiation exception while creating element builder: " + e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Access exception while creating element builder: " + e.getMessage(), e);
        } catch (Exception e) {
            throw new ConfigurationException("Exception while creating element builder: " + e.getMessage(), e);
        }
    }
    return builder;
}
Also used : ConfigurationException(org.opencastproject.util.ConfigurationException) ConfigurationException(org.opencastproject.util.ConfigurationException)

Aggregations

ConfigurationException (org.opencastproject.util.ConfigurationException)13 Test (org.junit.Test)5 MalformedURLException (java.net.MalformedURLException)4 XPath (javax.xml.xpath.XPath)4 XPathExpressionException (javax.xml.xpath.XPathExpressionException)4 Document (org.w3c.dom.Document)4 HashMap (java.util.HashMap)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Properties (java.util.Properties)1 Scanner (java.util.Scanner)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1