Search in sources :

Example 6 with GluuImage

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);
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuImage(org.xdi.model.GluuImage) GluuAttribute(org.xdi.model.GluuAttribute)

Example 7 with GluuImage

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);
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuImage(org.xdi.model.GluuImage) GluuAttribute(org.xdi.model.GluuAttribute)

Example 8 with GluuImage

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);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ContentDisposition(org.xdi.util.io.FileDownloader.ContentDisposition) ExternalContext(javax.faces.context.ExternalContext) GluuImage(org.xdi.model.GluuImage) HttpServletResponse(javax.servlet.http.HttpServletResponse) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 9 with GluuImage

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);
    }
}
Also used : DownloadWrapper(org.xdi.util.io.DownloadWrapper) InputStream(java.io.InputStream) GluuImage(org.xdi.model.GluuImage) OutputStream(java.io.OutputStream) IOException(java.io.IOException) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) File(java.io.File) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Date(java.util.Date)

Example 10 with GluuImage

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);
    }
}
Also used : GluuImage(org.xdi.model.GluuImage) MessagingException(javax.mail.MessagingException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) AuthenticationFailedException(javax.mail.AuthenticationFailedException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

GluuImage (org.xdi.model.GluuImage)14 IOException (java.io.IOException)6 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)4 Date (java.util.Date)3 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)3 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ParseException (java.text.ParseException)2 AuthenticationFailedException (javax.mail.AuthenticationFailedException)2 MessagingException (javax.mail.MessagingException)2 GluuOrganization (org.gluu.oxtrust.model.GluuOrganization)2 GluuAttribute (org.xdi.model.GluuAttribute)2 DownloadWrapper (org.xdi.util.io.DownloadWrapper)2 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 ServletException (javax.servlet.ServletException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 UploadedFile (org.richfaces.model.UploadedFile)1 ScopeDescription (org.xdi.oxauth.model.uma.persistence.ScopeDescription)1