logger.info("org contentVersions:" + contentVersions.size());
List selectedContentVersions = new ArrayList();
Iterator realContentVersionsIterator = contentVersions.iterator();
while(realContentVersionsIterator.hasNext())
{
ContentVersion contentVersion = (ContentVersion)realContentVersionsIterator.next();
Iterator selectedContentVersionsIterator = selectedContentVersions.iterator();
boolean addLanguageVersion = true;
boolean noLanguageVersionFound = true;
while(selectedContentVersionsIterator.hasNext())
{
ContentVersion currentContentVersion = (ContentVersion)selectedContentVersionsIterator.next();
logger.info("" + currentContentVersion.getLanguage().getLanguageCode() + "=" + contentVersion.getLanguage().getLanguageCode());
if(currentContentVersion.getLanguage().getLanguageCode().equals(contentVersion.getLanguage().getLanguageCode()))
{
noLanguageVersionFound = false;
logger.info("" + contentVersion.getIsActive() + "=" + contentVersion.getLanguage().getLanguageCode());
if(contentVersion.getIsActive().booleanValue() && contentVersion.getContentVersionId().intValue() > currentContentVersion.getContentVersionId().intValue())
{
logger.info("A later version was found... removing this one..");
selectedContentVersionsIterator.remove();
addLanguageVersion = true;
}
}
}
if(addLanguageVersion || noLanguageVersionFound)
selectedContentVersions.add(contentVersion);
}
contentVersions = selectedContentVersions;
}
Iterator contentVersionIterator = contentVersions.iterator();
while(contentVersionIterator.hasNext())
{
ContentVersion contentVersion = (ContentVersion)contentVersionIterator.next();
String contentVersionValue = contentVersion.getVersionValue();
Iterator<String> replaceMapIterator = replaceMap.keySet().iterator();
while(replaceMapIterator.hasNext())
{
String key = replaceMapIterator.next();
String value = (String)replaceMap.get(key);
contentVersionValue = contentVersionValue.replaceAll(key, value);
}
contentVersionValue = contentVersionValue.replaceAll("contentId=\"", "contentId=\"oldContentId_");
contentVersionValue = contentVersionValue.replaceAll("\\?contentId=", "\\?contentId=oldContentId_");
contentVersionValue = contentVersionValue.replaceAll("getInlineAssetUrl\\(", "getInlineAssetUrl\\(oldContentId_");
contentVersionValue = contentVersionValue.replaceAll("languageId,", "languageId,oldContentId_");
contentVersionValue = contentVersionValue.replaceAll("entity=\"Content\" entityId=\"", "entity=\"Content\" entityId=\"oldContentId_");
//contentVersionValue = contentVersionValue.replaceAll("entity='Content'><id>", "entity='Content'><id>oldContentId_");
contentVersionValue = contentVersionValue.replaceAll("siteNodeId=\"", "siteNodeId=\"oldSiteNodeId_");
contentVersionValue = contentVersionValue.replaceAll("detailSiteNodeId=\"", "detailSiteNodeId=\"oldSiteNodeId_");
contentVersionValue = contentVersionValue.replaceAll("getPageUrl\\((\\d)", "getPageUrl\\(oldSiteNodeId_$1");
contentVersionValue = contentVersionValue.replaceAll("entity=\"SiteNode\" entityId=\"", "entity=\"SiteNode\" entityId=\"oldSiteNodeId_");
//contentVersionValue = contentVersionValue.replaceAll("entity='SiteNode'><id>", "entity='SiteNode'><id>old_");
contentVersionValue = this.prepareAllRelations(contentVersionValue);
//logger.info("contentVersionValue before:" + contentVersionValue);
Iterator contentIdMapIterator = contentIdMap.keySet().iterator();
while (contentIdMapIterator.hasNext())
{
String oldContentId = (String)contentIdMapIterator.next();
String newContentId = (String)contentIdMap.get(oldContentId);
//logger.info("Replacing all:" + oldContentId + " with " + newContentId);
contentVersionValue = contentVersionValue.replaceAll("contentId=\"oldContentId_" + oldContentId + "\"", "contentId=\"" + newContentId + "\"");
contentVersionValue = contentVersionValue.replaceAll("\\?contentId=oldContentId_" + oldContentId + "&", "\\?contentId=" + newContentId + "&");
contentVersionValue = contentVersionValue.replaceAll("getInlineAssetUrl\\(oldContentId_" + oldContentId + ",", "getInlineAssetUrl\\(" + newContentId + ",");
contentVersionValue = contentVersionValue.replaceAll("languageId,oldContentId_" + oldContentId + "\\)", "languageId," + newContentId + "\\)");
contentVersionValue = contentVersionValue.replaceAll("entity=\"Content\" entityId=\"oldContentId_" + oldContentId + "\"", "entity=\"Content\" entityId=\"" + newContentId + "\"");
contentVersionValue = contentVersionValue.replaceAll("<id>oldContentId_" + oldContentId + "</id>", "<id>" + newContentId + "</id>");
//contentVersionValue = contentVersionValue.replaceAll("entity='Content'><id>old_" + oldContentId + "</id>", "entity='Content'><id>" + newContentId + "</id>");
//contentVersionValue = contentVersionValue.replaceAll("<id>" + oldContentId + "</id>", "<id>" + newContentId + "</id>");
}
Iterator siteNodeIdMapIterator = siteNodeIdMap.keySet().iterator();
while (siteNodeIdMapIterator.hasNext())
{
String oldSiteNodeId = (String)siteNodeIdMapIterator.next();
String newSiteNodeId = (String)siteNodeIdMap.get(oldSiteNodeId);
//logger.info("Replacing all:" + oldSiteNodeId + " with " + newSiteNodeId);
contentVersionValue = contentVersionValue.replaceAll("siteNodeId=\"oldSiteNodeId_" + oldSiteNodeId + "\"", "siteNodeId=\"" + newSiteNodeId + "\"");
contentVersionValue = contentVersionValue.replaceAll("detailSiteNodeId=\"oldSiteNodeId_" + oldSiteNodeId + "\"", "detailSiteNodeId=\"" + newSiteNodeId + "\"");
contentVersionValue = contentVersionValue.replaceAll("getPageUrl\\(oldSiteNodeId_" + oldSiteNodeId + ",", "getPageUrl\\(" + newSiteNodeId + ",");
contentVersionValue = contentVersionValue.replaceAll("entity=\"SiteNode\" entityId=\"oldSiteNodeId_" + oldSiteNodeId + "\"", "entity=\"SiteNode\" entityId=\"" + newSiteNodeId + "\"");
//contentVersionValue = contentVersionValue.replaceAll("entity='SiteNode'><id>old_" + oldSiteNodeId + "</id>", "entity='SiteNode'><id>" + newSiteNodeId + "</id>");
contentVersionValue = contentVersionValue.replaceAll("<id>oldSiteNodeId_" + oldSiteNodeId + "</id>", "<id>" + newSiteNodeId + "</id>");
}
//logger.info("contentVersionValue after:" + contentVersionValue);
//Now replace all occurrances of old as they should never be there.
contentVersionValue = contentVersionValue.replaceAll("oldContentId_", "");
contentVersionValue = contentVersionValue.replaceAll("oldSiteNodeId_", "");
logger.info("new contentVersionValue:" + contentVersionValue);
contentVersion.setVersionValue(contentVersionValue);
}
}