2020-01-23 17:35:11 +01:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
2020-01-24 17:03:05 +01:00
|
|
|
import java.io.FileInputStream;
|
2020-01-23 17:35:11 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping(value = {"/api/language/"})
|
|
|
|
public class LanguageController {
|
|
|
|
|
|
|
|
Environment environment;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public LanguageController(Environment environment) {
|
|
|
|
this.environment = environment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "{lang}", method = RequestMethod.GET)
|
|
|
|
public ResponseEntity getLanguage(@PathVariable String lang) throws IOException {
|
|
|
|
|
|
|
|
String fileName = this.environment.getProperty("language.path") + lang + ".json";
|
2020-01-24 17:03:05 +01:00
|
|
|
InputStream is = new FileInputStream(fileName);
|
2020-01-23 17:35:11 +01:00
|
|
|
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
responseHeaders.setContentLength(is.available());
|
2020-01-24 17:03:05 +01:00
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
|
2020-01-23 17:35:11 +01:00
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
|
|
|
byte[] content = new byte[is.available()];
|
|
|
|
is.read(content);
|
|
|
|
is.close();
|
|
|
|
|
|
|
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
|
|
|
}
|
|
|
|
}
|