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