Creates all module folders that are selected in the input form.<p>

@param module the module

@return the updated module

@throws CmsException if somehting goes wrong
430467
private CmsModule createModuleFolders(CmsObject cms, CmsModule module) throws CmsException {

        String modulePath = CmsWorkplace.VFS_PATH_MODULES + module.getName() + "/";
        List<CmsExportPoint> exportPoints = module.getExportPoints();
        List<String> resources = module.getResources();

        // set the createModuleFolder flag if any other flag is set
        if (module.isCreateClassesFolder()
            || module.isCreateElementsFolder()
            || module.isCreateI18NFolder()
            || module.isCreateLibFolder()
            || module.isCreateResourcesFolder()
            || module.isCreateSchemasFolder()
            || module.isCreateTemplateFolder()
            || module.isCreateFormattersFolder()) {
            module.setCreateModuleFolder(true);
        }

        Set<String> exportPointPaths = new HashSet<String>();
        for (CmsExportPoint exportPoint : exportPoints) {
            exportPointPaths.add(exportPoint.getUri());
        }

        // check if we have to create the module folder

        I_CmsResourceType folderType = OpenCms.getResourceManager().getResourceType(
            CmsResourceTypeFolder.getStaticTypeName());
        I_CmsResourceType configType = OpenCms.getResourceManager().getResourceType(CmsADEManager.MODULE_CONFIG_TYPE);

        if (module.isCreateModuleFolder()) {
            CmsResource resource = cms.createResource(modulePath, folderType);
            CmsResource configResource = cms.createResource(modulePath + CONFIG_FILE, configType);
            try {
                cms.unlockResource(resource);
                cms.unlockResource(configResource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
            // add the module folder to the resource list
            resources.add(modulePath);
            module.setResources(resources);
        }

        // check if we have to create the template folder
        if (module.isCreateTemplateFolder()) {
            String path = modulePath + PATH_TEMPLATES;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
        }

        if (module.isCreateI18NFolder()) {
            String path = modulePath + PATH_i18n;
            CmsResource resource = cms.createResource(path, folderType);
            CmsResource bundleResource = cms.createResource(
                path + module.getName() + SUFFIX_BUNDLE_FILE + "_" + CmsLocaleManager.getDefaultLocale(),
                OpenCms.getResourceManager().getResourceType(CmsVfsBundleManager.TYPE_PROPERTIES_BUNDLE),
                null,
                null);
            cms.writeResource(bundleResource);
            try {
                cms.unlockResource(resource);
                cms.unlockResource(bundleResource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
        }

        // check if we have to create the elements folder
        if (module.isCreateElementsFolder()) {
            String path = modulePath + PATH_ELEMENTS;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
        }

        if (module.isCreateFormattersFolder()) {
            String path = modulePath + PATH_FORMATTERS;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
        }

        // check if we have to create the schemas folder
        if (module.isCreateSchemasFolder()) {
            String path = modulePath + PATH_SCHEMAS;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
        }

        // check if we have to create the resources folder
        if (module.isCreateResourcesFolder()) {
            String path = modulePath + PATH_RESOURCES;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
        }

        // check if we have to create the lib folder
        if (module.isCreateLibFolder()) {
            String path = modulePath + PATH_LIB;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
            if (!exportPointPaths.contains(path)) {
                CmsExportPoint exp = new CmsExportPoint(path, "WEB-INF/lib/");
                exportPoints.add(exp);
            }
            module.setExportPoints(exportPoints);
        }

        // check if we have to create the classes folder
        if (module.isCreateClassesFolder()) {
            String path = modulePath + PATH_CLASSES;
            CmsResource resource = cms.createResource(path, folderType);
            try {
                cms.unlockResource(resource);
            } catch (CmsLockException locke) {
                LOG.warn("Unbale to unlock resource", locke);
            }
            if (!exportPointPaths.contains(path)) {
                CmsExportPoint exp = new CmsExportPoint(path, "WEB-INF/classes/");
                exportPoints.add(exp);
                module.setExportPoints(exportPoints);
            }

            // now create all subfolders for the package structure
            StringTokenizer tok = new StringTokenizer(m_module.getName(), ".");
            while (tok.hasMoreTokens()) {
                String folder = tok.nextToken();
                path += folder + "/";
                CmsResource resource2 = cms.createResource(path, folderType);
                try {
                    cms.unlockResource(resource2);
                } catch (CmsLockException locke) {
                    LOG.warn("Unbale to unlock resource", locke);
                }
            }
        }
        return module;
    }
142972
private synchronized void initModuleExportPoints() {

        Set<CmsExportPoint> exportPoints = new HashSet<CmsExportPoint>();
        Iterator<CmsModule> i = m_modules.values().iterator();
        while (i.hasNext()) {
            CmsModule module = i.next();
            List<CmsExportPoint> moduleExportPoints = module.getExportPoints();
            for (int j = 0; j < moduleExportPoints.size(); j++) {
                CmsExportPoint point = moduleExportPoints.get(j);
                if (exportPoints.contains(point)) {
                    if (LOG.isWarnEnabled()) {
                        LOG.warn(
                            Messages.get().getBundle().key(
                                Messages.LOG_DUPLICATE_EXPORT_POINT_2,
                                point,
                                module.getName()));
                    }
                } else {
                    exportPoints.add(point);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(
                            Messages.get().getBundle().key(Messages.LOG_ADD_EXPORT_POINT_2, point, module.getName()));
                    }
                }
            }
        }
        m_moduleExportPoints = Collections.unmodifiableSet(exportPoints);
    }
283730
public void addModule(Module module) {
		if (module instanceof HttpAdapterAware) {
			((HttpAdapterAware) module).setHttpAdapter(getHttpAdapter());
		}
		this.moduleRegistry.addModule(module);
	}
134742
public CmsResource ensureModelFolder(CmsResource rootResource) throws CmsException {

        String modelFolderPath = CmsStringUtil.joinPaths(m_adeConfig.getBasePath(), ".content/.templates");

        try {
            CmsResource result = m_cms.readFolder(modelFolderPath);
            return result;
        } catch (CmsVfsResourceNotFoundException e) {
            CmsProperty searchExclude = new CmsProperty(CmsPropertyDefinition.PROPERTY_SEARCH_EXCLUDE, "all", null);
            CmsResource result = m_cms.createResource(
                modelFolderPath,
                getType(CmsResourceTypeFolder.getStaticTypeName()),
                null,
                Arrays.asList(searchExclude));
            tryUnlock(result);
            return result;
        }

    }
501516
protected CmsProject createAndSetModuleImportProject(CmsObject cms, CmsModule module) throws CmsException {

        CmsProject importProject = cms.createProject(
            org.opencms.module.Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                org.opencms.module.Messages.GUI_IMPORT_MODULE_PROJECT_NAME_1,
                new Object[] {module.getName()}),
            org.opencms.module.Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
                org.opencms.module.Messages.GUI_IMPORT_MODULE_PROJECT_DESC_1,
                new Object[] {module.getName()}),
            OpenCms.getDefaultUsers().getGroupAdministrators(),
            OpenCms.getDefaultUsers().getGroupAdministrators(),
            CmsProject.PROJECT_TYPE_TEMPORARY);
        cms.getRequestContext().setCurrentProject(importProject);
        cms.copyResourceToProject("/");
        return importProject;
    }
615974
public void importModule() {

        Window window = CmsBasicDialog.prepareWindow(DialogWidth.wide);
        CmsImportTabForm form = new CmsImportTabForm(m_app, this::reload);
        window.setContent(form);
        window.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_MODULES_IMPORT_TITLE_0));
        A_CmsUI.get().addWindow(window);
        window.center();
    }
