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;
}
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;
}
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;
}
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");
}
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);
}
}
Aggregations