Example usage for com.google.common.net MediaType MICROSOFT_POWERPOINT

List of usage examples for com.google.common.net MediaType MICROSOFT_POWERPOINT

Introduction

In this page you can find the example usage for com.google.common.net MediaType MICROSOFT_POWERPOINT.

Prototype

MediaType MICROSOFT_POWERPOINT

To view the source code for com.google.common.net MediaType MICROSOFT_POWERPOINT.

Click Source Link

Usage

From source file:org.ambraproject.wombat.controller.PowerPointController.java

@RequestMapping(name = "powerPoint", value = "/article/figure/powerpoint")
public void download(HttpServletRequest request, HttpServletResponse response, @SiteParam Site site,
        RequestedDoiVersion figureId) throws IOException {
    AssetPointer assetPointer = articleResolutionService.toParentIngestion(figureId);
    ArticlePointer parentArticleId = assetPointer.getParentArticle();

    ArticleMetadata parentArticle = articleMetadataFactory
            .get(site, figureId.forDoi(parentArticleId.getDoi()), parentArticleId)
            .validateVisibility("powerPoint");
    List<Map<String, ?>> figureViewList = parentArticle.getFigureView();
    Map<String, ?> figureMetadata = findFigureViewFor(figureViewList, assetPointer).orElseThrow(
            () -> new NotFoundException("Asset exists but is not a figure: " + assetPointer.getAssetDoi()));

    String figureTitle = (String) figureMetadata.get("title");
    String figureDescription = (String) figureMetadata.get("description");

    URL articleUrl = buildArticleUrl(request, site, parentArticleId);
    ByteSource imageFileSource = getImageFile(assetPointer);
    ByteSource logoSource = new LogoSource(site.getTheme());

    Map<String, ?> parentArticleMetadata = parentArticle.getIngestionMetadata();
    List<Map<String, ?>> parentArticleAuthors = (List<Map<String, ?>>) parentArticle.getAuthors()
            .get("authors");

    SlideShow powerPointFile = new PowerPointDownload(parentArticleMetadata, parentArticleAuthors, articleUrl,
            figureTitle, figureDescription, imageFileSource, logoSource).createPowerPointFile();

    response.setContentType(MediaType.MICROSOFT_POWERPOINT.toString());
    response.setHeader(HttpHeaders.CONTENT_DISPOSITION,
            "attachment; filename=" + getDownloadFilename(assetPointer));
    try (OutputStream outputStream = response.getOutputStream()) {
        powerPointFile.write(outputStream);
    }/*  www.j  a v  a2 s.  c  om*/
}