throws IOException, ServletException {
@SuppressWarnings("unchecked")
List<Map<Object, Object>> importsInfos = (List<Map<Object, Object>>) session.getAttribute("importsInfos");
Map<Object, Object> siteKeyMapping = new HashMap<Object, Object>();
boolean stillBad = false;
JahiaSitesService jahiaSitesService = ServicesRegistry.getInstance().getJahiaSitesService();
for (Map<Object, Object> infos : importsInfos) {
File file = (File) infos.get("importFile");
infos.put("sitekey", StringUtils.left(request.getParameter(file.getName() + "siteKey") == null ? null :
request.getParameter(file.getName() + "siteKey").trim(), 50));
infos.put("oldsitekey", request.getParameter(file.getName() + "oldSiteKey") == null ? null :
request.getParameter(file.getName() + "oldSiteKey").trim());
if (infos.get("sitekey") != null && !infos.get("sitekey").equals(infos.get("oldsitekey"))) {
siteKeyMapping.put(infos.get("oldsitekey"), infos.get("sitekey"));
}
infos.put("siteservername", StringUtils.left(
request.getParameter(file.getName() + "siteServerName") == null ? null :
request.getParameter(file.getName() + "siteServerName").trim(), 200));
infos.put("sitetitle", StringUtils.left(request.getParameter(file.getName() + "siteTitle") == null ? null :
request.getParameter(file.getName() + "siteTitle").trim(), 100));
infos.put("selected", request.getParameter(file.getName() + "selected"));
infos.put("templates", request.getParameter(file.getName() + "templates"));
if (request.getParameter(file.getName() + "selected") != null) {
try {
if (NON_SITE_IMPORTS.contains(infos.get("importFileName"))) {
} else {
infos.put("siteTitleInvalid", StringUtils.isEmpty((String) infos.get("sitetitle")));
String siteKey = (String) infos.get("sitekey");
boolean valid = isSiteKeyValid(siteKey);
infos.put("siteKeyInvalid", !valid);
infos.put("siteKeyExists", valid && jahiaSitesService.getSiteByKey(siteKey) != null);
String serverName = (String) infos.get("siteservername");
valid = isServerNameValid(serverName);
infos.put("siteServerNameInvalid", !valid);
infos.put("siteServerNameExists", valid && !URLGenerator.isLocalhost(serverName) && jahiaSitesService.getSite(serverName) != null);
stillBad = (Boolean) infos.get("siteKeyInvalid")
|| (Boolean) infos.get("siteKeyExists")
|| (Boolean) infos.get("siteServerNameInvalid")
|| (Boolean) infos.get("siteServerNameExists");
}
} catch (JahiaException e) {
logger.error("Error while processing file import", e);
}
} else {
infos.put("siteKeyInvalid", Boolean.FALSE);
infos.put("siteKeyExists", Boolean.FALSE);
infos.put("siteServerNameInvalid", Boolean.FALSE);
infos.put("siteServerNameExists", Boolean.FALSE);
}
}
if (stillBad) {
try {
TreeMap<String, JCRNodeWrapper> orderedTemplateSets = getTemplatesSets();
request.setAttribute("tmplSets", new ArrayList<JCRNodeWrapper>(orderedTemplateSets.values()));
} catch (RepositoryException e) {
logger.error(e.getMessage(), e);
}
JahiaAdministration.doRedirect(request, response, session, JSP_PATH + "import_choose.jsp");
} else {
boolean doImportServerPermissions = false;
for (Map<Object, Object> infos : importsInfos) {
File file = (File) infos.get("importFile");
if (request.getParameter(file.getName() + "selected") != null
&& infos.get("importFileName").equals("serverPermissions.xml")) {
doImportServerPermissions = true;
break;
}
}
request.setAttribute("doImportServerPermissions", Boolean.valueOf(doImportServerPermissions));
for (Map<Object, Object> infos : importsInfos) {
File file = (File) infos.get("importFile");
if (request.getParameter(file.getName() + "selected") != null &&
infos.get("importFileName").equals("users.xml")) {
try {
ImportExportBaseService.getInstance().importUsers(file);
} finally {
file.delete();
}
break;
}
}
for (Map<Object, Object> infos : importsInfos) {
File file = (File) infos.get("importFile");
if (request.getParameter(file.getName() + "selected") != null) {
if (infos.get("type").equals("files")) {
try {
JahiaSite system = ServicesRegistry.getInstance().getJahiaSitesService().getSiteByKey(JahiaSitesBaseService.SYSTEM_SITE_KEY);
Map<String,String> pathMapping = JCRSessionFactory.getInstance().getCurrentUserSession().getPathMapping();
pathMapping.put("/shared/files/", "/sites/" + system.getSiteKey() + "/files/");
pathMapping.put("/shared/mashups/", "/sites/" + system.getSiteKey() + "/portlets/");
ImportExportBaseService.getInstance().importSiteZip(file, system, infos);
} catch (Exception e) {
logger.error("Error when getting templates", e);
} finally {
file.delete();
}
} else if (infos.get("type").equals("xml") &&
(infos.get("importFileName").equals("serverPermissions.xml") ||
infos.get("importFileName").equals("users.xml"))) {
} else if (infos.get("type").equals("site")) {
// site import
String tpl = (String) infos.get("templates");
if ("".equals(tpl)) {
tpl = null;
}
Locale defaultLocale = determineDefaultLocale(jParams, infos);
try {
JahiaSite site = jahiaSitesService
.addSite(jParams.getUser(), (String) infos.get("sitetitle"),
(String) infos.get("siteservername"), (String) infos.get("sitekey"), "",
defaultLocale, tpl, "fileImport", file,
(String) infos.get("importFileName"), false, false, (String) infos.get("originatingJahiaRelease"));
session.setAttribute(ProcessingContext.SESSION_SITE, site);