612417
protected void createExportFolder(String exportPath, String rfsName) throws CmsException {

        String exportFolderName = CmsFileUtil.normalizePath(exportPath + CmsResource.getFolderPath(rfsName));
        File exportFolder = new File(exportFolderName);
        if (!exportFolder.exists()) {
            // in case of concurrent requests to create this folder, check the folder existence again
            if (!exportFolder.mkdirs() && !exportFolder.exists()) {
                throw new CmsStaticExportException(Messages.get().container(Messages.ERR_CREATE_FOLDER_1, rfsName));
            }
        }
    }
249246
public void deleteModule(String moduleName) throws Exception {

        OpenCms.getModuleManager().deleteModule(
            m_cms,
            moduleName,
            false,
            new CmsShellReport(m_cms.getRequestContext().getLocale()));
    }
520118
public String htmlModules() {

        StringBuffer html = new StringBuffer(1024);
        Iterator<String> itModules = sortModules(getAvailableModules().values()).iterator();
        for (int i = 0; itModules.hasNext(); i++) {
            String moduleName = itModules.next();
            CmsModule module = getAvailableModules().get(moduleName);
            html.append(htmlModule(module, i));
        }
        return html.toString();
    }
186158
private static String getModuleFolder(String moduleName) {

        if (moduleName == null) {
            return null;
        }
        CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
        if (module != null) {
            for (String resource : module.getResources()) {
                if (CmsStringUtil.comparePaths("/system/modules/" + moduleName, resource)) {
                    return resource;
                }
            }
        }
        return null;
    }
