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