use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class CustomAttributeAction method uploadImage.
public void uploadImage(FileUploadEvent event) {
UploadedFile uploadedFile = event.getUploadedFile();
this.uploadedImage = null;
try {
GluuImage image = imageService.constructImage(identity.getUser(), uploadedFile);
image.setStoreTemporary(true);
if (imageService.createImageFiles(image)) {
this.uploadedImage = image;
}
} finally {
try {
uploadedFile.delete();
} catch (IOException ex) {
log.error("Failed to remove temporary image", ex);
}
}
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class LogoImageServlet method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) {
log.debug("Starting organization logo upload");
try {
GluuOrganization organization = organizationService.getOrganization();
GluuImage image = imageService.getGluuImageFromXML(organization.getLogoImage());
if (image != null) {
image.setLogo(true);
}
OutputStream os = null;
InputStream is = null;
try {
DownloadWrapper downloadWrapper = null;
// Send customized organization logo
if (image != null) {
File file = imageService.getSourceFile(image);
try {
is = FileUtils.openInputStream(file);
downloadWrapper = new DownloadWrapper(is, image.getSourceName(), image.getSourceContentType(), image.getCreationDate(), (int) file.length());
} catch (IOException ex) {
log.error("Organization logo image doesn't exist", ex);
FileDownloader.sendError(response);
return;
}
} else {
// If customized logo doesn't exist then send default
// organization logo
String defaultLogoFileName = "/WEB-INF/static/images/default_logo.png";
is = getServletContext().getResourceAsStream(defaultLogoFileName);
if (is == null) {
log.error("Default organization logo image doesn't exist");
FileDownloader.sendError(response);
return;
}
// Calculate default logo size
long contentLength;
try {
contentLength = is.skip(Long.MAX_VALUE);
} catch (IOException ex) {
log.error("Failed to calculate default organization logo image size", ex);
FileDownloader.sendError(response);
return;
} finally {
IOUtils.closeQuietly(is);
}
is = getServletContext().getResourceAsStream(defaultLogoFileName);
downloadWrapper = new DownloadWrapper(is, "default_logo.png", "image/png", new Date(), (int) contentLength);
}
try {
int logoSize = FileDownloader.writeOutput(downloadWrapper, ContentDisposition.INLINE, response);
response.getOutputStream().flush();
log.debug("Successfully send organization logo with size", logoSize);
} catch (IOException ex) {
log.error("Failed to send organization logo", ex);
FileDownloader.sendError(response);
}
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
} catch (Exception ex) {
log.error("Failed to send organization logo", ex);
}
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class UpdateScopeDescriptionAction method setIconImageImpl.
private void setIconImageImpl(UploadedFile uploadedFile) {
removeIconImage();
GluuImage newIcon = imageService.constructImageWithThumbnail(currentPerson, uploadedFile, 16, 16);
this.curIconImage = newIcon;
try {
this.scopeDescription.setFaviconImageAsXml(jsonService.objectToJson(this.curIconImage));
} catch (Exception ex) {
log.error("Failed to store icon image: '{}'", ex, newIcon);
}
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class ImageService method constructImage.
/**
* Creates GluuImage object from uploaded file
*
* @param creator
* person uploading the file
* @param uploadedFile
* uploaded file
* @return GluuImage object
*/
public GluuImage constructImage(GluuCustomPerson creator, UploadedFile uploadedFile) {
GluuImage image = new GluuImage();
image.setUuid(RepositoryUtility.generateUUID());
image.setCreationDate(new Date());
image.setCreator(creator.getDn());
image.setSourceName(FilenameUtils.getName(uploadedFile.getName()));
image.setSourceContentType(uploadedFile.getContentType());
image.setSize(uploadedFile.getSize());
image.setData(uploadedFile.getData());
return image;
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class ImageService method deleteImage.
/**
* Deletes the image from repository
*
* @param customAttribute
* @throws Exception
*/
public void deleteImage(GluuCustomAttribute customAttribute) throws Exception {
GluuImage image = getImage(customAttribute);
deleteImage(image);
}
Aggregations