1369188
private T createBeans() throws CmsException {

        // create the beans for the resources
        Map<CmsResource, T> beans = new HashMap<CmsResource, T>();
        for (CmsResource resource : m_knownResources) {
            T bean = createEntry(m_cms, resource);
            if (bean != null) {
                beans.put(resource, bean);
            }
        }

        // attach beans for child resources to the beans for their parents
        for (Map.Entry<CmsResource, T> entry : beans.entrySet()) {
            CmsResource key = entry.getKey();
            T bean = entry.getValue();
            for (CmsResource child : m_childMap.get(key)) {
                T childEntry = beans.get(child);
                if (childEntry != null) {
                    bean.addChild(childEntry);
                }
            }
        }
        return beans.get(m_rootResource);
    }
323555
protected void runImportScript(CmsObject cms, CmsModule module) {

        LOG.info("Executing import script for module " + module.getName());
        m_report.println(
            org.opencms.module.Messages.get().container(org.opencms.module.Messages.RPT_IMPORT_SCRIPT_HEADER_0),
            I_CmsReport.FORMAT_HEADLINE);
        String importScript = "echo on\n" + module.getImportScript();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        PrintStream out = new PrintStream(buffer);
        CmsShell shell = new CmsShell(cms, "${user}@${project}:${siteroot}|${uri}>", null, out, out);
        shell.execute(importScript);
        String outputString = buffer.toString();
        LOG.info("Shell output for import script was: \n" + outputString);
        m_report.println(
            org.opencms.module.Messages.get().container(
                org.opencms.module.Messages.RPT_IMPORT_SCRIPT_OUTPUT_1,
                outputString));
    }
399913
public void touchModule(String moduleName) {

        CmsModule module = OpenCms.getModuleManager().getModule(moduleName);
        if (module == null) {
            m_shell.getOut().println("touchModule: could not find module " + moduleName);
        } else {
            m_shell.getOut().println("Touching module: " + moduleName);
            module.setCheckpointTime(System.currentTimeMillis());
            m_shell.getOut().println("Writing module configuration.");
            OpenCms.getModuleManager().updateModuleConfiguration();
        }
    }
180912
private void createNewContainerElements(CmsObject cms, CmsXmlContainerPage page, String sitePath)
    throws CmsException {

        CmsADEConfigData configData = OpenCms.getADEManager().lookupConfiguration(cms, cms.addSiteRoot(sitePath));
        Locale contentLocale = OpenCms.getLocaleManager().getDefaultLocale(cms, CmsResource.getFolderPath(sitePath));
        CmsObject cloneCms = OpenCms.initCmsObject(cms);
        cloneCms.getRequestContext().setLocale(contentLocale);
        CmsContainerPageBean pageBean = page.getContainerPage(cms);
        boolean needsChanges = false;
        List<CmsContainerBean> updatedContainers = new ArrayList<CmsContainerBean>();
        for (CmsContainerBean container : pageBean.getContainers().values()) {
            List<CmsContainerElementBean> updatedElements = new ArrayList<CmsContainerElementBean>();
            for (CmsContainerElementBean element : container.getElements()) {
                if (element.isCreateNew() && !element.isGroupContainer(cms) && !element.isInheritedContainer(cms)) {
                    needsChanges = true;
                    String typeName = OpenCms.getResourceManager().getResourceType(element.getResource()).getTypeName();
                    CmsResourceTypeConfig typeConfig = configData.getResourceType(typeName);
                    if (typeConfig == null) {
                        throw new IllegalArgumentException(
                            "Can not copy template model element '"
                                + element.getResource().getRootPath()
                                + "' because the resource type '"
                                + typeName
                                + "' is not available in this sitemap.");
                    }

                    CmsResource newResource = typeConfig.createNewElement(
                        cloneCms,
                        element.getResource(),
                        CmsResource.getParentFolder(cms.getRequestContext().addSiteRoot(sitePath)));
                    CmsContainerElementBean newBean = new CmsContainerElementBean(
                        newResource.getStructureId(),
                        element.getFormatterId(),
                        element.getIndividualSettings(),
                        false);
                    updatedElements.add(newBean);
                } else {
                    updatedElements.add(element);
                }
            }

            CmsContainerBean updatedContainer = new CmsContainerBean(
                container.getName(),
                container.getType(),
                container.getParentInstanceId(),
                container.isRootContainer(),
                container.getMaxElements(),
                updatedElements);
            updatedContainers.add(updatedContainer);
        }
        if (needsChanges) {
            CmsContainerPageBean updatedPage = new CmsContainerPageBean(updatedContainers);
            page.writeContainerPage(cms, updatedPage);
        }
    }
