use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class UserProfileAction method getPhotoThumbData.
public byte[] getPhotoThumbData() {
List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.USER);
GluuAttribute photoAttribute = attributeService.getAttributeByName("photo1", attributes);
GluuCustomAttribute customAttribute = new GluuCustomAttribute("photo1", this.person.getAttribute("photo1"));
customAttribute.setMetadata(photoAttribute);
GluuImage image = imageService.getImage(customAttribute);
if (image == null) {
return imageService.getBlankPhotoData();
}
return imageService.getThumImageData(image);
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class WhitePagesAction method getPhotoThumbData.
public byte[] getPhotoThumbData(GluuCustomPerson person) {
List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.USER);
GluuAttribute photoAttribute = attributeService.getAttributeByName(PHOTO_NAME, attributes);
GluuCustomAttribute customAttribute = new GluuCustomAttribute(PHOTO_NAME, person.getAttribute(PHOTO_NAME));
customAttribute.setMetadata(photoAttribute);
GluuImage image = imageService.getImage(customAttribute);
if (image == null || (person.getGluuOptOuts() != null && person.getGluuOptOuts().contains(PHOTO_NAME))) {
return imageService.getBlankPhotoData();
}
return imageService.getThumImageData(image);
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class ScopeDescriptionDownloadAction method downloadIcon.
public void downloadIcon() {
byte[] resultFile = null;
ScopeDescription scopeDescription = getScopeDescription();
if (scopeDescription != null) {
GluuImage gluuImage = imageService.getGluuImageFromXML(scopeDescription.getFaviconImageAsXml());
try {
resultFile = imageService.getThumImageData(gluuImage);
} catch (Exception ex) {
log.error("Failed to generate image response", ex);
}
}
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
if (resultFile == null) {
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
FileDownloader.sendError(response, "Failed to prepare icon");
} else {
ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
ResponseHelper.downloadFile(scopeDescription.getId() + ".jpg", "image/jpeg", resultFile, contentDisposition, facesContext);
}
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class FaviconImageServlet method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) throws ServletException, IOException {
log.debug("Starting organization favicon upload");
String preview = httpServletRequest.getParameter("preview");
GluuOrganization organization = null;
try {
organization = organizationService.getOrganization();
} catch (Exception ex) {
log.error("an Error Occured", ex);
}
GluuImage image = null;
if ("true".equals(preview)) {
image = imageService.getGluuImageFromXML(organization.getTempFaviconImage());
if (image != null) {
image.setStoreTemporary(true);
}
}
if (!"true".equals(preview) || image == null) {
image = imageService.getGluuImageFromXML(organization.getFaviconImage());
}
if (image != null) {
image.setLogo(false);
}
OutputStream os = null;
InputStream is = null;
try {
DownloadWrapper downloadWrapper = null;
// Send customized organization logo
if (image != null) {
File file = null;
try {
file = imageService.getSourceFile(image);
} catch (Exception ex) {
log.error("an Error Occured", ex);
}
try {
is = FileUtils.openInputStream(file);
if (is != null && file != null) {
downloadWrapper = new DownloadWrapper(is, image.getSourceName(), image.getSourceContentType(), image.getCreationDate(), (int) file.length());
}
} catch (IOException ex) {
log.error("Organization favicon image doesn't exist", ex);
FileDownloader.sendError(response);
return;
}
} else {
// If customized logo doesn't exist then send default
// organization logo
String defaultFaviconFileName = "/WEB-INF/static/images/favicon_ic.ico";
is = getServletContext().getResourceAsStream(defaultFaviconFileName);
if (is == null) {
log.error("Default organization favicon 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 favicon image size", ex);
FileDownloader.sendError(response);
return;
} finally {
IOUtils.closeQuietly(is);
}
is = getServletContext().getResourceAsStream(defaultFaviconFileName);
downloadWrapper = new DownloadWrapper(is, "favicon_ic.ico", "image/x-icon", new Date(), (int) contentLength);
}
try {
int logoSize = FileDownloader.writeOutput(downloadWrapper, ContentDisposition.INLINE, response);
response.getOutputStream().flush();
log.debug("Successfully send organization favicon with size", logoSize);
} catch (IOException ex) {
log.error("Failed to send organization favicon", ex);
FileDownloader.sendError(response);
}
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
use of org.xdi.model.GluuImage in project oxTrust by GluuFederation.
the class UpdateOrganizationAction method setFaviconImageImpl.
public void setFaviconImageImpl(UploadedFile uploadedFile) {
removeFaviconImage();
GluuImage newFaviconImage = imageService.constructImage(currentPerson, uploadedFile);
newFaviconImage.setStoreTemporary(true);
newFaviconImage.setLogo(false);
try {
if (imageService.createFaviconImageFiles(newFaviconImage)) {
this.curFaviconImage = newFaviconImage;
}
this.organization.setFaviconImage(imageService.getXMLFromGluuImage(newFaviconImage));
} catch (Exception ex) {
log.error("Failed to store favicon image: '{}'", ex, newFaviconImage);
}
}
Aggregations