* @throws DotDataException
* @throws DotStateException
*/
public static String getPathFromCache(String URI, String hostId, Long languageId) throws DotStateException, DotDataException, DotSecurityException{
DotCacheAdministrator cache = CacheLocator.getCacheAdministrator();
if ( languageId == null ) {
languageId = APILocator.getLanguageAPI().getDefaultLanguage().getId();
}
String _uri = null;
try {
//First lets search in cache for a specific language
_uri = (String) cache.get( getPrimaryGroup() + hostId + ":" + URI, getPrimaryGroup() + "_" + hostId + "_" + languageId );
//If nothing found try without a language
if ( _uri == null ) {
_uri = (String) cache.get( getPrimaryGroup() + hostId + ":" + URI, getPrimaryGroup() + "_" + hostId );
}
} catch ( DotCacheException e ) {
Logger.debug( LiveCache.class, "Cache Entry not found", e );
}
if(_uri != null)
{
if(_uri.equals(WebKeys.Cache.CACHE_NOT_FOUND))
return null;
return _uri;
}
String ext = Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
if (URI.endsWith("/")) {
//it's a folder path, so I add index.{pages ext} at the end
URI += "index." + ext;
// try again with an index page this time
try{
_uri = (String) cache.get(getPrimaryGroup() + hostId + ":" + URI,getPrimaryGroup() + "_" + hostId);
}catch (DotCacheException e) {
Logger.debug(LiveCache.class,"Cache Entry not found", e);
}
if(_uri != null)
{
if(_uri.equals(WebKeys.Cache.CACHE_NOT_FOUND))
return null;
return _uri;
}
}
// lets try to lazy get it.
Host fake = new Host();
fake.setIdentifier(hostId);
Identifier id = APILocator.getIdentifierAPI().find( fake,URI);
if(!InodeUtils.isSet(id.getInode()))
{
cache.put(getPrimaryGroup() + hostId + ":" + URI, WebKeys.Cache.CACHE_NOT_FOUND, getPrimaryGroup() + "_" + hostId);
//it's a folder path, so I add index.html at the end
URI += "/index." + ext;
id = APILocator.getIdentifierAPI().find( fake, URI);
if(!InodeUtils.isSet(id.getInode()))
{
cache.put(getPrimaryGroup() + hostId + ":" + URI, WebKeys.Cache.CACHE_NOT_FOUND, getPrimaryGroup() + "_" + hostId);
return null;
}
}
Versionable asset;
if(id.getAssetType().equals("contentlet")){
User systemUser = APILocator.getUserAPI().getSystemUser();
try {
asset = APILocator.getContentletAPI().findContentletByIdentifier( id.getId(), true, languageId, systemUser, false );
} catch ( DotContentletStateException e ) {
Logger.debug( LiveCache.class, e.getMessage() );
//If we did not find the asset with for given language lets try with the default language
if ( !languageId.equals( APILocator.getLanguageAPI().getDefaultLanguage().getId() ) ) {
languageId = APILocator.getLanguageAPI().getDefaultLanguage().getId();
asset = APILocator.getContentletAPI().findContentletByIdentifier( id.getId(), true, languageId, systemUser, false );
} else {
throw e;
}
}
} else {
asset = APILocator.getVersionableAPI().findLiveVersion(id, APILocator.getUserAPI().getSystemUser(), false);
}
if(asset!=null && InodeUtils.isSet(asset.getInode()))
{
Logger.debug(PublishFactory.class, "Lazy Mapping: " + id.getURI() + " to " + URI);
//The cluster entry doesn't need to be invalidated when loading the entry lazily,
//if the entry gets invalidated from the cluster in this case causes an invalidation infinite loop
return addToLiveAssetToCache( asset, languageId );
} else {
//Identifier exists but the asset is not live
cache.put(getPrimaryGroup() + hostId + ":" + URI, WebKeys.Cache.CACHE_NOT_FOUND, getPrimaryGroup() + "_" + hostId);
return null;
}
}