}
path = basePath + path;
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("Getting path", t.getElapsedTime());
LanguageVO masterLanguage = LanguageController.getController().getMasterLanguage(repositoryId, db);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getLatestSiteNodeVersionVO", t.getElapsedTime());
Integer metaInfoContentTypeDefinitionId = ContentTypeDefinitionController.getController().getContentTypeDefinitionVOWithName("Meta info", db).getId();
Integer availableServiceBindingId = AvailableServiceBindingController.getController().getAvailableServiceBindingVOWithName("Meta information", db).getId();
List serviceDefinitions = AvailableServiceBindingController.getController().getServiceDefinitionVOList(db, availableServiceBindingId);
if(serviceDefinitions == null || serviceDefinitions.size() == 0)
{
ServiceDefinition serviceDefinition = ServiceDefinitionController.getController().getServiceDefinitionWithName("Core content service", db, false);
String[] values = {serviceDefinition.getId().toString()};
AvailableServiceBindingController.getController().update(availableServiceBindingId, values, db);
}
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getAvailableServiceBindingVOWithName", t.getElapsedTime());
ContentVO rootContent = ContentControllerProxy.getController().getRootContentVO(db, repositoryId, principal.getName(), true);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getRootContentVO", t.getElapsedTime());
if(rootContent != null)
{
ContentVO parentFolderContent = ContentController.getContentController().getContentVOWithPath(repositoryId, path, true, principal, db);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("getContentVOWithPath", t.getElapsedTime());
ContentVO contentVO = new ContentVO();
contentVO.setCreatorName(principal.getName());
contentVO.setIsBranch(new Boolean(false));
contentVO.setName(newSiteNode.getName() + " Metainfo");
contentVO.setRepositoryId(repositoryId);
content = ContentControllerProxy.getController().create(db, parentFolderContent.getId(), metaInfoContentTypeDefinitionId, repositoryId, contentVO);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("content.create", t.getElapsedTime());
newSiteNode.setMetaInfoContentId(contentVO.getId());
LanguageVO masterLanguageVO = LanguageController.getController().getMasterLanguage(repositoryId, db);
String componentStructure = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><components></components>";
if(pageTemplateContentId != null)
{
ContentVersionVO contentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(pageTemplateContentId, masterLanguageVO.getId(), db);
componentStructure = ContentVersionController.getContentVersionController().getAttributeValue(contentVersionVO, "ComponentStructure", false);
Document document = XMLHelper.readDocumentFromByteArray(componentStructure.getBytes("UTF-8"));
String componentXPath = "//component";
NodeList componentNodes = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath);
for(int i=0; i < componentNodes.getLength(); i++)
{
Element element = (Element)componentNodes.item(i);
String componentId = element.getAttribute("id");
String componentContentId = element.getAttribute("contentId");
ComponentController.getController().checkAndAutoCreateContents(db, newSiteNode.getId(), masterLanguageVO.getId(), masterLanguageVO.getId(), null, new Integer(componentId), document, new Integer(componentContentId), principal);
componentStructure = XMLHelper.serializeDom(document, new StringBuffer()).toString();
}
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("meta info create 1", t.getElapsedTime());
}
List<LanguageVO> languageVOList = RepositoryLanguageController.getController().getLanguageVOListForRepositoryId(repositoryId, db);
for(LanguageVO languageVO : languageVOList)
{
//Create initial content version also... in languageVO
String versionValue = "<?xml version='1.0' encoding='UTF-8'?><article xmlns=\"x-schema:ArticleSchema.xml\"><attributes>";
if(metaAttributes == null || !metaAttributes.containsKey(languageVO.getLanguageCode() + "_Title"))
versionValue += "<Title><![CDATA[" + newSiteNode.getName() + "]]></Title>";
if(metaAttributes == null || !metaAttributes.containsKey(languageVO.getLanguageCode() + "_NavigationTitle"))
versionValue += "<NavigationTitle><![CDATA[" + newSiteNode.getName() + "]]></NavigationTitle>";
if(metaAttributes == null || !metaAttributes.containsKey(languageVO.getLanguageCode() + "_NiceURIName"))
versionValue += "<NiceURIName><![CDATA[" + new VisualFormatter().replaceNiceURINonAsciiWithSpecifiedChars(newSiteNode.getName(), CmsPropertyHandler.getNiceURIDefaultReplacementCharacter()) + "]]></NiceURIName>";
if(metaAttributes == null || !metaAttributes.containsKey(languageVO.getLanguageCode() + "_Description"))
versionValue += "<Description><![CDATA[" + newSiteNode.getName() + "]]></Description>";
if(metaAttributes == null || !metaAttributes.containsKey(languageVO.getLanguageCode() + "_MetaInfo"))
versionValue += "<MetaInfo><![CDATA[" + newSiteNode.getName() + "]]></MetaInfo>";
boolean saveVersion = false;
boolean realValue = false;
if(metaAttributes != null)
{
for(String metaAttributeName : metaAttributes.keySet())
{
if(metaAttributeName.startsWith(languageVO.getLanguageCode() + "_"))
{
versionValue += "<" + metaAttributeName.replaceFirst(languageVO.getLanguageCode() + "_", "") + "><![CDATA[" + metaAttributes.get(metaAttributeName) + "]]></" + metaAttributeName.replaceFirst(languageVO.getLanguageCode() + "_", "") + ">";
saveVersion = true;
realValue = true;
}
}
}
if(!realValue) //No other values
versionValue = "<?xml version='1.0' encoding='UTF-8'?><article xmlns=\"x-schema:ArticleSchema.xml\"><attributes>";
if(languageVO.getId().equals(masterLanguageVO.getId()))
{
versionValue += "<ComponentStructure><![CDATA[" + componentStructure + "]]></ComponentStructure>";
saveVersion = true;
}
versionValue += "</attributes></article>";
if(saveVersion)
{
ContentVersionVO contentVersionVO = new ContentVersionVO();
contentVersionVO.setVersionComment("Autogenerated version");
contentVersionVO.setVersionModifier(principal.getName());
contentVersionVO.setVersionValue(versionValue);
//ContentVersionController.getContentVersionController().create(contentVO.getId(), masterLanguage.getId(), contentVersionVO, null, db);
MediumContentVersionImpl contentVersionImpl = ContentVersionController.getContentVersionController().createMedium(contentVO.getId(), languageVO.getId(), contentVersionVO, db);
if(newContentVersions != null)
newContentVersions.add(contentVersionImpl);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("meta info create 2", t.getElapsedTime());
}
}
LanguageVO localMasterLanguageVO = getInitialLanguageVO(db, parentFolderContent.getId(), repositoryId);
//Also created a version in the local master language for this part of the site if any
/*
if(localMasterLanguageVO.getId().intValue() != masterLanguage.getId().intValue())
{
String versionValueLocalMaster = "<?xml version='1.0' encoding='UTF-8'?><article xmlns=\"x-schema:ArticleSchema.xml\"><attributes><Title><![CDATA[" + newSiteNode.getName() + "]]></Title><NavigationTitle><![CDATA[" + newSiteNode.getName() + "]]></NavigationTitle><NiceURIName><![CDATA[" + new VisualFormatter().replaceNiceURINonAsciiWithSpecifiedChars(newSiteNode.getName(), CmsPropertyHandler.getNiceURIDefaultReplacementCharacter()) + "]]></NiceURIName><Description><![CDATA[" + newSiteNode.getName() + "]]></Description><MetaInfo><![CDATA[" + newSiteNode.getName() + "]]></MetaInfo><ComponentStructure><![CDATA[]]></ComponentStructure></attributes></article>";
ContentVersionVO contentVersionVOLocalMaster = new ContentVersionVO();
contentVersionVOLocalMaster.setVersionComment("Autogenerated version");
contentVersionVOLocalMaster.setVersionModifier(principal.getName());
contentVersionVOLocalMaster.setVersionValue(versionValueLocalMaster);
//ContentVersionController.getContentVersionController().create(contentVO.getId(), localMasterLanguageVO.getId(), contentVersionVOLocalMaster, null, db);
MediumContentVersionImpl contentVersionImplLocal = ContentVersionController.getContentVersionController().createMedium(contentVO.getId(), localMasterLanguageVO.getId(), contentVersionVOLocalMaster, db);
if(newContentVersions != null)
newContentVersions.add(contentVersionImplLocal);
RequestAnalyser.getRequestAnalyser().registerComponentStatistics("meta info create 3", t.getElapsedTime());
}
*/
// If there is an old meta info content this is a copy action and we should take appropriate actions
if (oldMetaInfoContentVO != null)
{
List<ContentVersionVO> contentVersions = ContentVersionController.getContentVersionController().getContentVersionVOList(oldMetaInfoContentVO.getId(), db);
if (logger.isDebugEnabled())
{
StringBuilder sb = new StringBuilder();
sb.append("Copying ContentVersions to new Meta info. Old Content.id: " + oldMetaInfoContentVO.getContentId());
sb.append("\n\tNumber of contentVersions: " + contentVersions.size());
sb.append("\n\tSite master language.id: " + masterLanguage.getId());
sb.append("\n\tParent folder master language: " + localMasterLanguageVO.getId());
logger.debug(sb);
}
else
{
logger.info("Copying ContentVersions to new Meta info. Old Content.id: " + oldMetaInfoContentVO.getContentId());
}
for(ContentVersionVO cv : contentVersions)
{
logger.debug("cv " + cv.getLanguageId() + ":" + cv.getId());
if(!cv.getLanguageId().equals(masterLanguage.getId()) && !cv.getLanguageId().equals(localMasterLanguageVO.getId()))
{
logger.info("Should create version for content <" + contentVO.getId() + "> with language.id " + cv.getLanguageId());
String versionValueOtherVersion = cv.getVersionValue();
ContentVersionVO contentVersionVOLocalMaster = new ContentVersionVO();
contentVersionVOLocalMaster.setVersionComment("Autogenerated version");