Search in sources :

Example 11 with Resource

use of javax.faces.application.Resource in project liferay-faces-bridge-impl by liferay.

the class ResourceHandlerBridgeImpl method handleResourceRequest.

/**
 * This method handles the current request which is assumed to be a request for a {@link Resource}.
 */
@Override
public void handleResourceRequest(FacesContext facesContext) throws IOException {
    ExternalContext externalContext = facesContext.getExternalContext();
    Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
    String resourceName = requestParameterMap.get("javax.faces.resource");
    // resource to the response.
    if (resourceName != null) {
        String libraryName = requestParameterMap.get("ln");
        if (logger.isTraceEnabled()) {
            // Surround with isTraceEnabled check in order to avoid unnecessary creation of object array.
            logger.trace("Handling - resourceName=[{0}], libraryName[{1}]", resourceName, libraryName);
        }
        // FACES-57: Provide the opportunity for applications to decorate the createResource methods of this
        // class by delegating creation of the resource to the chain-of-responsibility found in the application's
        // ResourceHandler.
        ResourceHandler resourceHandlerChain = facesContext.getApplication().getResourceHandler();
        Resource resource;
        if (libraryName == null) {
            resource = resourceHandlerChain.createResource(resourceName);
        } else {
            resource = resourceHandlerChain.createResource(resourceName, libraryName);
        }
        handleResource(facesContext, externalContext, resource);
    } else {
        logger.debug("NOT HANDLED - Missing request parameter {0} so delegating handleResourceRequest to chain", "javax.faces.resource");
        getWrapped().handleResourceRequest(facesContext);
    }
}
Also used : ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource) ResourceHandler(javax.faces.application.ResourceHandler)

Example 12 with Resource

use of javax.faces.application.Resource in project liferay-faces-bridge-impl by liferay.

the class ResourceHandlerRichfacesImpl method createResource.

@Override
public Resource createResource(String resourceName) {
    Resource resource = super.createResource(resourceName);
    resource = createResource(resourceName, resource);
    return resource;
}
Also used : Resource(javax.faces.application.Resource)

Example 13 with Resource

use of javax.faces.application.Resource in project liferay-faces-bridge-impl by liferay.

the class ResourceHandlerOuterImpl method createResource.

@Override
public Resource createResource(String resourceName, String libraryName, String contentType) {
    Resource resource = super.createResource(resourceName, libraryName, contentType);
    resource = createResource(resource);
    return resource;
}
Also used : Resource(javax.faces.application.Resource)

Example 14 with Resource

use of javax.faces.application.Resource in project liferay-faces-bridge-ext by liferay.

the class JSResourceWithDisabledAMDLoaderImpl method getResourceId.

private String getResourceId() {
    Resource wrappedResource = getWrapped();
    String libraryName = wrappedResource.getLibraryName();
    String resourceName = wrappedResource.getResourceName();
    return ResourceUtil.getResourceId(libraryName, resourceName);
}
Also used : Resource(javax.faces.application.Resource)

Example 15 with Resource

use of javax.faces.application.Resource in project primefaces by primefaces.

the class GraphicImageRenderer method getImageSrc.

protected String getImageSrc(FacesContext context, GraphicImage image) {
    String name = image.getName();
    if (name != null) {
        String library = image.getLibrary();
        ResourceHandler handler = context.getApplication().getResourceHandler();
        Resource resource = handler.createResource(name, library);
        if (resource == null) {
            return "RES_NOT_FOUND";
        }
        if (image.isStream()) {
            String requestPath = resource.getRequestPath();
            return context.getExternalContext().encodeResourceURL(requestPath);
        } else {
            return ResourceUtils.toBase64(context, resource);
        }
    } else {
        return DynamicContentSrcBuilder.build(context, image, image.getValueExpression(GraphicImage.PropertyKeys.value.name()), new Lazy<>(() -> image.getValue()), image.isCache(), image.isStream());
    }
}
Also used : Resource(javax.faces.application.Resource) ResourceHandler(javax.faces.application.ResourceHandler)

Aggregations

Resource (javax.faces.application.Resource)27 ExternalContext (javax.faces.context.ExternalContext)10 ResourceHandler (javax.faces.application.ResourceHandler)9 FacesContext (javax.faces.context.FacesContext)7 FacesResource (com.liferay.faces.util.application.FacesResource)5 Application (javax.faces.application.Application)5 IOException (java.io.IOException)4 ResponseWriter (javax.faces.context.ResponseWriter)4 URL (java.net.URL)3 Collection (java.util.Collection)3 FacesException (javax.faces.FacesException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 LocalDateTime (java.time.LocalDateTime)2 ZoneId (java.time.ZoneId)2 ZonedDateTime (java.time.ZonedDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2