Search in sources :

Example 6 with UnsupportedCaptionFormatException

use of org.opencastproject.caption.api.UnsupportedCaptionFormatException in project opencast by opencast.

the class CaptionServiceRemoteImpl method getLanguageList.

/**
 * @see org.opencastproject.caption.api.CaptionService#getLanguageList(MediaPackageElement, String)
 */
@Override
public String[] getLanguageList(MediaPackageElement input, String format) throws UnsupportedCaptionFormatException, CaptionConverterException {
    HttpPost post = new HttpPost("/languages");
    try {
        List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
        params.add(new BasicNameValuePair("captions", MediaPackageElementParser.getAsXml(input)));
        params.add(new BasicNameValuePair("input", format));
        post.setEntity(new UrlEncodedFormEntity(params));
    } catch (Exception e) {
        throw new CaptionConverterException(e);
    }
    HttpResponse response = null;
    try {
        response = getResponse(post);
        if (response != null) {
            List<String> langauges = new ArrayList<String>();
            Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(EntityUtils.toString(response.getEntity(), "UTF-8"));
            NodeList languages = doc.getElementsByTagName("languages");
            for (int i = 0; i < languages.getLength(); i++) {
                Node item = languages.item(i);
                langauges.add(item.getTextContent());
            }
            logger.info("Catalog languages received from remote caption service");
            return langauges.toArray(new String[langauges.size()]);
        }
    } catch (Exception e) {
        throw new CaptionConverterException("Unable to get catalog languages " + input + " using a remote caption service", e);
    } finally {
        closeConnection(response);
    }
    throw new CaptionConverterException("Unable to get catalog languages" + input + " using a remote caption service");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CaptionConverterException(org.opencastproject.caption.api.CaptionConverterException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Document(org.w3c.dom.Document) CaptionConverterException(org.opencastproject.caption.api.CaptionConverterException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) UnsupportedCaptionFormatException(org.opencastproject.caption.api.UnsupportedCaptionFormatException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair)

Aggregations

UnsupportedCaptionFormatException (org.opencastproject.caption.api.UnsupportedCaptionFormatException)6 CaptionConverterException (org.opencastproject.caption.api.CaptionConverterException)5 CaptionConverter (org.opencastproject.caption.api.CaptionConverter)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 HttpResponse (org.apache.http.HttpResponse)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 HttpPost (org.apache.http.client.methods.HttpPost)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 Caption (org.opencastproject.caption.api.Caption)2 NotFoundException (org.opencastproject.util.NotFoundException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 URI (java.net.URI)1 Job (org.opencastproject.job.api.Job)1 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)1