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");
}
Aggregations