use of org.mycore.sass.MCRServletContextResourceImporter in project mycore by MyCoRe-Org.
the class MCRSassResource method getCSS.
@GET
@Path("{fileName:.+}")
@Produces("text/css")
public Response getCSS(@PathParam("fileName") String name, @Context Request request) {
try {
MCRServletContextResourceImporter importer = new MCRServletContextResourceImporter(context);
Optional<String> cssFile = MCRSassCompilerManager.getInstance().getCSSFile(name, Stream.of(importer).collect(Collectors.toList()));
if (cssFile.isPresent()) {
CacheControl cc = new CacheControl();
cc.setMaxAge(SECONDS_OF_ONE_DAY);
String etagString = MCRSassCompilerManager.getInstance().getLastMD5(name).get();
EntityTag etag = new EntityTag(etagString);
Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
if (builder != null) {
return builder.cacheControl(cc).tag(etag).build();
}
return Response.ok().status(Response.Status.OK).cacheControl(cc).tag(etag).entity(cssFile.get()).build();
} else {
return Response.status(Response.Status.NOT_FOUND).build();
}
} catch (IOException | CompilationException e) {
StreamingOutput so = (OutputStream os) -> e.printStackTrace(new PrintStream(os, true, "UTF-8"));
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(so).build();
}
}
Aggregations