use of io.gravitee.rest.api.model.InlinePictureEntity in project gravitee-management-rest-api by gravitee-io.
the class CategoryServiceImpl method getBackground.
@Override
public InlinePictureEntity getBackground(String categoryId) {
CategoryEntity categoryEntity = findById(categoryId);
InlinePictureEntity imageEntity = new InlinePictureEntity();
if (categoryEntity.getBackground() != null) {
String[] parts = categoryEntity.getBackground().split(";", 2);
imageEntity.setType(parts[0].split(":")[1]);
String base64Content = categoryEntity.getBackground().split(",", 2)[1];
imageEntity.setContent(DatatypeConverter.parseBase64Binary(base64Content));
}
return imageEntity;
}
use of io.gravitee.rest.api.model.InlinePictureEntity in project gravitee-management-rest-api by gravitee-io.
the class CategoryServiceImpl method getPicture.
@Override
public InlinePictureEntity getPicture(String categoryId) {
CategoryEntity categoryEntity = findById(categoryId);
InlinePictureEntity imageEntity = new InlinePictureEntity();
if (categoryEntity.getPicture() != null) {
String[] parts = categoryEntity.getPicture().split(";", 2);
imageEntity.setType(parts[0].split(":")[1]);
String base64Content = categoryEntity.getPicture().split(",", 2)[1];
imageEntity.setContent(DatatypeConverter.parseBase64Binary(base64Content));
}
return imageEntity;
}
use of io.gravitee.rest.api.model.InlinePictureEntity in project gravitee-management-rest-api by gravitee-io.
the class CategoryResource method background.
@GET
@Path("background")
public Response background(@Context Request request, @PathParam("categoryId") String categoryId) {
categoryService.findNotHiddenById(categoryId);
InlinePictureEntity image = categoryService.getBackground(categoryId);
return createPictureResponse(request, image);
}
use of io.gravitee.rest.api.model.InlinePictureEntity in project gravitee-management-rest-api by gravitee-io.
the class ThemeResource method buildPictureResponse.
private Response buildPictureResponse(PictureEntity picture, @Context Request request) {
if (picture == null) {
return Response.ok().build();
}
if (picture instanceof UrlPictureEntity) {
return Response.temporaryRedirect(URI.create(((UrlPictureEntity) picture).getUrl())).build();
}
CacheControl cc = new CacheControl();
cc.setNoTransform(true);
cc.setMustRevalidate(false);
cc.setNoCache(false);
cc.setMaxAge(86400);
InlinePictureEntity image = (InlinePictureEntity) picture;
EntityTag etag = new EntityTag(Integer.toString(new String(image.getContent()).hashCode()));
Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
if (builder != null) {
// Preconditions are not met, returning HTTP 304 'not-modified'
return builder.cacheControl(cc).build();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(image.getContent(), 0, image.getContent().length);
return Response.ok().entity(baos).cacheControl(cc).tag(etag).type(image.getType()).build();
}
use of io.gravitee.rest.api.model.InlinePictureEntity in project gravitee-management-rest-api by gravitee-io.
the class ThemeServiceImpl method convertToPicture.
private PictureEntity convertToPicture(String picture) {
if (picture.matches("^(http|https)://.*$")) {
return new UrlPictureEntity(picture);
} else {
InlinePictureEntity imageEntity = new InlinePictureEntity();
String[] parts = picture.split(";", 2);
imageEntity.setType(parts[0].split(":")[1]);
String base64Content = picture.split(",", 2)[1];
imageEntity.setContent(DatatypeConverter.parseBase64Binary(base64Content));
return imageEntity;
}
}
Aggregations