Package org.jahia.services.sites

Examples of org.jahia.services.sites.JahiaSitesService


        jahiaSite = (JahiaSite) request.getSession().getAttribute(ProcessingContext.SESSION_SITE);
        JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData");
        this.jParams = jData.getProcessingContext();

        if (jahiaSite == null) {
            JahiaSitesService sitesService = sReg.getJahiaSitesService();
            jahiaSite = sitesService.getSite(0);
            request.getSession().setAttribute(ProcessingContext.SESSION_SITE, jahiaSite);
        }
        userRequestDispatcher(request, response, request.getSession());
    } // end constructor
View Full Code Here


        redirect(redirect, response);
    }

    protected JCRSiteNode resolveSite(HttpServletRequest request, String workspace) throws JahiaException, RepositoryException {
        JahiaSitesService siteService = JahiaSitesBaseService.getInstance();
        JahiaSite resolvedSite = !URLGenerator.isLocalhost(request.getServerName()) ? siteService.getSiteByServerName(request.getServerName()) : null;
        if (resolvedSite == null) {
            resolvedSite = siteService.getDefaultSite();
        }
        return resolvedSite != null ? (JCRSiteNode) JCRStoreService.getInstance().getSessionFactory()
                .getCurrentUserSession(workspace).getNode(resolvedSite.getJCRLocalPath()) : null;
    }
View Full Code Here

            final List<String> deletedLanguageList = Arrays.asList(deletedLanguages);
            mandatoryLanguagesSet.removeAll(deletedLanguageList);
            site.getLanguages().removeAll(deletedLanguageList);
        }
        try {
            JahiaSitesService service = ServicesRegistry.getInstance().getJahiaSitesService();
            service.updateSite(site);
            JahiaSite jahiaSite = service.getSiteByKey(JahiaSitesBaseService.SYSTEM_SITE_KEY);
            jahiaSite.getLanguages().addAll(site.getLanguages());
            service.updateSite(jahiaSite);
        } catch (JahiaException e) {
            logger.error(e.getMessage(), e);
        }
        // finally the most complicated operation, let's delete the
        // languages. This is a two step process that requires a
View Full Code Here

            if (Jahia.jahiaHttpPort == -1) {
                Jahia.jahiaHttpPort = request.getServerPort();
            }

            if (ParamBean.getDefaultSite() == null) {
                JahiaSitesService jahiaSitesService = ServicesRegistry.getInstance().getJahiaSitesService();
                if (jahiaSitesService.getNbSites() > 0) {
                    jahiaSitesService.setDefaultSite(jahiaSitesService.getSites().next());
                } else {
                    getServletContext().getRequestDispatcher("/administration?do=sites&sub=list").forward(request, response);
                    return;
                }
            }
View Full Code Here

        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) {
View Full Code Here

            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);
View Full Code Here

        return createSite(name, "localhost" + System.currentTimeMillis(), WEB_TEMPLATES, null, null);
    }

    public static JahiaSite createSite(String name, Set<String> languages, Set<String> mandatoryLanguages, boolean mixLanguagesActive) throws Exception {
        JahiaSite site = createSite(name, "localhost" + System.currentTimeMillis(), WEB_TEMPLATES, null, null);
        JahiaSitesService service = ServicesRegistry.getInstance().getJahiaSitesService();
        if (!CollectionUtils.isEmpty(languages) && !languages.equals(site.getLanguages())) {
            site.setLanguages(languages);
        }
        if (!CollectionUtils.isEmpty(mandatoryLanguages) && !mandatoryLanguages.equals(site.getMandatoryLanguages())) {
            site.setMandatoryLanguages(mandatoryLanguages);
        }
        if (mixLanguagesActive != site.isMixLanguagesActive()) {
            site.setMixLanguagesActive(mixLanguagesActive);
        }
        service.updateSite(site);
        return site;
    }
View Full Code Here

                                       String prepackedZIPFile, String siteZIPName) throws Exception {

        ProcessingContext ctx = Jahia.getThreadParamBean();
        JahiaUser admin = JahiaAdminUser.getAdminUser(0);

        JahiaSitesService service = ServicesRegistry.getInstance().getJahiaSitesService();
        JahiaSite site = service.getSiteByKey(name);

        if (site != null) {
            service.removeSite(site);
        }
        File siteZIPFile = null;
        File sharedZIPFile = null;
        try {
            if (!StringUtils.isEmpty(prepackedZIPFile)) {
                ZipInputStream zis = null;
                OutputStream os = null;
                try {
                    zis = new ZipInputStream(new FileInputStream(new File(prepackedZIPFile)));
                    ZipEntry z = null;
                    while ((z = zis.getNextEntry()) != null) {
                        if (siteZIPName.equalsIgnoreCase(z.getName())
                                || "shared.zip".equals(z.getName())) {
                            File zipFile = File.createTempFile("import", ".zip");
                            os = new FileOutputStream(zipFile);
                            byte[] buf = new byte[4096];
                            int r;
                            while ((r = zis.read(buf)) > 0) {
                                os.write(buf, 0, r);
                            }
                            os.close();
                            if ("shared.zip".equals(z.getName())) {
                                sharedZIPFile = zipFile;
                            } else {
                                siteZIPFile = zipFile;
                            }
                        }
                    }
                } catch (IOException e) {
                    logger.error(e.getMessage(), e);
                } finally {
                    if (os != null) {
                        try {
                            os.close();
                        } catch (IOException e) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                    if (zis != null) {
                        try {
                            zis.close();
                        } catch (IOException e) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                }
            }
            if (sharedZIPFile != null) {
                try {
                    ImportExportBaseService.getInstance().importSiteZip(sharedZIPFile, null, null);
                } catch (RepositoryException e) {
                    logger.warn("shared.zip could not be imported", e);
                }
            }
            site = service.addSite(admin, name, serverName, name, name, ctx.getLocale(),
                    templateSet, siteZIPFile == null ? "noImport" : "fileImport", siteZIPFile,
                    null, false, false, null);
            ctx.setSite(site);
        } finally {
            if (sharedZIPFile != null) {
View Full Code Here

            service.removeSite(jahiaSite);
        }
    }

    public static void deleteSite(String name) throws Exception {
        JahiaSitesService service = ServicesRegistry.getInstance().getJahiaSitesService();
        JahiaSite site = service.getSiteByKey(name);
        if (site != null)
            service.removeSite(site);
    }
View Full Code Here

TOP

Related Classes of org.jahia.services.sites.JahiaSitesService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.