throws RollerException {
log.debug("Importing theme "+theme.getName()+" to weblog "+website.getName());
try {
UserManager userMgr = RollerFactory.getRoller().getUserManager();
Collection templates = theme.getTemplates();
Iterator iter = templates.iterator();
ThemeTemplate theme_template = null;
while ( iter.hasNext() ) {
theme_template = (ThemeTemplate) iter.next();
WeblogTemplate template = null;
if(theme_template.getName().equals(WeblogTemplate.DEFAULT_PAGE)) {
// this is the main Weblog template
try {
template = userMgr.getPage(website.getDefaultPageId());
} catch(Exception e) {
// user may not have a default page yet
}
} else {
// any other template
template = userMgr.getPageByName(website, theme_template.getName());
}
if (template != null) {
// User already has page by that name, so overwrite it.
template.setContents(theme_template.getContents());
template.setLink(theme_template.getLink());
} else {
// User does not have page by that name, so create new page.
template = new WeblogTemplate(
null, // id
website, // website
theme_template.getName(), // name
theme_template.getDescription(), // description
theme_template.getLink(), // link
theme_template.getContents(), // contents
new Date(), // last mod
theme_template.getTemplateLanguage(), // temp lang
theme_template.isHidden(), // hidden
theme_template.isNavbar(), // navbar
theme_template.getDecoratorName() // decorator
);
userMgr.savePage( template );
}
}
// now update this website's theme to custom
website.setEditorTheme(Theme.CUSTOM);
// if this is the first time someone is customizing a theme then
// we need to set a default page
if(website.getDefaultPageId() == null ||
website.getDefaultPageId().trim().equals("") ||
website.getDefaultPageId().equals("dummy")) {
// we have to go back to the db to figure out the id
WeblogTemplate template = userMgr.getPageByName(website, "Weblog");
if(template != null) {
log.debug("Setting default page to "+template.getId());
website.setDefaultPageId(template.getId());
}
}
// we also want to set the weblogdayid
WeblogTemplate dayTemplate = userMgr.getPageByName(website, "_day");
if(dayTemplate != null) {
log.debug("Setting default day page to "+dayTemplate.getId());
website.setWeblogDayPageId(dayTemplate.getId());
}
// save our updated website
userMgr.saveWebsite(website);
// now lets import all the theme resources
FileManager fileMgr = RollerFactory.getRoller().getFileManager();
List resources = theme.getResources();