private List createContents(Content content, Map idMap, Map contentTypeDefinitionIdMap, List allContents, Collection contentTypeDefinitions, Map categoryIdMap, int version, Database db, String onlyLatestVersions, boolean isCopyAction, Map<String,String> replaceMap) throws Exception
{
//logger.info("createContents:" + content.getName() + ":" + content.getId());
ContentTypeDefinition contentTypeDefinition = null;
Integer originalContentId = content.getContentId();
if(version == 2)
{
Integer contentTypeDefinitionId = ((ContentImpl)content).getContentTypeDefinitionId();
if(contentTypeDefinitionId != null)
{
if(!isCopyAction)
{
if(contentTypeDefinitionIdMap.containsKey(contentTypeDefinitionId))
contentTypeDefinitionId = (Integer)contentTypeDefinitionIdMap.get(contentTypeDefinitionId);
ContentTypeDefinition originalContentTypeDefinition = null;
Iterator contentTypeDefinitionsIterator = contentTypeDefinitions.iterator();
while(contentTypeDefinitionsIterator.hasNext())
{
ContentTypeDefinition contentTypeDefinitionCandidate = (ContentTypeDefinition)contentTypeDefinitionsIterator.next();
if(contentTypeDefinitionCandidate.getId().intValue() == contentTypeDefinitionId.intValue())
{
originalContentTypeDefinition = contentTypeDefinitionCandidate;
break;
}
}
if(originalContentTypeDefinition != null)
{
contentTypeDefinition = ContentTypeDefinitionController.getController().getContentTypeDefinitionWithName(originalContentTypeDefinition.getName(), db);
if(contentTypeDefinition == null)
{
Integer before = originalContentTypeDefinition.getId();
db.create(originalContentTypeDefinition);
contentTypeDefinition = originalContentTypeDefinition;
Integer after = originalContentTypeDefinition.getId();
contentTypeDefinitionIdMap.put(before, after);
}
content.setContentTypeDefinition((ContentTypeDefinitionImpl)contentTypeDefinition);
}
else
{
logger.error("The content " + content.getName() + " had a content type not found amongst the listed ones:" + contentTypeDefinitionId);
}
}
else
{
contentTypeDefinition = ContentTypeDefinitionController.getController().getContentTypeDefinitionWithId(contentTypeDefinitionId, db);
content.setContentTypeDefinition((ContentTypeDefinitionImpl)contentTypeDefinition);
}
}
else
logger.warn("The content " + content.getName() + " had no content type at all");
}
else if(version == 1)
{
ContentTypeDefinition originalContentTypeDefinition = content.getContentTypeDefinition();
if(originalContentTypeDefinition != null)
{
contentTypeDefinition = ContentTypeDefinitionController.getController().getContentTypeDefinitionWithName(originalContentTypeDefinition.getName(), db);
if(contentTypeDefinition == null)
{
db.create(originalContentTypeDefinition);
contentTypeDefinition = originalContentTypeDefinition;
}