return omdl;
}
@Override
public Page importOmdl(MultipartFile multipartFile, String pageName) throws DuplicateItemException {
Page page = null;
OmdlInputAdapter omdlInputAdapter = new OmdlInputAdapter();
File temp = null;
String xml = null;
try {
if(multipartFile != null){
if(multipartFile.getSize() > 0) {
String tempUploadFolder = System.getProperty("java.io.tmpdir");
temp = new File(tempUploadFolder, multipartFile.getOriginalFilename());
multipartFile.transferTo(temp);
xml = FileUtils.readFileToString(temp);
}
}
} catch (IllegalStateException e) {
logger.error(e.getMessage());
throw new RuntimeException(e);
} catch (IOException e) {
logger.error(e.getMessage());
throw new RuntimeException(e);
}
Document root = initializeBuilder(xml);
if(root != null){
try {
parseOmdlFile(root, omdlInputAdapter);
} catch (BadOmdlXmlFormatException e) {
logger.error(e.getMessage());
throw new RuntimeException(e);
}
}
page = pageService.addNewUserPage(pageName, omdlInputAdapter.getLayoutCode());
switch (page.getRegions().size()){
case 1:
populateRegionWidgets(page, omdlInputAdapter.getAllUrls(), page.getRegions().get(0).getId());
break;
case 2:
populateRegionWidgets(page, omdlInputAdapter.getAllLeftUrls(), page.getRegions().get(0).getId());
populateRegionWidgets(page, omdlInputAdapter.getAllRightUrls(), page.getRegions().get(1).getId());
break;
case 3:
populateRegionWidgets(page, omdlInputAdapter.getAllLeftUrls(), page.getRegions().get(0).getId());
populateRegionWidgets(page, omdlInputAdapter.getAllCenterUrls(), page.getRegions().get(1).getId());
populateRegionWidgets(page, omdlInputAdapter.getAllRightUrls(), page.getRegions().get(2).getId());
break;
case 4:
populateRegionWidgets(page, omdlInputAdapter.getAllLeftUrls(), page.getRegions().get(0).getId());
populateRegionWidgets(page, omdlInputAdapter.getAllCenterUrls(), page.getRegions().get(1).getId());
populateRegionWidgets(page, omdlInputAdapter.getAllRightUrls(), page.getRegions().get(2).getId());
populateRegionWidgets(page, omdlInputAdapter.getAllUnknownUrls(), page.getRegions().get(3).getId());
break;
default:
// there are no layouts with more than 4 regions at present
}
return page;