Search in sources :

Example 6 with Resource

use of javax.faces.application.Resource 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 7 with Resource

use of javax.faces.application.Resource 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 8 with Resource

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

the class ExpressionUtil method filterResourceExpressions.

/* package-priavte */
static String filterResourceExpressions(String text, ResourceHandler resourceHandlerChain, ExternalContext externalContext) {
    int startPos = text.indexOf(RESOURCE_TOKEN_BEGIN);
    while (startPos > 0) {
        int finishPos = text.indexOf(RESOURCE_TOKEN_END, startPos);
        if (finishPos > 0) {
            String resourcePair = text.substring(startPos + RESOURCE_TOKEN_BEGIN.length(), finishPos);
            if (resourcePair.indexOf(":") > 0) {
                String[] resourceTokens = resourcePair.split(":");
                String libraryName = resourceTokens[0];
                String resourceName = resourceTokens[1];
                Resource resource = resourceHandlerChain.createResource(resourceName, libraryName);
                if (resource != null) {
                    String requestPath = resource.getRequestPath();
                    if (requestPath != null) {
                        String resourceURL = externalContext.encodeResourceURL(requestPath);
                        text = text.substring(0, startPos) + resourceURL + text.substring(finishPos + RESOURCE_TOKEN_END.length());
                    }
                }
            }
        }
        startPos = text.indexOf(RESOURCE_TOKEN_BEGIN);
    }
    return text;
}
Also used : Resource(javax.faces.application.Resource)

Example 9 with Resource

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

the class FilteredResourceExpressionImpl method getModulePathsDelimiter.

private String getModulePathsDelimiter(String resourceName, ResourceHandler resourceHandlerChain, ExternalContext externalContext) {
    String modulePathsDelimiter = "&";
    Resource resource = resourceHandlerChain.createResource(resourceName, ResLibResourceHandler.LIBRARY_NAME);
    if (resource != null) {
        String requestPath = resource.getRequestPath();
        if (requestPath != null) {
            String resourceURL = externalContext.encodeResourceURL(requestPath);
            if (!resourceURL.contains("?")) {
                modulePathsDelimiter = "?";
            }
        }
    }
    return modulePathsDelimiter;
}
Also used : Resource(javax.faces.application.Resource)

Example 10 with Resource

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

the class ResLibResourceHandler method createResource.

@Override
public Resource createResource(String resourceName, String libraryName) {
    Resource resource;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (!isLiferayPortalDetected(facesContext) && LIBRARY_NAME.equals(libraryName)) {
        if ("combo".equals(resourceName) || "script".equals(resourceName)) {
            resource = createResource(resourceName);
        } else {
            resource = super.createResource(resourceName, libraryName);
            if (LIFERAY_JS.equals(resourceName)) {
                resource = new FilteredResourceExpressionImpl(resource);
            }
        }
    } else {
        resource = super.createResource(resourceName, libraryName);
    }
    return resource;
}
Also used : FacesContext(javax.faces.context.FacesContext) Resource(javax.faces.application.Resource)

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