Resource resource = context.getApplication().getResourceHandler().createResource( "dynamiccontent.properties", "primefaces", streamedContent.getContentType()); String resourcePath = resource.getRequestPath(); Map<String, Object> session = context.getExternalContext().getSessionMap(); Map<String, String> dynamicResourcesMapping = (Map) session.get(Constants.DYNAMIC_RESOURCES_MAPPING); if (dynamicResourcesMapping == null) { context.getELContext(), component.getValueExpression("value")); .append("&").append(Constants.DYNAMIC_CONTENT_TYPE_PARAM).append("=").append(type.toString()); for (int i = 0; i < component.getChildCount(); i++) { UIComponent child = component.getChildren().get(i); if (child instanceof UIParameter) { UIParameter param = (UIParameter) child; return context.getExternalContext().encodeResourceURL(src);
public static void addComponentResource(FacesContext context, String name, String library, String target) { Application application = context.getApplication(); UIComponent componentResource = application.createComponent(UIOutput.COMPONENT_TYPE); componentResource.setRendererType(application.getResourceHandler().getRendererTypeForResourceName(name)); componentResource.getAttributes().put("name", name); componentResource.getAttributes().put("library", library); componentResource.getAttributes().put("target", target); context.getViewRoot().addComponentResource(context, componentResource, target); }
private List<String> getResourceLibraryContracts(FacesContext context) { UIViewRoot viewRoot = context.getViewRoot(); if(viewRoot == null) { if(context.getApplication().getResourceHandler().isResourceRequest(context)) { // it is a resource request. look at the parameter con=. String param = context.getExternalContext().getRequestParameterMap().get("con"); if(!nameContainsForbiddenSequence(param) && param != null && param.trim().length() > 0) { return Arrays.asList(param); } } // PENDING(edburns): calculate the contracts! return Collections.emptyList(); } return context.getResourceLibraryContracts(); }
ResourceHandler handler = context.getApplication().getResourceHandler(); String resourceName = image.getName(); String value = image.getValue(); if (value != null && value.length() > 0) { if (resourceName != null && image.getLibrary() != null) { if (FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development)) { LOGGER.warning( "Please use either the 'value' attribute of b:image, or the 'name' and 'library' attribute pair. If all three attributes are provided, BootsFaces uses the 'value' attributes, ignoring both 'name' and 'library'."); if (handler.isResourceURL(value)) { return value; } else { value = context.getApplication().getViewHandler().getResourceURL(context, value); return (context.getExternalContext().encodeResourceURL(value)); Resource res = handler.createResource(resourceName, library); if (res == null) { if (context.isProjectStage(ProjectStage.Development)) { String msg = "Unable to find resource " + resourceName; FacesMessages.error(component.getClientId(context), msg, msg); return (context.getExternalContext().encodeResourceURL(res.getRequestPath()));
public static void writeScriptInline(FacesContext facesContext, ResponseWriter writer, String libraryName, String resourceName) throws IOException { if (!ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName)) { if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isRiImplAvailable()) { //Use more compatible way. UIComponent outputScript = facesContext.getApplication(). createComponent(facesContext, JAVAX_FACES_OUTPUT_COMPONENT_TYPE, DEFAULT_SCRIPT_RENDERER_TYPE); outputScript.getAttributes().put(JSFAttr.NAME_ATTR, resourceName); outputScript.getAttributes().put(JSFAttr.LIBRARY_ATTR, libraryName); outputScript.encodeAll(facesContext); } else { //Fast shortcut, don't create component instance and do what HtmlScriptRenderer do. Resource resource = facesContext.getApplication().getResourceHandler().createResource(resourceName, libraryName); markScriptAsRendered(facesContext, libraryName, resourceName); writer.startElement(HTML.SCRIPT_ELEM, null); writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT , null); writer.writeURIAttribute(HTML.SRC_ATTR, resource.getRequestPath(), null); writer.endElement(HTML.SCRIPT_ELEM); } } }
public static String getResourceRequestPath(FacesContext context, String resourceName) { Resource resource = context.getApplication().getResourceHandler().createResource(resourceName, "primefaces"); return resource.getRequestPath(); }
protected String getImageSrc(FacesContext context, GraphicImage image) throws Exception { String name = image.getName(); if (name != null) { String libName = image.getLibrary(); ResourceHandler handler = context.getApplication().getResourceHandler(); Resource res = handler.createResource(name, libName); if (res == null) { return "RES_NOT_FOUND"; } else { String requestPath = res.getRequestPath(); return context.getExternalContext().encodeResourceURL(requestPath); } } else { return DynamicContentSrcBuilder.build(context, image.getValue(), image, image.isCache(), DynamicContentType.STREAMED_CONTENT, image.isStream()); } } }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); Barcode barcode = (Barcode) component; String clientId = barcode.getClientId(context); Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent.properties", "primefaces", "image/png"); String resourcePath = resource.getRequestPath(); Map<String, Object> session = context.getExternalContext().getSessionMap(); Map<String, String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING); if (barcodeMapping == null) { writer.writeAttribute("src", context.getExternalContext().encodeResourceURL(src), null);
public void encodeScript(FacesContext context, UIComponent component, String name, String library) throws IOException { Map<Object, Object> contextMap = context.getAttributes(); Resource resource = context.getApplication().getResourceHandler() .createResource(name, library); ResponseWriter writer = context.getResponseWriter(); writer.startElement("script", component); writer.writeAttribute("type", "text/javascript", "type"); if (context.isProjectStage(ProjectStage.Development)) { String msg = "Unable to find resource " + (library == null ? "" : library + ", ") + name; context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, resourceSrc = resource.getRequestPath(); if (query != null) { resourceSrc = resourceSrc + query; resourceSrc = context.getExternalContext().encodeResourceURL(resourceSrc);
private static Resource createResource(FacesContext context) { if (Hacks.isPrimeFacesDynamicResourceRequest(context)) { return null; } String pathInfo = context.getExternalContext().getRequestPathInfo(); String resourceName = (pathInfo != null) ? pathInfo.substring(1) : ""; if (resourceName.isEmpty()) { return null; } String libraryName = context.getExternalContext().getRequestParameterMap().get("ln"); return context.getApplication().getResourceHandler().createResource(resourceName, libraryName); }
private boolean isResourceRequest() { FacesContext ctx = FacesContext.getCurrentInstance(); return (ctx.getApplication().getResourceHandler().isResourceRequest(ctx)); }
protected void writeJavascriptFile(FacesContext facesContext, UIComponent component, String JS_NAME, String JS_MIN_NAME, String JS_LIBRARY) throws IOException { ResponseWriter writer = facesContext.getResponseWriter(); String clientId = component.getClientId(facesContext); writer.startElement(HTML.SPAN_ELEM, null); writer.writeAttribute(HTML.ID_ATTR, clientId+"_libJS", HTML.ID_ATTR); writer.writeAttribute(HTML.CLASS_ATTR, "mobi-hidden", null); if (!isScriptLoaded(facesContext, JS_NAME)) { String jsFname = JS_NAME; if (facesContext.isProjectStage(ProjectStage.Production)){ jsFname = JS_MIN_NAME; } //set jsFname to min if development stage Resource jsFile = facesContext.getApplication().getResourceHandler().createResource(jsFname, JS_LIBRARY); String src = jsFile.getRequestPath(); writer.startElement("script", component); writer.writeAttribute("type", "text/javascript", null); writer.writeAttribute("src", src, null); writer.endElement("script"); setScriptLoaded(facesContext, JS_NAME); } writer.endElement(HTML.SPAN_ELEM); }
/** * Obtain the resource, construct a {@link Reader} around it using the character encoding as obtained from the * response writer and then invoke {@link #startElement(ResponseWriter, UIComponent)}, * {@link #writeResource(Reader, ResponseWriter)} and {@link #endElement(ResponseWriter)} in sequence. */ @Override public void encodeChildren(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); String name = (String) component.getAttributes().get("name"); String library = (String) component.getAttributes().get("library"); Resource resource = context.getApplication().getResourceHandler().createResource(name, library); startElement(writer, component); try (Reader reader = new InputStreamReader(resource.getInputStream(), writer.getCharacterEncoding())) { writeResource(reader, writer); } endElement(writer); }
private void renderComponentResources(FacesContext context, UIViewRoot viewRoot) throws IOException { ResourceHandler resourceHandler = context.getApplication().getResourceHandler(); PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); boolean updateStarted = false; for (UIComponent resource : viewRoot.getComponentResources(context)) { String name = (String) resource.getAttributes().get("name"); String library = (String) resource.getAttributes().get("library"); if (resource.getChildCount() == 0 && resourceHandler.getRendererTypeForResourceName(name) != null && !resourceHandler.isResourceRendered(context, name, library)) { if (!updateStarted) { writer.startUpdate("javax.faces.Resource"); updateStarted = true; } resource.encodeAll(context); } } if (updateStarted) { writer.endUpdate(); } }
public boolean containsNamespace(String ns) { if (ns != null && ns.startsWith(NAMESPACE_PREFIX)) { ResourceHandler resourceHandler = FacesContext.getCurrentInstance().getApplication().getResourceHandler(); if (ns.length() > NAMESPACE_PREFIX.length()) { String libraryName = ns.substring(NAMESPACE_PREFIX.length()); return resourceHandler.libraryExists(libraryName); } } return false; }
@Override public URL resolveUrl(String path) { ViewResource faceletResource = resourceHandler.createViewResource(FacesContext.getCurrentInstance(), path); if (faceletResource != null) { return faceletResource.getURL(); } return null; }
public String getRendererType(FacesContext context) { ResourceHandler resourceHandler = context.getApplication().getResourceHandler(); return resourceHandler.getRendererTypeForResourceName(getName()); }
protected void handleJSF2ResourceRequest(FacesContext facesContext) throws IOException { ResourceHandler resourceHandler = facesContext.getApplication().getResourceHandler(); resourceHandler.handleResourceRequest(facesContext); }
Application application = facesContext.getApplication(); ResourceHandler resourceHandler = application.getResourceHandler(); resource = resourceHandler.createResource(resourceName, resourceLibrary); resource = resourceHandler.createResource(resourceName);
public boolean isResourceRequest(FacesContext context) { EnvUtils.createSessionOnPageLoad(context); if (EnvUtils.isSessionInvalid(context)) { //make sure dispose window requests are treated as submit requests even if the session has expired if (WindowScopeManager.isDisposeWindowRequest(context.getExternalContext().getRequestParameterMap())) { return false; } else { return getWrapped().isResourceRequest(context); } } else { return isSessionAwareResourceRequest(context); } }