public static Integer getSiteNodeIdFromPath(Database db, InfoGluePrincipal infogluePrincipal, RepositoryVO repositoryVO, String[] path, String attributeName, DeliveryContext deliveryContext, HttpSession session, Integer languageId) throws SystemException, Exception
{
Integer siteNodeId = null;
URIMapperCache uriCache = URIMapperCache.getInstance();
int numberOfPaths = path.length;
while (numberOfPaths >= 0)
{
//logger.info("Looking for cached nodeName at index "+idx);
siteNodeId = uriCache.getCachedSiteNodeId(repositoryVO.getId(), path, numberOfPaths);
if (siteNodeId != null)
break;
numberOfPaths = numberOfPaths - 1;
}
String repositoryPath = null;
boolean noHostStated = true;
if(!CmsPropertyHandler.getOperatingMode().equals("3"))
{
int workingPathStartIndex = repositoryVO.getDnsName().indexOf("workingPath=");
if(workingPathStartIndex != -1)
{
int workingPathEndIndex = repositoryVO.getDnsName().indexOf(",", workingPathStartIndex);
if(workingPathEndIndex > -1)
repositoryPath = repositoryVO.getDnsName().substring(workingPathStartIndex + 12, workingPathEndIndex);
else
repositoryPath = repositoryVO.getDnsName().substring(workingPathStartIndex + 12);
}
if(repositoryVO.getDnsName().indexOf("working=") > -1)
noHostStated = false;
}
if(repositoryPath == null)
{
int pathStartIndex = repositoryVO.getDnsName().indexOf("path=");
if(pathStartIndex != -1)
{
int pathEndIndex = repositoryVO.getDnsName().indexOf(",", pathStartIndex);
if(pathEndIndex > -1)
repositoryPath = repositoryVO.getDnsName().substring(pathStartIndex + 5, pathEndIndex);
else
repositoryPath = repositoryVO.getDnsName().substring(pathStartIndex + 5);
}
if(repositoryVO.getDnsName().indexOf("live=") > -1 || repositoryVO.getDnsName().indexOf("preview=") > -1)
noHostStated = false;
}
if(logger.isInfoEnabled())
{
logger.info("repositoryPath:" + repositoryPath);
logger.info("path:" + path.length);
}
if(repositoryPath == null && noHostStated)
{
if(logger.isInfoEnabled())
logger.info("The repo " + repositoryVO.getName() + " seems corrupt so this repository should be excluded.");
return null;
}
if(repositoryPath != null && path.length <= 0)
{
if(logger.isInfoEnabled())
logger.info("There was a repository path:" + repositoryPath + " but the path.length was " + path.length + " so this repository should be excluded.");
return null;
}
if(repositoryPath != null && path.length > 0)
{
String[] repositoryPaths = repositoryPath.split("/");
for(int i=0; i<repositoryPaths.length; i++)
{
String repositoryPathPart = repositoryPaths[i];
if(path.length <= i)
{
logger.error("Could not match the repository paths so this repository should be excluded.");
return null;
}
String pathPart = path[i];
if(logger.isInfoEnabled())
{
logger.info("repositoryPathPart:" + repositoryPathPart);
logger.info("pathPart:" + pathPart);
}
if(!repositoryPathPart.equalsIgnoreCase(pathPart))
{
if(logger.isInfoEnabled())
logger.info("Could not match the repository paths so this repository should be excluded.");
return null;
}
}
}
if(repositoryPath != null && path.length > 0)
{
String[] repositoryPaths = repositoryPath.split("/");
String[] newPath = path;
if(logger.isInfoEnabled())
{
logger.info("repositoryPaths:" + repositoryPaths.length);
logger.info("newPath:" + newPath.length);
}
for(int repPathIndex = 0; repPathIndex < repositoryPaths.length; repPathIndex++)
{
String repPath = repositoryPaths[repPathIndex];
if(logger.isInfoEnabled())
logger.info("repPath:" + repPath);
if(path.length > repPathIndex)
{
if(logger.isInfoEnabled())
logger.info("path:" + path[repPathIndex]);
if(path[repPathIndex].equals(repPath))
{
String[] tempNewPath = new String[newPath.length - 1];
for(int i=1; i<newPath.length; i++)
tempNewPath[i-1] = newPath[i];
newPath = tempNewPath;
}
}
}
path = newPath;
}
if(logger.isInfoEnabled())
{
logger.info("new path:" + path.length);
logger.info("numberOfPaths = "+numberOfPaths);
}
String enableNiceURIForLanguage = CmsPropertyHandler.getEnableNiceURIForLanguage();
if((enableNiceURIForLanguage == null || !enableNiceURIForLanguage.equals("false")) && path.length > 0 && path[0].length() == 2)
{
LanguageVO language = LanguageDeliveryController.getLanguageDeliveryController().getLanguageWithCode(db, path[0].toLowerCase());
if(language != null)
enableNiceURIForLanguage = "true";
}
//logger.info("enableNiceURIForLanguage:" + enableNiceURIForLanguage);
//logger.info("numberOfPaths:" + numberOfPaths);
if(enableNiceURIForLanguage.equalsIgnoreCase("true") && path.length > 0)
{
//logger.info("path[numberOfPaths]:" + path[numberOfPaths]);
//logger.info("path[0]:" + path[0]);
LanguageVO language = LanguageDeliveryController.getLanguageDeliveryController().getLanguageWithCode(db, path[0].toLowerCase());
//logger.info("language:" + language);
if(language != null)
{
//logger.info("YES - we should consider the first node as a language:" + language);
session.setAttribute(FilterConstants.LANGUAGE_ID, language.getId());
deliveryContext.setLanguageId(language.getId());
languageId = language.getId();
String[] tempNewPath = new String[path.length - 1];
for(int i=1; i<path.length; i++)
tempNewPath[i-1] = path[i];
path = tempNewPath;
}
}
for (int i = numberOfPaths;i < path.length; i++)
{
if (i < 0)
{
if(logger.isInfoEnabled())
logger.info("Getting root node");
siteNodeId = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNodeId(db, infogluePrincipal, repositoryVO.getId(), null, attributeName, null, languageId, deliveryContext);
}
else
{
if(logger.isInfoEnabled())
logger.info("Getting normal");
siteNodeId = NodeDeliveryController.getNodeDeliveryController(null, deliveryContext.getLanguageId(), null, deliveryContext).getSiteNodeId(db, infogluePrincipal, repositoryVO.getId(), path[i], attributeName, siteNodeId, languageId, deliveryContext);
}
if (siteNodeId != null)
uriCache.addCachedSiteNodeId(repositoryVO.getId(), path, i+1, siteNodeId);
}
return siteNodeId;
}