*/
SiteNodeVO currentSiteNode = SiteNodeController.getController().getSmallSiteNodeVOWithId(deliveryContext.getSiteNodeId(), db);
if(!siteNode.getRepositoryId().equals(currentSiteNode.getRepositoryId()))
{
RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNode.getRepositoryId(), db);
String dnsName = repositoryVO.getDnsName();
logger.info("dnsName:" + dnsName + " for siteNode " + siteNode.getName());
// String operatingMode = CmsPropertyHandler.getOperatingMode();
String keyword = "";
if (operatingMode.equalsIgnoreCase("0"))
{
keyword = "working=";
}
else if (operatingMode.equalsIgnoreCase("2"))
{
keyword = "preview=";
}
if (operatingMode.equalsIgnoreCase("3"))
{
keyword = "live=";
}
String repositoryPath = null;
if (!operatingMode.equals("3"))
{
int workingPathStartIndex = dnsName.indexOf("workingPath=");
if(workingPathStartIndex != -1)
{
int workingPathEndIndex = dnsName.indexOf(",", workingPathStartIndex);
if(workingPathEndIndex > -1)
repositoryPath = dnsName.substring(workingPathStartIndex + 12, workingPathEndIndex);
else
repositoryPath = dnsName.substring(workingPathStartIndex + 12);
}
}
if(repositoryPath == null)
{
int pathStartIndex = dnsName.indexOf("path=");
if(pathStartIndex != -1)
{
int pathEndIndex = dnsName.indexOf(",", pathStartIndex);
if(pathEndIndex > -1)
repositoryPath = dnsName.substring(pathStartIndex + 5, pathEndIndex);
else
repositoryPath = dnsName.substring(pathStartIndex + 5);
}
}
if(logger.isInfoEnabled())
{
logger.info("repositoryPath in constructing new url:" + repositoryPath);
logger.info("dnsName:" + dnsName);
logger.info("repositoryPath:" + repositoryPath);
}
if(dnsName != null)
{
int startIndex = dnsName.indexOf(keyword);
if(startIndex != -1)
{
int endIndex = dnsName.indexOf(",", startIndex);
if(endIndex > -1)
dnsName = dnsName.substring(startIndex, endIndex);
else
dnsName = dnsName.substring(startIndex);
dnsName = dnsName.split("=")[1];
}
else
{
int endIndex = dnsName.indexOf(",");
if(endIndex > -1)
dnsName = dnsName.substring(0, endIndex);
else
dnsName = dnsName.substring(0);
}
}
if(logger.isInfoEnabled())
{
logger.info("A4:" + dnsName);
}
if(schema != null && schema.equalsIgnoreCase("https"))
{
dnsName = dnsName.replaceFirst(unprotectedProtocolName + "://", protectedProtocolName + "://").replaceFirst(unprotectedProtocolPort, protectedProtocolPort);
}
if(logger.isInfoEnabled())
{
logger.info("A42:" + dnsName);
}
if(repositoryPath != null)
{
if(applicationContext.startsWith("/"))
applicationContext = dnsName + applicationContext + "/" + repositoryPath;
else
applicationContext = dnsName + "/" + (applicationContext.equals("") ? "" : applicationContext + "/") + repositoryPath;
}
else
{
if(applicationContext.startsWith("/"))
applicationContext = dnsName + applicationContext;
else
applicationContext = dnsName + "/" + applicationContext;
}
if(logger.isInfoEnabled())
{
logger.info("A5:" + applicationContext);
}
}
else
{
RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNode.getRepositoryId(), db);
String dnsName = repositoryVO.getDnsName();
String repositoryPath = null;
if (!operatingMode.equals("3"))
{
int workingPathStartIndex = dnsName.indexOf("workingPath=");
if(workingPathStartIndex != -1)
{
int workingPathEndIndex = dnsName.indexOf(",", workingPathStartIndex);
if(workingPathEndIndex > -1)
repositoryPath = dnsName.substring(workingPathStartIndex + 12, workingPathEndIndex);
else
repositoryPath = dnsName.substring(workingPathStartIndex + 12);
}
}
if(repositoryPath == null)
{
int pathStartIndex = dnsName.indexOf("path=");
if(pathStartIndex != -1)
{
int pathEndIndex = dnsName.indexOf(",", pathStartIndex);
if(pathEndIndex > -1)
repositoryPath = dnsName.substring(pathStartIndex + 5, pathEndIndex);
else
repositoryPath = dnsName.substring(pathStartIndex + 5);
}
}
logger.info("repositoryPath in constructing new url:" + repositoryPath);
if(repositoryPath != null)
{
applicationContext = applicationContext + "/" + repositoryPath;
}
}
StringBuilder sb = new StringBuilder(256);
if ((deliveryContext.getUseFullUrl() || makeAccessBasedProtocolAdjustments) && applicationContext.indexOf("://") == -1)
{
String originalUrl;
if (request == null)
{
logger.info("Could not derive full base URL since we got no request. Getting value from DNS names instead.");
RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNode.getRepositoryId(), db);
originalUrl = getHost(repositoryVO.getDnsName(), operatingMode);
}
else
{
originalUrl = request.getRequestURL().toString();
}
if (originalUrl != null)
{
String base = originalUrl;
int indexOfProtocol = base.indexOf("://");
if (indexOfProtocol > -1)
{
indexOfProtocol += 3;
}
else
{
indexOfProtocol = 0;
}
int indexFirstSlash = originalUrl.indexOf("/", indexOfProtocol);
if (indexFirstSlash > -1)
{
base = originalUrl.substring(0, indexFirstSlash);
}
sb.append(base);
}
}
sb.append(applicationContext);
try
{
String navigationPath = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getPageNavigationPath(db, infoGluePrincipal, siteNodeId, languageId, contentId, deliveryContext);
if(navigationPath != null && navigationPath.startsWith("/") && sb.toString().endsWith("/"))
sb.append(navigationPath.substring(1));
else
sb.append(navigationPath);
if(sb.toString().endsWith(applicationContext) && !sb.toString().endsWith("/"))
{
sb.append("/");
}
boolean addedContent = false;
/*
if(contentId != null && contentId.intValue() != -1)
{
sb.append("?contentId=").append(String.valueOf(contentId));
addedContent = true;
}
*/
if(contentId != null && contentId.intValue() != -1)
{
if(!CmsPropertyHandler.getNiceURIDisableNiceURIForContent().equals("true"))
{
String navigationTitle = ContentDeliveryController.getContentDeliveryController().getContentAttribute(db, contentId, languageId, "NavigationTitle", siteNodeId, true, deliveryContext, infoGluePrincipal, false, false);
if(navigationTitle == null || navigationTitle.equals(""))
navigationTitle = ContentDeliveryController.getContentDeliveryController().getContentAttribute(db, contentId, languageId, "Title", siteNodeId, true, deliveryContext, infoGluePrincipal, false, false);
if(navigationTitle != null && !navigationTitle.equals(""))
{
navigationTitle = new VisualFormatter().replaceNiceURINonAsciiWithSpecifiedChars(navigationTitle, CmsPropertyHandler.getNiceURIDefaultReplacementCharacterForContent());
sb.append("/" + navigationTitle + ".cid").append(String.valueOf(contentId));
addedContent = true;
}
else
{
if(contentId != null && contentId.intValue() != -1)
{
sb.append("?contentId=").append(String.valueOf(contentId));
addedContent = true;
}
}
}
else
{
if(contentId != null && contentId.intValue() != -1)
{
sb.append("?contentId=").append(String.valueOf(contentId));
addedContent = true;
}
}
}
if(!enableNiceURIForLanguage.equalsIgnoreCase("true"))
{
if (languageId != null && languageId.intValue() != -1 && deliveryContext.getLanguageId().intValue() != languageId.intValue())
{
if(addedContent)
sb.append(getRequestArgumentDelimiter());
else
sb.append("?");
sb.append("languageId=").append(String.valueOf(languageId));
}
}
url = (!sb.toString().equals("") ? sb.toString() : "/");
}
catch (Exception e)
{
logger.warn("Error generating url:" + e.getMessage());
}
}
else
{
if(!useDNSNameInUrls.equalsIgnoreCase("false"))
{
if(siteNodeId == null)
siteNodeId = new Integer(-1);
if(languageId == null)
languageId = new Integer(-1);
if(contentId == null)
contentId = new Integer(-1);
String arguments = "siteNodeId=" + siteNodeId + getRequestArgumentDelimiter() + "languageId=" + languageId + getRequestArgumentDelimiter() + "contentId=" + contentId;
//SiteNode siteNode = SiteNodeController.getSiteNodeWithId(siteNodeId, db, true);
SiteNodeVO siteNode = SiteNodeController.getController().getSiteNodeVOWithId(siteNodeId, db);
String dnsName = CmsPropertyHandler.getWebServerAddress();
if(siteNode != null)
{
RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(siteNode.getRepositoryId(), db);
if(siteNode != null && repositoryVO.getDnsName() != null && !repositoryVO.getDnsName().equals(""))
dnsName = repositoryVO.getDnsName();
}
// String operatingMode = CmsPropertyHandler.getOperatingMode();
String keyword = "";
if(operatingMode.equalsIgnoreCase("0"))