Search in sources :

Example 1 with GluuImage

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);
        }
    }
}
Also used : UploadedFile(org.richfaces.model.UploadedFile) GluuImage(org.xdi.model.GluuImage) IOException(java.io.IOException)

Example 2 with GluuImage

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);
    }
}
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) Date(java.util.Date) IOException(java.io.IOException)

Example 3 with GluuImage

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

Example 4 with GluuImage

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;
}
Also used : GluuImage(org.xdi.model.GluuImage) Date(java.util.Date)

Example 5 with GluuImage

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

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