Search in sources :

Example 1 with ContentDisposition

use of org.xdi.util.io.FileDownloader.ContentDisposition in project oxTrust by GluuFederation.

the class ScopeDescriptionDownloadAction method downloadFile.

public void downloadFile() {
    byte[] resultFile = null;
    ScopeDescription scopeDescription = getScopeDescription();
    if (scopeDescription != null) {
        JSONObject jsonObject = new JSONObject();
        try {
            HashMap<String, List<String>> pageParams = new HashMap<String, List<String>>();
            pageParams.put("scope", Arrays.asList(scopeDescription.getId()));
            String umaScope = viewHandlerService.getBookmarkableURL("/uma/scope/scopeDescriptionFile.xhtml", pageParams);
            jsonObject.put("name", scopeDescription.getId());
            jsonObject.put("icon_uri", umaScope);
            resultFile = jsonObject.toString().getBytes("UTF-8");
        } catch (Exception ex) {
            log.error("Failed to generate json response", ex);
        }
    }
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (resultFile == null) {
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        FileDownloader.sendError(response, "Failed to generate json file");
    } else {
        ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
        ResponseHelper.downloadFile(scopeDescription.getId() + ".json", "application/json;charset=UTF-8", resultFile, contentDisposition, facesContext);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) JSONObject(org.codehaus.jettison.json.JSONObject) ContentDisposition(org.xdi.util.io.FileDownloader.ContentDisposition) HashMap(java.util.HashMap) ExternalContext(javax.faces.context.ExternalContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) List(java.util.List) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 2 with ContentDisposition

use of org.xdi.util.io.FileDownloader.ContentDisposition in project oxTrust by GluuFederation.

the class ScopeDescriptionDownloadAction method downloadIcon.

public void downloadIcon() {
    byte[] resultFile = null;
    UmaScopeDescription 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) UmaScopeDescription(org.xdi.oxauth.model.uma.persistence.UmaScopeDescription) ExternalContext(javax.faces.context.ExternalContext) GluuImage(org.xdi.model.GluuImage) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException)

Aggregations

ExternalContext (javax.faces.context.ExternalContext)2 FacesContext (javax.faces.context.FacesContext)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ContentDisposition (org.xdi.util.io.FileDownloader.ContentDisposition)2 HashMap (java.util.HashMap)1 List (java.util.List)1 JSONObject (org.codehaus.jettison.json.JSONObject)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)1 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)1 GluuImage (org.xdi.model.GluuImage)1 ScopeDescription (org.xdi.oxauth.model.uma.persistence.ScopeDescription)1 UmaScopeDescription (org.xdi.oxauth.model.uma.persistence.UmaScopeDescription)1