Search in sources :

Example 1 with ResourceHandler

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

the class VideoBacking method getEncodedMp4ResourceURL.

public String getEncodedMp4ResourceURL() throws UnsupportedEncodingException {
    if (encodedMp4ResourceURL == null) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ResourceHandler resourceHandler = application.getResourceHandler();
        Resource mp3AudioResource = resourceHandler.createResource("over-the-rainbow.mp4", "videos");
        String requestPath = mp3AudioResource.getRequestPath();
        ExternalContext externalContext = facesContext.getExternalContext();
        String mp4ResourceURL = externalContext.encodeResourceURL(requestPath);
        encodedMp4ResourceURL = URLEncoder.encode(mp4ResourceURL, "UTF-8");
    }
    return encodedMp4ResourceURL;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource) FacesResource(com.liferay.faces.util.application.FacesResource) ResourceHandler(javax.faces.application.ResourceHandler) Application(javax.faces.application.Application)

Example 2 with ResourceHandler

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

the class AudioBacking method getEncodedMp3ResourceURL.

public String getEncodedMp3ResourceURL() throws UnsupportedEncodingException {
    if (encodedMp3ResourceURL == null) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ResourceHandler resourceHandler = application.getResourceHandler();
        Resource mp3AudioResource = resourceHandler.createResource("over-the-rainbow.mp3", "audios");
        String requestPath = mp3AudioResource.getRequestPath();
        ExternalContext externalContext = facesContext.getExternalContext();
        String mp3ResourceURL = externalContext.encodeResourceURL(requestPath);
        encodedMp3ResourceURL = URLEncoder.encode(mp3ResourceURL, "UTF-8");
    }
    return encodedMp3ResourceURL;
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource) FacesResource(com.liferay.faces.util.application.FacesResource) ResourceHandler(javax.faces.application.ResourceHandler) Application(javax.faces.application.Application)

Example 3 with ResourceHandler

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

the class AlloyResource method getRequestPath.

@Override
public String getRequestPath() {
    if (requestPath == null) {
        // In order to determine the request path, create a dummy resource that corresponds to an existing text file
        // in the classpath. This provides the ability to ask the JSF runtime for a request path that corresponds to
        // the existing file.
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ResourceHandler resourceHandlerChain = facesContext.getApplication().getResourceHandler();
        Resource dummyResource = resourceHandlerChain.createResource("dummy-resource.txt", getLibraryName());
        String dummyResourceRequestPath = dummyResource.getRequestPath();
        // Replace the dummy resource's name in the request path with the actual resource name.
        requestPath = dummyResourceRequestPath.replace("dummy-resource.txt", getResourceName());
    }
    return requestPath;
}
Also used : FacesContext(javax.faces.context.FacesContext) Resource(javax.faces.application.Resource) ResourceHandler(javax.faces.application.ResourceHandler)

Example 4 with ResourceHandler

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

the class ComboResource method getInputStream.

@Override
public InputStream getInputStream() throws IOException {
    StringBuilder comboResourceText = new StringBuilder();
    String contentType = getContentType();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ResourceHandler resourceHandlerChain = facesContext.getApplication().getResourceHandler();
    ExternalContext externalContext = facesContext.getExternalContext();
    for (String modulePath : modulePaths) {
        String resourcePath = RESOURCE_PATH_BASE + modulePath;
        URL resourceURL = getClass().getClassLoader().getResource(resourcePath);
        String resourceText;
        if (resourceURL != null) {
            logger.debug("resourcePath=[{0}] resourceURL=[{1}]", resourcePath, resourceURL);
            InputStream inputStream = resourceURL.openStream();
            resourceText = ResourceUtil.toString(inputStream, "UTF-8", 1024);
        } else {
            throw new IOException("resourceURL cannot be null");
        }
        if ("text/css".equals(contentType)) {
            resourceText = ExpressionUtil.filterResourceExpressions(resourceText, resourceHandlerChain, externalContext);
        }
        comboResourceText.append(resourceText);
    }
    return ResourceUtil.toInputStream(comboResourceText.toString(), "UTF-8");
}
Also used : FacesContext(javax.faces.context.FacesContext) ExternalContext(javax.faces.context.ExternalContext) InputStream(java.io.InputStream) ResourceHandler(javax.faces.application.ResourceHandler) IOException(java.io.IOException) URL(java.net.URL)

Example 5 with ResourceHandler

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

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