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);
}
}
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);
}
}
Aggregations