List of usage examples for org.springframework.http HttpHeaders CONTENT_DISPOSITION
String CONTENT_DISPOSITION
To view the source code for org.springframework.http HttpHeaders CONTENT_DISPOSITION.
Click Source Link
From source file:org.artifactory.rest.resource.ssh.SshResource.java
@GET @Path("key/public") @Produces(MediaType.TEXT_PLAIN)/* w ww. j ava2 s . c o m*/ public Response getPublicKey() { java.nio.file.Path key = sshAuthService.getPublicKeyFile(); if (Files.notExists(key)) { return Response.status(HttpStatus.SC_NOT_FOUND).entity("No public SSH server key exists in Artifactory") .build(); } return Response.status(HttpStatus.SC_OK) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + key.getFileName().toString()) .entity(key.toFile()).build(); }
From source file:org.fao.geonet.api.records.MetadataApi.java
@ApiOperation(value = "Get a metadata record as ZIP", notes = "Metadata Exchange Format (MEF) is returned. MEF is a ZIP file containing " + "the metadata as XML and some others files depending on the version requested. " + "See http://geonetwork-opensource.org/manuals/trunk/eng/users/annexes/mef-format.html.", nickname = "getRecordAsZip") @RequestMapping(value = "/{metadataUuid}/formatters/zip", method = RequestMethod.GET, consumes = { MediaType.ALL_VALUE }, produces = { "application/zip", MEF_V1_ACCEPT_TYPE, MEF_V2_ACCEPT_TYPE }) @ApiResponses(value = { @ApiResponse(code = 200, message = "Return the record."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW) }) public @ResponseBody void getRecordAsZip( @ApiParam(value = API_PARAM_RECORD_UUID, required = true) @PathVariable String metadataUuid, @ApiParam(value = "MEF file format.", required = false) @RequestParam(required = false, defaultValue = "FULL") MEFLib.Format format, @ApiParam(value = "With related records (parent and service).", required = false) @RequestParam(required = false, defaultValue = "true") boolean withRelated, @ApiParam(value = "Resolve XLinks in the records.", required = false) @RequestParam(required = false, defaultValue = "true") boolean withXLinksResolved, @ApiParam(value = "Preserve XLink URLs in the records.", required = false) @RequestParam(required = false, defaultValue = "false") boolean withXLinkAttribute, @RequestParam(required = false, defaultValue = "true") boolean addSchemaLocation, @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = "application/x-gn-mef-2-zip") String acceptHeader, HttpServletResponse response, HttpServletRequest request) throws Exception { ApplicationContext appContext = ApplicationContextHolder.get(); GeonetworkDataDirectory dataDirectory = appContext.getBean(GeonetworkDataDirectory.class); AbstractMetadata metadata;/*w ww .j a v a 2s .c o m*/ try { metadata = ApiUtils.canViewRecord(metadataUuid, request); } catch (SecurityException e) { Log.debug(API.LOG_MODULE_NAME, e.getMessage(), e); throw new NotAllowedException(ApiParams.API_RESPONSE_NOT_ALLOWED_CAN_VIEW); } Path stylePath = dataDirectory.getWebappDir().resolve(Geonet.Path.SCHEMAS); Path file = null; ServiceContext context = ApiUtils.createServiceContext(request); MEFLib.Version version = MEFLib.Version.find(acceptHeader); if (version == MEFLib.Version.V1) { // This parameter is deprecated in v2. boolean skipUUID = false; file = MEFLib.doExport(context, metadataUuid, format.toString(), skipUUID, withXLinksResolved, withXLinkAttribute, addSchemaLocation); } else { Set<String> tmpUuid = new HashSet<String>(); tmpUuid.add(metadataUuid); // MEF version 2 support multiple metadata record by file. if (withRelated) { // Adding children in MEF file // Creating request for services search Element childRequest = new Element("request"); childRequest.addContent(new Element("parentUuid").setText(metadataUuid)); childRequest.addContent(new Element("to").setText("1000")); // Get children to export - It could be better to use GetRelated service TODO Set<String> childs = MetadataUtils.getUuidsToExport(metadataUuid, request, childRequest); if (childs.size() != 0) { tmpUuid.addAll(childs); } // Creating request for services search Element servicesRequest = new Element(Jeeves.Elem.REQUEST); servicesRequest .addContent(new Element(org.fao.geonet.constants.Params.OPERATES_ON).setText(metadataUuid)); servicesRequest.addContent(new Element(org.fao.geonet.constants.Params.TYPE).setText("service")); // Get linked services for export Set<String> services = MetadataUtils.getUuidsToExport(metadataUuid, request, servicesRequest); if (services.size() != 0) { tmpUuid.addAll(services); } } Log.info(Geonet.MEF, "Building MEF2 file with " + tmpUuid.size() + " records."); file = MEFLib.doMEF2Export(context, tmpUuid, format.toString(), false, stylePath, withXLinksResolved, withXLinkAttribute, false, addSchemaLocation); } response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=\"%s.zip\"", metadata.getUuid())); response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(Files.size(file))); response.setContentType(acceptHeader); FileUtils.copyFile(file.toFile(), response.getOutputStream()); }