Search in sources :

Example 6 with ResourceHandler

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

the class BridgePhaseCompat_2_0_Impl method handleJSF2ResourceRequest.

protected void handleJSF2ResourceRequest(FacesContext facesContext) throws IOException {
    ResourceHandler resourceHandler = facesContext.getApplication().getResourceHandler();
    resourceHandler.handleResourceRequest(facesContext);
}
Also used : ResourceHandler(javax.faces.application.ResourceHandler)

Example 7 with ResourceHandler

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

the class ApplicationPrimeFacesHeadImpl method getResourceHandler.

@Override
public ResourceHandler getResourceHandler() {
    ResourceHandler resourceHandler = super.getResourceHandler();
    // request path, not an encoded resourceURL.
    if (resourceHandler instanceof ResourceHandlerOuterImpl) {
        ResourceHandlerWrapper resourceHandlerWrapper = (ResourceHandlerOuterImpl) resourceHandler;
        resourceHandler = resourceHandlerWrapper.getWrapped();
    }
    return resourceHandler;
}
Also used : ResourceHandlerOuterImpl(com.liferay.faces.bridge.application.internal.ResourceHandlerOuterImpl) ResourceHandlerWrapper(javax.faces.application.ResourceHandlerWrapper) ResourceHandler(javax.faces.application.ResourceHandler)

Example 8 with ResourceHandler

use of javax.faces.application.ResourceHandler 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)

Example 9 with ResourceHandler

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

the class ImageCropperRenderer method getImageResource.

/**
 * Attempt to obtain the resource from the server by parsing the valueExpression of the image attribute. Returns null
 * if the valueExpression is not of the form #{resource['path/to/resource']} or #{resource['library:name']}. Otherwise
 * returns the value obtained by ResourceHandler.createResource().
 */
private Resource getImageResource(FacesContext facesContext, ImageCropper imageCropper) {
    Resource resource = null;
    ValueExpression imageValueExpression = imageCropper.getValueExpression(ImageCropper.PropertyKeys.image.toString());
    if (imageValueExpression != null) {
        String imageValueExpressionString = imageValueExpression.getExpressionString();
        if (imageValueExpressionString.matches("^[#][{]resource\\['[^']+'\\][}]$")) {
            imageValueExpressionString = imageValueExpressionString.replaceFirst("^[#][{]resource\\['", "");
            imageValueExpressionString = imageValueExpressionString.replaceFirst("'\\][}]$", "");
            String resourceLibrary = null;
            String resourceName;
            String[] resourceInfo = imageValueExpressionString.split(":");
            if (resourceInfo.length == 2) {
                resourceLibrary = resourceInfo[0];
                resourceName = resourceInfo[1];
            } else {
                resourceName = resourceInfo[0];
            }
            if (resourceName != null) {
                Application application = facesContext.getApplication();
                ResourceHandler resourceHandler = application.getResourceHandler();
                if (resourceLibrary != null) {
                    resource = resourceHandler.createResource(resourceName, resourceLibrary);
                } else {
                    resource = resourceHandler.createResource(resourceName);
                }
            }
        }
    }
    return resource;
}
Also used : ValueExpression(javax.el.ValueExpression) Resource(javax.faces.application.Resource) ResourceHandler(javax.faces.application.ResourceHandler) Application(javax.faces.application.Application)

Example 10 with ResourceHandler

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

the class ResourceRichFacesCSSImpl method filter.

@Override
protected String filter(String cssText) {
    // Since the same image URL often appears more then once, maintain a cache of URLs for fast lookup.
    Map<String, String> resourceURLCache = new HashMap<String, String>();
    ResourceHandler resourceHandler = FacesContext.getCurrentInstance().getApplication().getResourceHandler();
    // For each of the RichFaces image resource types:
    for (RichFacesImageResource richFacesImageResource : RichFacesImageResource.values()) {
        // Parse the specified CSS text, and replace each relative URL with a ResourceURL.
        boolean doneProcessingURLs = false;
        while (!doneProcessingURLs) {
            String pathPrefix = richFacesImageResource.getPathPrefix();
            int urlStartPos = cssText.indexOf(pathPrefix);
            if (urlStartPos > 0) {
                int fileNameStartPos = urlStartPos + pathPrefix.length();
                int dotPos = cssText.indexOf(".", fileNameStartPos);
                if (dotPos > 0) {
                    boolean doneFindingExtension = false;
                    int extensionStartPos = dotPos + 1;
                    int extensionFinishPos = extensionStartPos;
                    while (!doneFindingExtension) {
                        if ((extensionFinishPos < cssText.length()) && Character.isLetterOrDigit(cssText.charAt(extensionFinishPos))) {
                            extensionFinishPos++;
                        } else {
                            doneFindingExtension = true;
                        }
                    }
                    String relativePathKey = cssText.substring(urlStartPos, extensionFinishPos);
                    String imageResourceURL = resourceURLCache.get(relativePathKey);
                    if (imageResourceURL == null) {
                        String resourceName = cssText.substring(fileNameStartPos, extensionFinishPos);
                        String libraryName = richFacesImageResource.getLibraryName();
                        String substitutionToken = richFacesImageResource.getSubstitutionToken();
                        Resource imageResource = resourceHandler.createResource(resourceName, libraryName);
                        imageResourceURL = imageResource.getRequestPath();
                        imageResourceURL = imageResourceURL.replaceAll(libraryName, substitutionToken);
                        resourceURLCache.put(relativePathKey, imageResourceURL);
                    }
                    StringBuilder buf = new StringBuilder();
                    buf.append(cssText.substring(0, urlStartPos));
                    buf.append(imageResourceURL);
                    buf.append(cssText.substring(extensionFinishPos));
                    cssText = buf.toString();
                } else {
                    logger.error("Unable to find image filename in URL");
                }
            } else {
                doneProcessingURLs = true;
            }
        }
    }
    for (RichFacesImageResource richFacesImageResource : RichFacesImageResource.values()) {
        cssText = cssText.replace(richFacesImageResource.getSubstitutionToken(), richFacesImageResource.getLibraryName());
    }
    return cssText;
}
Also used : HashMap(java.util.HashMap) Resource(javax.faces.application.Resource) ResourceHandler(javax.faces.application.ResourceHandler)

Aggregations

ResourceHandler (javax.faces.application.ResourceHandler)15 Resource (javax.faces.application.Resource)9 ExternalContext (javax.faces.context.ExternalContext)8 Application (javax.faces.application.Application)7 FacesContext (javax.faces.context.FacesContext)6 FacesResource (com.liferay.faces.util.application.FacesResource)4 UIComponent (javax.faces.component.UIComponent)2 ResponseWriter (javax.faces.context.ResponseWriter)2 Media (com.liferay.faces.alloy.component.media.Media)1 Video (com.liferay.faces.alloy.component.video.Video)1 ResourceHandlerOuterImpl (com.liferay.faces.bridge.application.internal.ResourceHandlerOuterImpl)1 ResourceComponent (com.liferay.faces.bridge.component.internal.ResourceComponent)1 InlineScript (com.liferay.faces.bridge.renderkit.html_basic.internal.InlineScript)1 BrowserSniffer (com.liferay.faces.util.client.BrowserSniffer)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1