use of org.opencastproject.coverimage.CoverImageException in project opencast by opencast.
the class AbstractCoverImageService method createTempFile.
protected File createTempFile(Job job, String suffix) throws CoverImageException {
File tempFile;
try {
tempFile = File.createTempFile(COVERIMAGE_WORKSPACE_COLLECTION, Long.toString(job.getId()) + "_" + suffix);
log.debug("Created temporary file {}", tempFile);
} catch (IOException e) {
log.warn("Error creating temporary file:", e);
throw new CoverImageException("Error creating temporary file", e);
}
return tempFile;
}
use of org.opencastproject.coverimage.CoverImageException in project opencast by opencast.
the class AbstractCoverImageService method transformSvg.
protected static void transformSvg(Result svg, Source xmlSource, Document xslDoc, int width, int height, String posterImage) throws TransformerFactoryConfigurationError, CoverImageException {
if (svg == null || xmlSource == null || xslDoc == null)
throw new IllegalArgumentException("Neither svg nor xmlSource nor xslDoc must be null");
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = factory.newTransformer(new DOMSource(xslDoc));
} catch (TransformerConfigurationException e) {
// this should never happen...
throw new CoverImageException("The XSL transformer factory has serious configuration errors", e);
}
transformer.setParameter("width", width);
transformer.setParameter("height", height);
if (isNotBlank(posterImage))
transformer.setParameter("posterimage", posterImage);
Thread thread = Thread.currentThread();
ClassLoader loader = thread.getContextClassLoader();
thread.setContextClassLoader(AbstractCoverImageService.class.getClassLoader());
try {
log.debug("Transform XML source to SVG");
transformer.transform(xmlSource, svg);
} catch (TransformerException e) {
log.warn("Error while transforming SVG to image: {}", e.getMessage());
throw new CoverImageException("Error while transforming SVG to image", e);
} finally {
thread.setContextClassLoader(loader);
}
}
use of org.opencastproject.coverimage.CoverImageException in project opencast by opencast.
the class AbstractCoverImageService method parseXsl.
protected static Document parseXsl(String xsl) throws CoverImageException {
if (StringUtils.isBlank(xsl))
throw new IllegalArgumentException("XSL string must not be empty");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
Document xslDoc;
try {
log.debug("Parse given XSL to a org.w3c.dom.Document object");
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
xslDoc = dBuilder.parse(new InputSource(new ByteArrayInputStream(xsl.getBytes("utf-8"))));
} catch (ParserConfigurationException e) {
// this should never happen...
throw new CoverImageException("The XSLT parser has serious configuration errors", e);
} catch (SAXException e) {
log.warn("Error while parsing the XSLT stylesheet: {}", e.getMessage());
throw new CoverImageException("Error while parsing the XSLT stylesheet", e);
} catch (IOException e) {
log.warn("Error while reading the XSLT stylesheet: {}", e.getMessage());
throw new CoverImageException("Error while reading the XSLT stylesheet", e);
}
return xslDoc;
}
use of org.opencastproject.coverimage.CoverImageException in project opencast by opencast.
the class AbstractCoverImageService method rasterizeSvg.
protected static void rasterizeSvg(File svgSource, File pngResult) throws CoverImageException {
SVGConverter converter = new SVGConverter();
converter.setDestinationType(DestinationType.PNG);
converter.setDst(pngResult);
converter.setSources(new String[] { svgSource.getAbsolutePath() });
try {
log.debug("Start converting SVG to PNG");
converter.execute();
} catch (SVGConverterException e) {
log.warn("Error while converting the SVG to a PNG: {}", e.getMessage());
throw new CoverImageException("Error while converting the SVG to a PNG", e);
}
}
use of org.opencastproject.coverimage.CoverImageException in project opencast by opencast.
the class CoverImageServiceRemoteImpl method generateCoverImage.
@Override
public Job generateCoverImage(String xml, String xsl, String width, String height, String posterImageUri, String targetFlavor) throws CoverImageException {
HttpPost post = new HttpPost("/generate");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("xml", xml));
params.add(new BasicNameValuePair("xsl", xsl));
params.add(new BasicNameValuePair("width", width));
params.add(new BasicNameValuePair("height", height));
params.add(new BasicNameValuePair("posterimage", posterImageUri));
params.add(new BasicNameValuePair("targetflavor", targetFlavor));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (Exception e) {
throw new CoverImageException("Unable to assemble a remote cover image request", e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
String content = EntityUtils.toString(response.getEntity(), "UTF-8");
Job r = JobParser.parseJob(content);
logger.info("Cover image generation job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new CoverImageException("Unable to generate cover image using a remote generation service", e);
} finally {
closeConnection(response);
}
throw new CoverImageException("Unable to generate cover image using a remote generation service");
}
Aggregations