Search in sources :

Example 1 with SmilException

use of org.opencastproject.smil.api.SmilException in project opencast by opencast.

the class SmilMediaElementImpl method convertTimeToMS.

/**
 * Convert time unit to milliseconds.
 *
 * @param timeUnit to convert
 * @return time unit in milliseconds
 * @throws SmilException if time unit format can't parsed
 */
protected long convertTimeToMS(String timeUnit) throws SmilException {
    TimeUnit unit;
    long time = -1;
    if (timeUnit.endsWith("ms")) {
        unit = TimeUnit.MILLISECONDS;
        time = Long.parseLong(timeUnit.replace("ms", "").trim());
    } else if (timeUnit.endsWith("s")) {
        unit = TimeUnit.SECONDS;
        time = (long) Double.parseDouble(timeUnit.replace("s", "").trim());
    } else {
        // TODO: parse other formats
        throw new SmilException("failed parsing time unit");
    }
    return unit.toMillis(time);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) SmilException(org.opencastproject.smil.api.SmilException)

Example 2 with SmilException

use of org.opencastproject.smil.api.SmilException in project opencast by opencast.

the class SmilResponseImplTest method testGetEntities.

/**
 * Test of getEntities method, of class SmilResponseImpl.
 */
@Test
public void testGetEntities() throws Exception {
    Smil smil = new SmilImpl();
    SmilResponse response = new SmilResponseImpl(smil);
    try {
        response.getEntities();
        fail("getEntities should fail, if entity count is zero");
    } catch (SmilException ex) {
    }
    response = new SmilResponseImpl(smil, smil.getBody());
    try {
        SmilObject[] entities = response.getEntities();
        assertSame(1, entities.length);
        assertSame(smil.getBody(), entities[0]);
    } catch (SmilException ex) {
        fail("getEntities should not throw an Exception if some entities are set");
    }
    response = new SmilResponseImpl(smil, new SmilObject[] { smil.getHead(), smil.getBody() });
    try {
        SmilObject[] entities = response.getEntities();
        assertSame(2, entities.length);
        assertSame(smil.getHead(), entities[0]);
        assertSame(smil.getBody(), entities[1]);
    } catch (SmilException ex) {
        fail("getEntities should not throw an Exception if some entities are set");
    }
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilImpl(org.opencastproject.smil.entity.SmilImpl) SmilObject(org.opencastproject.smil.entity.api.SmilObject) Smil(org.opencastproject.smil.entity.api.Smil) SmilException(org.opencastproject.smil.api.SmilException) Test(org.junit.Test)

Example 3 with SmilException

use of org.opencastproject.smil.api.SmilException in project opencast by opencast.

the class SmilServiceRest method addClips.

@POST
@Path("addClips")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "addClips", description = "Add new media elements based on given Tracks information and start / duration parameters. " + "ParentId specifies where to put the new media.", restParameters = { @RestParameter(name = "smil", description = "SMIL document where to add new media elements.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "parentId", description = "An element Id, were to add new media. ", isRequired = false, type = RestParameter.Type.STRING), @RestParameter(name = "tracks", description = "Tracks (MediaPackageElements) to add as media elements." + "Some information like Track source and flavor will be stored in ParamGroup (in SMIL Head) " + "and referenced by paramGroup media element attribute.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "start", description = "Track start position in milliseconds. " + "The start position will be applied to each media element.", isRequired = true, type = RestParameter.Type.INTEGER), @RestParameter(name = "duration", description = "Clip duration in milliseconds (should be positive). " + "The duration will be applied to each media element.", isRequired = true, type = RestParameter.Type.INTEGER) }, returnDescription = "Returns new Smil with new media elements inside " + "(the new media and metadata elements will be returned as response entities).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Add media elements to SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Tracks are not valid."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document doesn't contain an element with given parentId."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Start plus duration is bigger than Track length.") })
public Response addClips(@FormParam("smil") String smil, @FormParam("parentId") String parentId, @FormParam("tracks") String tracks, @FormParam("start") long start, @FormParam("duration") long duration) {
    SmilResponse smilResponse = null;
    List<Track> tracksList = null;
    try {
        smilResponse = smilService.fromXml(smil);
        tracksList = (List<Track>) MediaPackageElementParser.getArrayFromXml(tracks);
    } catch (SmilException ex) {
        logger.info(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
    } catch (MediaPackageException ex) {
        logger.error(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("Tracks are not valid.").build();
    }
    Track[] tracksArr = tracksList.toArray(new Track[tracksList.size()]);
    try {
        smilResponse = smilService.addClips(smilResponse.getSmil(), parentId, tracksArr, start, duration);
        return Response.ok(smilResponse).build();
    } catch (SmilException ex) {
        logger.info(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document doesn't contain an element with given parentId.").build();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilException(org.opencastproject.smil.api.SmilException) Track(org.opencastproject.mediapackage.Track) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 4 with SmilException

use of org.opencastproject.smil.api.SmilException in project opencast by opencast.

the class SmilServiceRest method addMeta.

@POST
@Path("addMeta")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "addMeta", description = "Add a meta element to SMIL head.", restParameters = { @RestParameter(name = "smil", description = "SMIL document where to add an meta element.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "name", description = "Value of meta name attribute.", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "content", description = "Value of meta content attribute.", isRequired = true, type = RestParameter.Type.STRING) }, returnDescription = "Returns SmilResponse with a new meta element inside " + "(the new meta will be returned as response entity).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Add par to SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid.") })
public Response addMeta(@FormParam("smil") String smil, @FormParam("name") String metaName, @FormParam("content") String metaContent) {
    SmilResponse smilResponse = null;
    try {
        smilResponse = smilService.fromXml(smil);
    } catch (SmilException ex) {
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
    }
    smilResponse = smilService.addMeta(smilResponse.getSmil(), metaName, metaContent);
    return Response.ok(smilResponse).build();
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilException(org.opencastproject.smil.api.SmilException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 5 with SmilException

use of org.opencastproject.smil.api.SmilException in project opencast by opencast.

the class SmilServiceRest method removeSmilElement.

@POST
@Path("remove")
@Produces({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
@RestQuery(name = "remove", description = "Remove an element with given Id from SMIL.", restParameters = { @RestParameter(name = "smil", description = "SMIL document.", isRequired = true, type = RestParameter.Type.TEXT), @RestParameter(name = "elementId", description = "Id of element to remove.", isRequired = true, type = RestParameter.Type.STRING) }, returnDescription = "Returns SMIL document without an element with given Id " + "(if SMIL document contains an element with given Id, this will be returned as entity).", reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Removing element from SMIL successfull."), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "SMIL document not valid.") })
public Response removeSmilElement(@FormParam("smil") String smil, @FormParam("elementId") String elementId) {
    SmilResponse smilResponse = null;
    try {
        smilResponse = smilService.fromXml(smil);
        smilResponse = smilService.removeSmilElement(smilResponse.getSmil(), elementId);
        return Response.ok(smilResponse).build();
    } catch (SmilException ex) {
        logger.info(ex.getMessage(), ex);
        return Response.status(HttpServletResponse.SC_BAD_REQUEST).entity("SMIL document invalid.").build();
    }
}
Also used : SmilResponse(org.opencastproject.smil.api.SmilResponse) SmilException(org.opencastproject.smil.api.SmilException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

SmilException (org.opencastproject.smil.api.SmilException)14 SmilResponse (org.opencastproject.smil.api.SmilResponse)7 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)6 Track (org.opencastproject.mediapackage.Track)6 Smil (org.opencastproject.smil.entity.api.Smil)5 IOException (java.io.IOException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 InputStream (java.io.InputStream)3 URI (java.net.URI)3 JAXBException (javax.xml.bind.JAXBException)3 Job (org.opencastproject.job.api.Job)3 Catalog (org.opencastproject.mediapackage.Catalog)3 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)3 SmilMediaObject (org.opencastproject.smil.entity.media.api.SmilMediaObject)3 SmilMediaContainer (org.opencastproject.smil.entity.media.container.api.SmilMediaContainer)3 NotFoundException (org.opencastproject.util.NotFoundException)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 File (java.io.File)2