}
final String localePrefix = getLocalePrefixForLocateResource(facesContext);
final List<String> contracts = facesContext.getResourceLibraryContracts();
String contractPreferred = getContractNameForLocateResource(facesContext);
ResourceValue resourceValue = null;
// Check cache:
//
// Contracts are on top of everything, because it is a concept that defines
// resources in a application scope concept. It means all resources in
// /resources or /META-INF/resources can be overriden using a contract. Note
// it also means resources under /META-INF/flows can also be overriden using
// a contract.
// Check first the preferred contract if any. If not found, try the remaining
// contracts and finally if not found try to found a resource without a
// contract name.
if (contractPreferred != null)
{
resourceValue = getResourceLoaderCache().getResource(
resourceName, libraryName, contentType, localePrefix, contractPreferred);
}
if (resourceValue == null && !contracts.isEmpty())
{
// Try to get resource but try with a contract name
for (String contract : contracts)
{
resourceValue = getResourceLoaderCache().getResource(
resourceName, libraryName, contentType, localePrefix, contract);
if (resourceValue != null)
{
break;
}
}
}
// Only if no contract preferred try without it.
if (resourceValue == null)
{
// Try to get resource without contract name
resourceValue = getResourceLoaderCache().getResource(resourceName, libraryName, contentType, localePrefix);
}
if(resourceValue != null)
{
resource = new ResourceImpl(resourceValue.getResourceMeta(), resourceValue.getResourceLoader(),
getResourceHandlerSupport(), contentType,
resourceValue.getCachedInfo() != null ? resourceValue.getCachedInfo().getURL() : null,
resourceValue.getCachedInfo() != null ? resourceValue.getCachedInfo().getRequestPath() : null);
}
else
{
boolean resolved = false;
// Try preferred contract first