*/
public boolean terminateAdd(HttpServletRequest request, HttpSession session) throws IOException, ServletException {
String warningMsg = "";
JahiaSite currentSite = (JahiaSite) session.getAttribute(ProcessingContext.SESSION_SITE);
// get objects temporary stocked in session...
JahiaSite site = (JahiaSite) session.getAttribute(CLASS_NAME + "newJahiaSite");
Boolean defaultSite = (Boolean) session.getAttribute(CLASS_NAME + "defaultSite");
JahiaUser existantAdminUser = (JahiaUser) session.getAttribute(CLASS_NAME + "existantAdminUser");
Locale selectedLocale = (Locale) session.getAttribute(CLASS_NAME + "selectedLocale");
try {
JahiaUser adminSiteUser = null;
// get services...
JahiaUserManagerService jums = ServicesRegistry.getInstance().getJahiaUserManagerService();
JahiaSitesService jsms = ServicesRegistry.getInstance().getJahiaSitesService();
JahiaUser currentUser = jums.lookupUser((String) session.getAttribute(CLASS_NAME + "jahiaLoginUsername"));
// add the site in siteManager...
site = jsms.addSite(currentUser, site.getTitle(), site.getServerName(), site.getSiteKey(), site.getDescr(),
selectedLocale, (String) request.getAttribute("selectedTmplSet"),
(String) request.getAttribute("firstImport"), (File) request.getAttribute("fileImport"),
(String) request.getAttribute("fileImportName"), (Boolean) request.getAttribute("asAJob"),
(Boolean) request.getAttribute("doImportServerPermissions"), (String) request.getAttribute("originatingJahiaRelease"));
if (site != null) {
jParams.setSite(site);
jParams.setSiteID(site.getID());
jParams.setSiteKey(site.getSiteKey());
jParams.setCurrentLocale(selectedLocale);
// set as default site
if (defaultSite.booleanValue()) {
changeDefaultSite(site);
}
// create administrator user if requested...
if (existantAdminUser == null) {
// get session administrator properties...
String adminUsername = (String) session.getAttribute(CLASS_NAME + "adminUsername");
String adminPassword = (String) session.getAttribute(CLASS_NAME + "adminPassword");
Properties adminProps = (Properties) session.getAttribute(CLASS_NAME + "adminProps");
if (adminUsername != null) {
// create user...
adminSiteUser = jums.createUser(adminUsername, adminPassword, adminProps);
}
} else {
adminSiteUser = existantAdminUser; // the administrator already exists... use this.
}
if (adminSiteUser != null) {
// attach admin to administrators group...
JahiaSiteTools.getAdminGroup(site).addMember(adminSiteUser);
}
// set as current site if the session site is null
if (session.getAttribute(ProcessingContext.SESSION_SITE) == null) {
session.setAttribute(ProcessingContext.SESSION_SITE, site);
session.setAttribute(JahiaAdministration.CLASS_NAME + "manageSiteID", new Integer(site.getID()));
}
// set new site in session
session.setAttribute(CLASS_NAME + "newJahiaSite", site);
if (currentSite != null) {
jParams.setSite(currentSite);
jParams.setSiteID(currentSite.getID());
}
sMgr.updateSite(site);
JahiaSite jahiaSite = sMgr.getSiteByKey(JahiaSitesBaseService.SYSTEM_SITE_KEY);
jahiaSite.getLanguages().addAll(site.getLanguages());
sMgr.updateSite(jahiaSite);
} else {
warningMsg =
getMessage("label.error.processingRequestError");
request.setAttribute("warningMsg", warningMsg);