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);
if (resource != null && !"RES_NOT_FOUND".equals(resource.toString())) { inputStream = resource.getInputStream(); contentType = resource.getContentType(); ExternalContext externalContext = context.getExternalContext(); File file = new File(externalContext.getRealPath("") + imagePath); inputStream = new FileInputStream(file);
@Override public String getResourceName() { return getWrapped().getResourceName(); }
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); } } }
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 static String getResourceRequestPath(FacesContext context, String resourceName) { Resource resource = context.getApplication().getResourceHandler().createResource(resourceName, "primefaces"); return resource.getRequestPath(); }
/** * 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); }
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); }
private void handleHeaders(FacesContext ctx, Resource resource) { ExternalContext extContext = ctx.getExternalContext(); for (Map.Entry<String, String> cur : resource.getResponseHeaders().entrySet()) { extContext.setResponseHeader(cur.getKey(), cur.getValue()); } }
public InputStream getInputStream() throws IOException { ArrayList<InputStream> streams = new ArrayList(); for (Info next : resourceInfos.resources) { ResourceHandler handler = FacesContext.getCurrentInstance().getApplication().getResourceHandler(); Resource resource = handler.createResource(next.name, next.library); streams.add(new SkipBOMInputStream(resource.getInputStream())); streams.add(new ByteArrayInputStream("\n\r".getBytes("UTF-8"))); } return new SequenceInputStream(Collections.enumeration(streams)); }
private Resource getDynamicResourceViaDummyFile(String actualResourceName){ FacesContext fc = FacesContext.getCurrentInstance(); ResourceHandler handler = fc.getApplication().getResourceHandler(); Resource rez = handler.createResource("coalesced.txt",getLibraryName(),getContentType()); rez.setResourceName(getResourceName()); return rez; }
private Resource createGraphicResourceByName(FacesContext context, String name, boolean dataURI) throws IOException { String library = (String) getAttributes().get("library"); Resource resource = context.getApplication().getResourceHandler().createResource(name, library); if (resource != null && dataURI && resource.getContentType().startsWith("image")) { resource = new GraphicResource(resource.getInputStream(), resource.getContentType()); } return resource; }
public void handleResourceRequest(FacesContext facesContext) throws IOException { ExternalContext externalContext = facesContext.getExternalContext(); if ( getTokenResource().getRequestPath().equals( getResourcePath(facesContext)) ) { storeParts(externalContext); externalContext.setResponseContentType("text/plain"); OutputStream out = externalContext.getResponseOutputStream(); out.write("handled by AuxUploadResourceHandler".getBytes()); return; } wrapped.handleResourceRequest(facesContext); }
private ResourceBundle findResourceBundleAsResource(FacesContext context) { if (getAttributes().containsKey(COMPONENT_RESOURCE_KEY)) { Resource ccResource = (Resource) this.getAttributes().get(COMPONENT_RESOURCE_KEY); if (ccResource != null) { ccResource = findComponentResourceBundleLocaleMatch(context, ccResource.getResourceName(), ccResource.getLibraryName()); if (ccResource != null) { try (InputStream propertiesInputStream = ccResource.getInputStream()) { return new PropertyResourceBundle(propertiesInputStream); } catch (IOException ex) { Logger.getLogger(UIComponent.class.getName()).log(SEVERE, null, ex); } } } } return null; }
private String getCompositeComponentName(UIComponent compositeComponent) { Resource resource = (Resource) compositeComponent.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY); String name = resource.getResourceName(); String library = resource.getLibraryName(); if (library != null) { return "Composite Component: " + name + ", library: " + library; } else { return "Composite Component: " + name; } }
VersionedResource(Resource wrapped) { this.wrapped = wrapped; //Not sure why this is necessary but if we don't do this, the //Content-Type response header may not make it back to the browser. setResourceName(wrapped.getResourceName()); setLibraryName(wrapped.getLibraryName()); setContentType(wrapped.getContentType()); }
public void initialize(Resource resource) throws IOException { setResourceName(resource.getResourceName()); setContentType(resource.getContentType()); this.headers = resource.getResponseHeaders(); initializeFromHeaders(); this.content = readContent(resource.getInputStream()); }
/** * <p class="changed_added_2_0">The default behavior of this method * is to call {@link Resource#userAgentNeedsUpdate} on the wrapped {@link * ResourceHandler} object.</p> */ @Override public boolean userAgentNeedsUpdate(FacesContext context) { return getWrapped().userAgentNeedsUpdate(context); }