|
|
|
@ -20,6 +20,7 @@ import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
@ -41,32 +42,36 @@ public class UserGuideController {
|
|
|
|
|
|
|
|
|
|
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
|
|
|
|
|
public ResponseEntity getUserGuide(@PathVariable(name = "lang") String lang) throws IOException {
|
|
|
|
|
long files = Files.list(Paths.get(this.environment.getProperty("userguide.path"))).count();
|
|
|
|
|
metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
|
|
|
|
|
Stream<Path> walk = Files.walk(Paths.get(this.environment.getProperty("userguide.path")));
|
|
|
|
|
List<String> result = walk.filter(Files::isRegularFile)
|
|
|
|
|
.map(Path::toString).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
String fileName = result.stream().filter(guide -> guide.contains("_" + lang)).findFirst().orElse(null);
|
|
|
|
|
if (fileName == null) {
|
|
|
|
|
fileName = result.stream().filter(guide -> guide.contains("_en")).findFirst().get();
|
|
|
|
|
long files = 0;
|
|
|
|
|
try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("userguide.path"))))) {
|
|
|
|
|
files = paths.count();
|
|
|
|
|
}
|
|
|
|
|
InputStream is = new FileInputStream(fileName);
|
|
|
|
|
metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
|
|
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty("userguide.path"))))) {
|
|
|
|
|
List<String> result = paths.filter(Files::isRegularFile)
|
|
|
|
|
.map(Path::toString).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
String fileName = result.stream().filter(guide -> guide.contains("_" + lang)).findFirst().orElse(null);
|
|
|
|
|
if (fileName == null) {
|
|
|
|
|
fileName = result.stream().filter(guide -> guide.contains("_en")).findFirst().get();
|
|
|
|
|
}
|
|
|
|
|
InputStream is = new FileInputStream(fileName);
|
|
|
|
|
|
|
|
|
|
Path path = Paths.get(fileName);
|
|
|
|
|
Path path = Paths.get(fileName);
|
|
|
|
|
|
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
|
responseHeaders.setContentLength(is.available());
|
|
|
|
|
responseHeaders.setContentType(MediaType.TEXT_HTML);
|
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + path.getFileName().toString());
|
|
|
|
|
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
|
|
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
|
|
|
|
|
HttpHeaders responseHeaders = new HttpHeaders();
|
|
|
|
|
responseHeaders.setContentLength(is.available());
|
|
|
|
|
responseHeaders.setContentType(MediaType.TEXT_HTML);
|
|
|
|
|
responseHeaders.set("Content-Disposition", "attachment;filename=" + path.getFileName().toString());
|
|
|
|
|
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();
|
|
|
|
|
byte[] content = new byte[is.available()];
|
|
|
|
|
is.read(content);
|
|
|
|
|
is.close();
|
|
|
|
|
|
|
|
|
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
|
|
|
|
return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|