use of javax.faces.context.ExternalContext 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);
}
}
use of javax.faces.context.ExternalContext in project acs-community-packaging by Alfresco.
the class ContentUpdateBean method updateFile.
/**
* Ajax method to update file content. A multi-part form is required as the input.
*
* "return-page" = javascript to execute on return from the upload request
* "nodeRef" = the nodeRef of the item to update the content of
*
* @throws Exception
*/
@InvokeCommand.ResponseMimetype(value = MimetypeMap.MIMETYPE_HTML)
public void updateFile() throws Exception {
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
upload.setHeaderEncoding("UTF-8");
List<FileItem> fileItems = upload.parseRequest(request);
String strNodeRef = null;
String strFilename = null;
String strReturnPage = null;
File file = null;
for (FileItem item : fileItems) {
if (item.isFormField() && item.getFieldName().equals("return-page")) {
strReturnPage = item.getString();
} else if (item.isFormField() && item.getFieldName().equals("nodeRef")) {
strNodeRef = item.getString();
} else {
strFilename = FilenameUtils.getName(item.getName());
file = TempFileProvider.createTempFile("alfresco", ".upload");
item.write(file);
}
}
if (logger.isDebugEnabled())
logger.debug("Ajax content update request: " + strFilename + " to nodeRef: " + strNodeRef + " return page: " + strReturnPage);
try {
if (file != null && strNodeRef != null && strNodeRef.length() != 0) {
NodeRef nodeRef = new NodeRef(strNodeRef);
if (nodeRef != null) {
ServiceRegistry services = Repository.getServiceRegistry(fc);
// get a writer for the content and put the file
ContentWriter writer = services.getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(file);
}
}
} catch (Exception e) {
strReturnPage = strReturnPage.replace("${UPLOAD_ERROR}", e.getMessage());
}
Document result = XMLUtil.newDocument();
Element htmlEl = result.createElement("html");
result.appendChild(htmlEl);
Element bodyEl = result.createElement("body");
htmlEl.appendChild(bodyEl);
Element scriptEl = result.createElement("script");
bodyEl.appendChild(scriptEl);
scriptEl.setAttribute("type", "text/javascript");
Node scriptText = result.createTextNode(strReturnPage);
scriptEl.appendChild(scriptText);
if (logger.isDebugEnabled())
logger.debug("Content update request complete.");
ResponseWriter out = fc.getResponseWriter();
XMLUtil.print(result, out);
}
use of javax.faces.context.ExternalContext in project wildfly by wildfly.
the class CountBeanViewScoped method invalidateGC.
public String invalidateGC() {
LOG.debug("Running View Scoped Garbage Collect, invalidate session so view will be destroyed");
System.gc();
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.invalidateSession();
return "";
}
use of javax.faces.context.ExternalContext in project deltaspike by apache.
the class JsfUtils method getViewConfigPageParameters.
public static Set<RequestParameter> getViewConfigPageParameters() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Set<RequestParameter> result = new HashSet<RequestParameter>();
if (// detection of early config for different mojarra versions
externalContext == null || externalContext.getRequestParameterValuesMap() == null || externalContext.getRequest() == null) {
return result;
}
NavigationParameterContext navigationParameterContext = BeanProvider.getContextualReference(NavigationParameterContext.class);
for (Map.Entry<String, String> entry : navigationParameterContext.getPageParameters().entrySet()) {
// TODO add multi-value support
result.add(new RequestParameter(entry.getKey(), new String[] { entry.getValue() }));
}
return result;
}
use of javax.faces.context.ExternalContext in project deltaspike by apache.
the class ClientWindowHelper method handleInitialRedirect.
/**
* Handles the initial redirect for the LAZY mode, if no windowId is available in the current request URL.
*
* @param facesContext the {@link FacesContext}
* @param newWindowId the new windowId
*/
public static void handleInitialRedirect(FacesContext facesContext, String newWindowId) {
// store the new windowId as context attribute to prevent infinite loops
// #sendRedirect will append the windowId (from ClientWindow#getWindowId again) to the redirectUrl
facesContext.getAttributes().put(INITIAL_REDIRECT_WINDOW_ID, newWindowId);
ExternalContext externalContext = facesContext.getExternalContext();
String url = constructRequestUrl(externalContext);
// remember the initial redirect windowId till the next request - see #729
addRequestWindowIdCookie(facesContext, newWindowId, newWindowId);
try {
externalContext.redirect(url);
} catch (IOException e) {
throw new FacesException("Could not send initial redirect!", e);
}
}
Aggregations