String componentStructure = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><components></components>";
ContentVO metaInfoContentVO = ContentController.getContentController().getContentVOWithId(this.contentId);
Integer originalMetaInfoMasterLanguageId = LanguageController.getController().getMasterLanguage(metaInfoContentVO.getRepositoryId()).getId();
Integer destinationMasterLanguageId = LanguageController.getController().getMasterLanguage(this.repositoryId).getId();
ContentVersionVO originalContentVersionVO = ContentVersionController.getContentVersionController().getLatestActiveContentVersionVO(this.contentId, originalMetaInfoMasterLanguageId);
logger.info("originalMetaInfoMasterLanguageId:" + originalMetaInfoMasterLanguageId);
logger.info("contentId:" + contentId);
logger.info("originalContentVersionVO:" + originalContentVersionVO);
componentStructure = ContentVersionController.getContentVersionController().getAttributeValue(originalContentVersionVO.getId(), "ComponentStructure", false);
logger.info("componentStructure:" + componentStructure);
if(componentId != null)
{
logger.info("We should strip all but componentId:" + componentId);
Document document = XMLHelper.readDocumentFromByteArray(componentStructure.getBytes("UTF-8"));
String componentXPath = "//component[@id=" + componentId + "]";
Node node = org.apache.xpath.XPathAPI.selectSingleNode(document.getDocumentElement(), componentXPath);
if(node != null)
{
Element component = (Element)node;
component.setAttribute("pagePartTemplateContentId", "-1");
component.setAttribute("isInherited", "true");
String modifiedXML = XMLHelper.serializeDom(component, new StringBuffer()).toString();
logger.info("modifiedXML:" + modifiedXML);
componentStructure = "<?xml version='1.0' encoding='UTF-8'?><components>" + modifiedXML + "</components>";
}
}
//Create initial content version also... in masterlanguage
String versionValue = "<?xml version='1.0' encoding='UTF-8'?><article xmlns=\"x-schema:ArticleSchema.xml\"><attributes><Name><![CDATA[" + this.name + "]]></Name><GroupName><![CDATA[" + this.groupName + "]]></GroupName><ComponentStructure><![CDATA[" + componentStructure + "]]></ComponentStructure></attributes></article>";
ContentVersionVO contentVersionVO = new ContentVersionVO();
contentVersionVO.setVersionComment("Saved page template");
contentVersionVO.setVersionModifier(this.getInfoGluePrincipal().getName());
contentVersionVO.setVersionValue(versionValue);
ContentVersionVO newContentVersion = ContentVersionController.getContentVersionController().create(contentVO.getId(), destinationMasterLanguageId, contentVersionVO, null);
InputStream is = null;
File file = null;
try
{
MultiPartRequestWrapper mpr = ActionContext.getContext().getMultiPartRequest();
logger.info("mpr:" + mpr);
if(mpr != null)
{
Enumeration names = mpr.getFileNames();
while (names.hasMoreElements())
{
String name = (String)names.nextElement();
String contentType = mpr.getContentType(name);
String fileSystemName = mpr.getFilesystemName(name);
logger.info("name:" + name);
logger.info("contentType:" + contentType);
logger.info("fileSystemName:" + fileSystemName);
file = mpr.getFile(name);
if(file != null)
{
String fileName = fileSystemName;
//fileName = new VisualFormatter().replaceNonAscii(fileName, '_');
fileName = new VisualFormatter().replaceNiceURINonAsciiWithSpecifiedChars(fileName, CmsPropertyHandler.getNiceURIDefaultReplacementCharacter());
String tempFileName = "tmp_" + System.currentTimeMillis() + "_" + fileName;
String filePath = CmsPropertyHandler.getDigitalAssetPath();
fileSystemName = filePath + File.separator + tempFileName;
DigitalAssetVO newAsset = new DigitalAssetVO();
newAsset.setAssetContentType(contentType);
newAsset.setAssetKey("thumbnail");
newAsset.setAssetFileName(fileName);
newAsset.setAssetFilePath(filePath);
newAsset.setAssetFileSize(new Integer(new Long(file.length()).intValue()));
is = new FileInputStream(file);
DigitalAssetController.create(newAsset, is, newContentVersion.getContentVersionId(), this.getInfoGluePrincipal());
}
}
}
else
{