870930
public void editNewModule(Runnable callback) {

        CmsModule module = new CmsModule();
        module.setSite("/");

        editModule(module, true, CmsVaadinUtils.getMessageText(Messages.GUI_MODULES_TITLE_NEW_MODULE_0), callback);

    }
352053
protected boolean performDialogOperation() throws CmsException {

        // lock the folder
        checkLock(getParamResource());

        Iterator<CmsResource> i = getResources().iterator();
        // loop over all image resources to change the properties
        CmsResource res;
        while (i.hasNext()) {
            res = i.next();
            String imageName = res.getName();
            String propertySuffix = "" + imageName.hashCode();

            String property;
            I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(res);
            CmsExplorerTypeSettings settings = getSettingsForType(type.getTypeName());
            Iterator<String> itProperties = settings.getProperties().iterator();
            while (itProperties.hasNext()) {
                property = itProperties.next();
                CmsProperty currProperty = getCms().readPropertyObject(res, property, false);
                String newValue = getJsp().getRequest().getParameter(property + propertySuffix);
                writeProperty(res, property, newValue, currProperty);
            }
        }

        // unlock the folder
        CmsObject cms = getCms();
        cms.unlockResource(getParamResource());
        return true;
    }
1090239
private void initMacroContent() throws CmsException {

        I_CmsFormatterBean formatterConfig = OpenCms.getADEManager().getCachedFormatters(
            m_cms.getRequestContext().getCurrentProject().isOnlineProject()).getFormatters().get(
                m_element.getFormatterId());
        if (formatterConfig instanceof CmsMacroFormatterBean) {
            CmsMacroFormatterBean config = (CmsMacroFormatterBean)formatterConfig;
            m_input = config.getMacroInput();
            m_formatterReferences = config.getReferencedFormatters();
            if (m_element.isInMemoryOnly()) {
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(config.getPlaceholderMacroInput())) {
                    m_input = config.getPlaceholderMacroInput();
                }
                if (config.getDefaultContentStructureId() != null) {
                    try {
                        CmsResource defaultContent = m_cms.readResource(
                            ((CmsMacroFormatterBean)formatterConfig).getDefaultContentStructureId());
                        CmsFile defaultFile = m_cms.readFile(defaultContent);
                        m_element = new CmsContainerElementBean(
                            defaultFile,
                            m_element.getFormatterId(),
                            m_element.getIndividualSettings(),
                            true,
                            m_element.editorHash(),
                            m_element.isCreateNew());
                    } catch (CmsException e) {
                        LOG.error("Error reading default content for new resource", e);
                    }
                }
            }
        } else {
            // only as a fall back, should not be used
            m_formatterReferences = new HashMap<String, CmsUUID>();
            CmsResource macroContent = m_cms.readResource(m_element.getFormatterId());
            CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(m_cms, macroContent, m_request);
            m_input = xmlContent.getStringValue(m_cms, CmsFormatterBeanParser.N_MACRO, CmsLocaleManager.MASTER_LOCALE);
            List<I_CmsXmlContentValue> formatters = xmlContent.getValues(
                CmsFormatterBeanParser.N_FORMATTERS,
                CmsLocaleManager.MASTER_LOCALE);
            for (I_CmsXmlContentValue formatterValue : formatters) {
                CmsXmlVfsFileValue file = (CmsXmlVfsFileValue)xmlContent.getValue(
                    formatterValue.getPath() + "/" + CmsFormatterBeanParser.N_FORMATTER,
                    CmsLocaleManager.MASTER_LOCALE);
                String macroName = xmlContent.getStringValue(
                    m_cms,
                    formatterValue.getPath() + "/" + CmsFormatterBeanParser.N_MACRO_NAME,
                    CmsLocaleManager.MASTER_LOCALE);
                m_formatterReferences.put(macroName, file.getLink(m_cms).getStructureId());
            }
        }
    }