Imports a resource into the Cms.<p>

@param importFile the name (absolute Path) of the import resource (zip or folder)
@param importPath the name (absolute Path) of folder in which should be imported

@throws Exception if something goes wrong
328193
public void importResources(String importFile, String importPath) throws Exception {

        CmsImportParameters params = new CmsImportParameters(
            OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(importFile),
            importPath,
            true);

        OpenCms.getImportExportManager().importData(
            m_cms,
            new CmsShellReport(m_cms.getRequestContext().getLocale()),
            params);
    }
390861
protected function resolveDatabaseImportPath($import_path = null)
    {
        if (!isset($import_path)) {
            $import_path = $this->doAsk(
                new Question(
                    'Input the path to the database file: '
                )
            );

            if (!file_exists($import_path)) {
                throw new \Exception(
                    'The path to the database file does not exist.'
                );
            }
        }

        return new \SplFileInfo($import_path);
    }
445035
protected String normalizeExportPath(String exportPath) {

        String result = insertContextStrings(exportPath);
        result = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebApplication(result);
        if (result.endsWith(File.separator)) {
            // ensure export path does NOT end with a File.separator
            result = result.substring(0, result.length() - 1);
        }
        return result;
    }
1291633
@Override
    public I importFrom(final File file, Filter<ArchivePath> filter) throws ArchiveImportException {
        Validate.notNull(file, "File must be specified");
        if (!file.exists()) {
            throw new IllegalArgumentException("Specified file for import does not exist: " + file);
        }
        if (file.isDirectory()) {
            throw new IllegalArgumentException("Specified file for import is a directory: " + file);
        }

        final S archive;
        try {
            archive = this.getInputStreamForFile(file);
        } catch (final IOException e) {
            throw new ArchiveImportException("Could not read archive file " + file, e);
        }

        return this.importFrom(archive, filter);

    }
324594
protected Proto searchFromProtoPathOnly(String path, Proto importer) throws Exception
    {
        // proto_path
        File protoFile;
        for (File dir : __protoLoadDirs)
        {
            if ((protoFile = new File(dir, path)).exists())
                return loadFrom(protoFile, importer);
        }

        throw new IllegalStateException("Imported proto " + path +
                " not found. (" + importer.getSourcePath() + ")");
    }
98317
public static base_response Import(nitro_service client, appqoecustomresp resource) throws Exception {
		appqoecustomresp Importresource = new appqoecustomresp();
		Importresource.src = resource.src;
		Importresource.name = resource.name;
		return Importresource.perform_operation(client,"Import");
	}
264030
@Deprecated
    public void importData(CmsObject cms, String importFile, String importPath, I_CmsReport report)
    throws CmsXmlException, CmsImportExportException, CmsRoleViolationException, CmsException {

        CmsImportParameters parameters = new CmsImportParameters(importFile, importPath, true);
        setImportParameters(parameters);

        importData(cms, report);
    }
242625
@Override
    public ZipImporter importFrom(InputStream stream, Filter<ArchivePath> filter) throws ArchiveImportException {
        Validate.notNull(stream, "Stream must be specified");
        Validate.notNull(filter, "Filter must be specified");

        try {
            // Wrap in ZipInputStream if we haven't been given one
            final ZipInputStream zipStream = new ZipInputStream(stream);

            ZipEntry entry;
            while ((entry = zipStream.getNextEntry()) != null) {
                // Get the name
                final String entryName = entry.getName();

                if(!filter.include(ArchivePaths.create(entryName))) {
                    zipStream.closeEntry();
                    continue;
                }

                // Get the archive
                final Archive<?> archive = this.getArchive();

                // Handle directories separately
                if (entry.isDirectory()) {
                    archive.addAsDirectory(entryName);
                    continue;
                }

                final ByteArrayOutputStream output = new ByteArrayOutputStream(8192);
                IOUtil.copy(zipStream, output);
                archive.add(new ByteArrayAsset(output.toByteArray()), entryName);
                zipStream.closeEntry();
            }
        } catch (IOException e) {
            throw new ArchiveImportException("Could not import stream", e);
        }
        return this;
    }
1113595
public static CmsFlexBucketConfiguration loadFromVfsFile(CmsObject cms, String path) throws CmsException {

        if (!cms.existsResource(path)) {
            return null;
        }
        CmsResource configRes = cms.readResource(path);
        if (configRes.isFolder()) {
            return null;
        }
        CmsFile configFile = cms.readFile(configRes);
        String encoding = CmsFileUtil.getEncoding(cms, configRes);
        Properties props = new Properties();
        try {
            props.load(new InputStreamReader(new ByteArrayInputStream(configFile.getContents()), encoding));
            return loadFromProperties(props);
        } catch (IOException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return null;
    }
593139
public void importModulesFromSetupBean() throws Exception {

        // read here how the list of modules to be installed is passed from the setup bean to the
        // setup thread, and finally to the shell process that executes the setup script:
        // 1) the list with the package names of the modules to be installed is saved by setInstallModules
        // 2) the setup thread gets initialized in a JSP of the setup wizard
        // 3) the instance of the setup bean is passed to the setup thread by setAdditionalShellCommand
        // 4) the setup bean is passed to the shell by startSetup
        // 5) because the setup bean implements I_CmsShellCommands, the shell constructor can pass the shell's CmsObject back to the setup bean
        // 6) thus, the setup bean can do things with the Cms

        if ((m_cms != null) && (m_installModules != null)) {
            for (int i = 0; i < m_installModules.size(); i++) {
                String filename = m_moduleFilenames.get(m_installModules.get(i));
                try {
                    importModuleFromDefault(filename);
                } catch (Exception e) {
                    // log a exception during module import, but make sure the next module is still imported
                    e.printStackTrace(System.err);
                }
            }
            m_hasIndexHtml = false;
            try {
                m_cms.readResource("/index.html");
                m_hasIndexHtml = true;
            } catch (Exception e) {

            }

        }

    }
1079127
private void importAllResources() throws CmsImportExportException {

        String source, destination, type, uuidresource, userlastmodified, usercreated, flags, timestamp;
        long datelastmodified, datecreated;

        List<Node> fileNodes;
        List<Node> acentryNodes;
        Element currentElement, currentEntry;
        List<CmsProperty> properties = null;

        // get list of unwanted properties
        List<String> deleteProperties = OpenCms.getImportExportManager().getIgnoredProperties();
        if (deleteProperties == null) {
            deleteProperties = new ArrayList<String>();
        }
        // get list of immutable resources
        List<String> immutableResources = OpenCms.getImportExportManager().getImmutableResources();
        if (immutableResources == null) {
            immutableResources = Collections.EMPTY_LIST;
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_IMPORTEXPORT_IMMUTABLE_RESOURCES_SIZE_1,
                    Integer.toString(immutableResources.size())));
        }
        // get the wanted page type for imported pages
        m_convertToXmlPage = OpenCms.getImportExportManager().convertToXmlPage();

        try {
            // get all file-nodes
            fileNodes = m_docXml.selectNodes("//" + A_CmsImport.N_FILE);

            int importSize = fileNodes.size();
            // walk through all files in manifest
            for (int i = 0; i < fileNodes.size(); i++) {
                m_report.print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_SUCCESSION_2,
                        String.valueOf(i + 1),
                        String.valueOf(importSize)));
                currentElement = (Element)fileNodes.get(i);
                // get all information for a file-import
                // <source>
                source = getChildElementTextValue(currentElement, A_CmsImport.N_SOURCE);
                // <destintion>
                destination = getChildElementTextValue(currentElement, A_CmsImport.N_DESTINATION);
                // <type>
                type = getChildElementTextValue(currentElement, A_CmsImport.N_TYPE);
                // <uuidstructure>
                //uuidstructure = CmsImport.getChildElementTextValue(
                //    currentElement,
                //    CmsImportExportManager.N_UUIDSTRUCTURE);
                // <uuidresource>
                uuidresource = getChildElementTextValue(currentElement, A_CmsImport.N_UUIDRESOURCE);
                // <datelastmodified>
                timestamp = getChildElementTextValue(currentElement, A_CmsImport.N_DATELASTMODIFIED);
                if (timestamp != null) {
                    datelastmodified = Long.parseLong(timestamp);
                } else {
                    datelastmodified = System.currentTimeMillis();
                }
                // <userlastmodified>
                userlastmodified = getChildElementTextValue(currentElement, A_CmsImport.N_USERLASTMODIFIED);
                // <datecreated>
                timestamp = getChildElementTextValue(currentElement, A_CmsImport.N_DATECREATED);
                if (timestamp != null) {
                    datecreated = Long.parseLong(timestamp);
                } else {
                    datecreated = System.currentTimeMillis();
                }
                // <usercreated>
                usercreated = getChildElementTextValue(currentElement, A_CmsImport.N_USERCREATED);
                // <flags>
                flags = getChildElementTextValue(currentElement, A_CmsImport.N_FLAGS);

                String translatedName = m_cms.getRequestContext().addSiteRoot(m_importPath + destination);
                if (CmsResourceTypeFolder.RESOURCE_TYPE_NAME.equals(type)) {
                    translatedName += "/";
                }
                // translate the name during import
                translatedName = m_cms.getRequestContext().getDirectoryTranslator().translateResource(translatedName);
                // check if this resource is immutable
                boolean resourceNotImmutable = checkImmutable(translatedName, immutableResources);
                translatedName = m_cms.getRequestContext().removeSiteRoot(translatedName);
                // if the resource is not immutable and not on the exclude list, import it
                if (resourceNotImmutable) {
                    // print out the information to the report
                    m_report.print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
                    m_report.print(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));
                    //m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0));
                    // get all properties
                    properties = readPropertiesFromManifest(currentElement, deleteProperties);

                    // import the resource
                    CmsResource res = importResource(
                        source,
                        destination,
                        type,
                        uuidresource,
                        datelastmodified,
                        userlastmodified,
                        datecreated,
                        usercreated,
                        flags,
                        properties);

                    List<CmsAccessControlEntry> aceList = new ArrayList<CmsAccessControlEntry>();
                    if (res != null) {
                        // write all imported access control entries for this file
                        acentryNodes = currentElement.selectNodes("*/" + A_CmsImport.N_ACCESSCONTROL_ENTRY);
                        // collect all access control entries
                        for (int j = 0; j < acentryNodes.size(); j++) {
                            currentEntry = (Element)acentryNodes.get(j);
                            // get the data of the access control entry
                            String id = getChildElementTextValue(currentEntry, A_CmsImport.N_ACCESSCONTROL_PRINCIPAL);
                            String acflags = getChildElementTextValue(currentEntry, A_CmsImport.N_FLAGS);
                            String allowed = getChildElementTextValue(
                                currentEntry,
                                A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
                                    + "/"
                                    + A_CmsImport.N_ACCESSCONTROL_ALLOWEDPERMISSIONS);
                            String denied = getChildElementTextValue(
                                currentEntry,
                                A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
                                    + "/"
                                    + A_CmsImport.N_ACCESSCONTROL_DENIEDPERMISSIONS);

                            // get the correct principal
                            try {
                                String principalId = new CmsUUID().toString();
                                String principal = id.substring(id.indexOf('.') + 1, id.length());

                                if (id.startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) {
                                    principal = OpenCms.getImportExportManager().translateGroup(principal);
                                    principalId = m_cms.readGroup(principal).getId().toString();
                                } else {
                                    principal = OpenCms.getImportExportManager().translateUser(principal);
                                    principalId = m_cms.readUser(principal).getId().toString();
                                }

                                // add the entry to the list
                                aceList.add(getImportAccessControlEntry(res, principalId, allowed, denied, acflags));
                            } catch (CmsDataAccessException e) {
                                // user or group not found, so do not import the ace
                            }
                        }
                        importAccessControlEntries(res, aceList);

                    } else {
                        // resource import failed, since no CmsResource was created
                        m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                        m_report.println(
                            org.opencms.report.Messages.get().container(
                                org.opencms.report.Messages.RPT_ARGUMENT_1,
                                translatedName));
                    }
                } else {
                    // skip the file import, just print out the information to the report
                    m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    m_report.println(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));
                }
            }

        } catch (Exception e) {
            m_report.println(e);
            m_report.addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }
            throw new CmsImportExportException(message, e);
        }

    }
892881
public void importResource() {

        boolean resourceIdWasNull = false;

        try {
            if (m_throwable != null) {
                getReport().println(m_throwable);
                getReport().addError(m_throwable);

                CmsMessageContainer message = Messages.get().container(
                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(message.key(), m_throwable);
                }
                m_throwable = null;
                m_importACEs = false;
                m_resource = null;

                return;
            }

            // apply name translation and import path
            String translatedName = getCms().getRequestContext().addSiteRoot(
                m_parameters.getDestinationPath() + m_destination);

            boolean resourceImmutable = checkImmutable(translatedName);
            translatedName = getCms().getRequestContext().removeSiteRoot(translatedName);
            // if the resource is not immutable and not on the exclude list, import it
            if (!resourceImmutable) {
                // print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
                getReport().print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));
                getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

                boolean exists = getCms().existsResource(translatedName, CmsResourceFilter.ALL);

                byte[] content = null;
                // get the file content
                if (m_source != null) {
                    content = m_helper.getFileBytes(m_source);
                }
                int size = 0;
                if (content != null) {
                    size = content.length;
                }

                // get UUID for the structure
                if (m_structureId == null) {
                    // if null generate a new structure id
                    m_structureId = new CmsUUID();
                }

                // get UUIDs for the resource
                if ((m_resourceId == null) || (m_type.isFolder())) {
                    // folders get always a new resource UUID
                    m_resourceId = new CmsUUID();
                    resourceIdWasNull = true;
                }

                // create a new CmsResource
                CmsResource resource = new CmsResource(
                    m_structureId,
                    m_resourceId,
                    translatedName,
                    m_type.getTypeId(),
                    m_type.isFolder(),
                    m_flags,
                    getCms().getRequestContext().getCurrentProject().getUuid(),
                    CmsResource.STATE_NEW,
                    m_dateCreated,
                    m_userCreated,
                    m_dateLastModified,
                    m_userLastModified,
                    m_dateReleased,
                    m_dateExpired,
                    1,
                    size,
                    System.currentTimeMillis(),
                    0);

                if (m_properties == null) {
                    m_properties = new HashMap<String, CmsProperty>();
                }

                if (m_type.isFolder() || resourceIdWasNull || hasContentInVfsOrImport(resource)) {
                    // import this resource in the VFS
                    m_resource = getCms().importResource(
                        translatedName,
                        resource,
                        content,
                        new ArrayList<CmsProperty>(m_properties.values()));
                }

                // only set permissions if the resource did not exists or if the keep permissions flag is not set
                m_importACEs = (m_resource != null) && (!exists || !m_parameters.isKeepPermissions());

                if (m_resource != null) {
                    getReport().println(
                        org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                        I_CmsReport.FORMAT_OK);

                    if (OpenCms.getResourceManager().getResourceType(
                        m_resource.getTypeId()) instanceof I_CmsLinkParseable) {
                        // store for later use
                        m_parseables.add(m_resource);
                    }
                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_IMPORTING_4,
                                new Object[] {
                                    String.valueOf(m_fileCounter),
                                    String.valueOf(m_totalFiles),
                                    translatedName,
                                    m_destination}));
                    }
                } else {
                    // resource import failed, since no CmsResource was created
                    getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    getReport().println(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));

                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_SKIPPING_3,
                                String.valueOf(m_fileCounter),
                                String.valueOf(m_totalFiles),
                                translatedName));
                    }
                }
            } else {
                m_resource = null;
                // skip the file import, just print out the information to the report
                getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                getReport().println(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_ARGUMENT_1,
                        translatedName));

                if (LOG.isInfoEnabled()) {
                    LOG.info(
                        Messages.get().getBundle().key(
                            Messages.LOG_SKIPPING_3,
                            String.valueOf(m_fileCounter),
                            String.valueOf(m_totalFiles),
                            translatedName));
                }
                // do not import ACEs
                m_importACEs = false;
            }
        } catch (Exception e) {
            m_resource = null;
            m_importACEs = false;

            getReport().println(e);
            getReport().addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            return;
        } finally {
            m_structureId = null;
            m_resourceId = null;
            m_destination = null;
            m_source = null;
            m_type = null;
            m_flags = 0;
            m_dateCreated = 0;
            m_dateLastModified = 0;
            m_dateReleased = CmsResource.DATE_RELEASED_DEFAULT;
            m_dateExpired = CmsResource.DATE_EXPIRED_DEFAULT;
            m_properties = null;
            m_throwable = null;
            m_aces = null;
            m_properties = null;
        }
    }
991695
@SuppressWarnings("unchecked")
    protected void readResourcesFromManifest() throws CmsImportExportException {

        String source = null, destination = null, uuidstructure = null, uuidresource = null, userlastmodified = null,
        usercreated = null, flags = null, timestamp = null;
        long datelastmodified = 0, datecreated = 0, datereleased = 0, dateexpired = 0;

        List<Node> fileNodes = null, acentryNodes = null;
        Element currentElement = null, currentEntry = null;
        List<CmsProperty> properties = null;

        // get list of immutable resources
        List<String> immutableResources = OpenCms.getImportExportManager().getImmutableResources();
        if (immutableResources == null) {
            immutableResources = Collections.emptyList();
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(
                Messages.get().getBundle().key(
                    Messages.LOG_IMPORTEXPORT_IMMUTABLE_RESOURCES_SIZE_1,
                    Integer.toString(immutableResources.size())));
        }
        // get list of ignored properties
        List<String> ignoredProperties = OpenCms.getImportExportManager().getIgnoredProperties();
        if (ignoredProperties == null) {
            ignoredProperties = Collections.emptyList();
        }

        // get the desired page type for imported pages
        m_convertToXmlPage = OpenCms.getImportExportManager().convertToXmlPage();

        try {
            // get all file-nodes
            fileNodes = m_docXml.selectNodes("//" + A_CmsImport.N_FILE);
            int importSize = fileNodes.size();

            // walk through all files in manifest
            for (int i = 0; i < fileNodes.size(); i++) {
                m_report.print(
                    org.opencms.report.Messages.get().container(
                        org.opencms.report.Messages.RPT_SUCCESSION_2,
                        String.valueOf(i + 1),
                        String.valueOf(importSize)),
                    I_CmsReport.FORMAT_NOTE);
                currentElement = (Element)fileNodes.get(i);

                // <source>
                source = getChildElementTextValue(currentElement, A_CmsImport.N_SOURCE);
                // <destination>
                destination = getChildElementTextValue(currentElement, A_CmsImport.N_DESTINATION);

                // <type>
                String typeName = getChildElementTextValue(currentElement, A_CmsImport.N_TYPE);
                I_CmsResourceType type;
                try {
                    type = OpenCms.getResourceManager().getResourceType(typeName);
                } catch (CmsLoaderException e) {
                    int plainId;
                    try {
                        plainId = OpenCms.getResourceManager().getResourceType(
                            CmsResourceTypePlain.getStaticTypeName()).getTypeId();
                    } catch (CmsLoaderException e1) {
                        // this should really never happen
                        plainId = CmsResourceTypePlain.getStaticTypeId();
                    }
                    type = OpenCms.getResourceManager().getResourceType(plainId);
                }

                // <uuidstructure>
                uuidstructure = getChildElementTextValue(currentElement, A_CmsImport.N_UUIDSTRUCTURE);

                // <uuidresource>
                if (!type.isFolder()) {
                    uuidresource = getChildElementTextValue(currentElement, A_CmsImport.N_UUIDRESOURCE);
                } else {
                    uuidresource = null;
                }

                // <datelastmodified>
                timestamp = getChildElementTextValue(currentElement, A_CmsImport.N_DATELASTMODIFIED);
                if (timestamp != null) {
                    datelastmodified = convertTimestamp(timestamp);
                } else {
                    datelastmodified = System.currentTimeMillis();
                }

                // <userlastmodified>
                userlastmodified = getChildElementTextValue(currentElement, A_CmsImport.N_USERLASTMODIFIED);
                userlastmodified = OpenCms.getImportExportManager().translateUser(userlastmodified);

                // <datecreated>
                timestamp = getChildElementTextValue(currentElement, A_CmsImport.N_DATECREATED);
                if (timestamp != null) {
                    datecreated = convertTimestamp(timestamp);
                } else {
                    datecreated = System.currentTimeMillis();
                }

                // <usercreated>
                usercreated = getChildElementTextValue(currentElement, A_CmsImport.N_USERCREATED);
                usercreated = OpenCms.getImportExportManager().translateUser(usercreated);

                // <datereleased>
                timestamp = getChildElementTextValue(currentElement, A_CmsImport.N_DATERELEASED);
                if (timestamp != null) {
                    datereleased = convertTimestamp(timestamp);
                } else {
                    datereleased = CmsResource.DATE_RELEASED_DEFAULT;
                }

                // <dateexpired>
                timestamp = getChildElementTextValue(currentElement, A_CmsImport.N_DATEEXPIRED);
                if (timestamp != null) {
                    dateexpired = convertTimestamp(timestamp);
                } else {
                    dateexpired = CmsResource.DATE_EXPIRED_DEFAULT;
                }

                // <flags>
                flags = getChildElementTextValue(currentElement, A_CmsImport.N_FLAGS);

                // apply name translation and import path
                String translatedName = m_cms.getRequestContext().addSiteRoot(m_importPath + destination);
                if (type.isFolder()) {
                    // ensure folders end with a "/"
                    if (!CmsResource.isFolder(translatedName)) {
                        translatedName += "/";
                    }
                }

                // check if this resource is immutable
                boolean resourceNotImmutable = checkImmutable(translatedName, immutableResources);
                translatedName = m_cms.getRequestContext().removeSiteRoot(translatedName);
                // if the resource is not immutable and not on the exclude list, import it
                if (resourceNotImmutable) {
                    // print out the information to the report
                    m_report.print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE);
                    m_report.print(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));
                    m_report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));
                    // get all properties
                    properties = readPropertiesFromManifest(currentElement, ignoredProperties);

                    boolean exists = m_cms.existsResource(translatedName, CmsResourceFilter.ALL);

                    // import the resource
                    CmsResource res = importResource(
                        source,
                        translatedName,
                        type,
                        uuidstructure,
                        uuidresource,
                        datelastmodified,
                        userlastmodified,
                        datecreated,
                        usercreated,
                        datereleased,
                        dateexpired,
                        flags,
                        properties);

                    if (res != null) {
                        // only set permissions if the resource did not exists or if the keep permissions flag is not set
                        if (!exists || !m_keepPermissions) {
                            // if the resource was imported add the access control entries if available
                            List<CmsAccessControlEntry> aceList = new ArrayList<CmsAccessControlEntry>();

                            // write all imported access control entries for this file
                            acentryNodes = currentElement.selectNodes("*/" + A_CmsImport.N_ACCESSCONTROL_ENTRY);

                            // collect all access control entries
                            for (int j = 0; j < acentryNodes.size(); j++) {
                                currentEntry = (Element)acentryNodes.get(j);

                                // get the data of the access control entry
                                String id = getChildElementTextValue(
                                    currentEntry,
                                    A_CmsImport.N_ACCESSCONTROL_PRINCIPAL);
                                String principalId = new CmsUUID().toString();
                                String principal = id.substring(id.indexOf('.') + 1, id.length());

                                try {
                                    if (id.startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) {
                                        principal = OpenCms.getImportExportManager().translateGroup(principal);
                                        principalId = m_cms.readGroup(principal).getId().toString();
                                    } else if (id.startsWith(I_CmsPrincipal.PRINCIPAL_USER)) {
                                        principal = OpenCms.getImportExportManager().translateUser(principal);
                                        principalId = m_cms.readUser(principal).getId().toString();
                                    } else if (id.startsWith(CmsRole.PRINCIPAL_ROLE)) {
                                        principalId = CmsRole.valueOfRoleName(principal).getId().toString();
                                    } else if (id.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) {
                                        principalId = CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID.toString();
                                    } else if (id.equalsIgnoreCase(
                                        CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) {
                                        principalId = CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID.toString();
                                    } else {
                                        if (LOG.isWarnEnabled()) {
                                            LOG.warn(
                                                Messages.get().getBundle().key(
                                                    Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
                                                    id));
                                        }
                                    }

                                    String acflags = getChildElementTextValue(currentEntry, A_CmsImport.N_FLAGS);

                                    String allowed = ((Element)currentEntry.selectNodes("./"
                                        + A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
                                        + "/"
                                        + A_CmsImport.N_ACCESSCONTROL_ALLOWEDPERMISSIONS).get(0)).getTextTrim();

                                    String denied = ((Element)currentEntry.selectNodes("./"
                                        + A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
                                        + "/"
                                        + A_CmsImport.N_ACCESSCONTROL_DENIEDPERMISSIONS).get(0)).getTextTrim();

                                    // add the entry to the list
                                    aceList.add(
                                        getImportAccessControlEntry(res, principalId, allowed, denied, acflags));
                                } catch (CmsException e) {
                                    // user or group of ACE might not exist in target system, ignore ACE
                                    if (LOG.isWarnEnabled()) {
                                        LOG.warn(
                                            Messages.get().getBundle().key(
                                                Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
                                                translatedName),
                                            e);
                                    }
                                    m_report.println(e);
                                    m_report.addError(e);
                                }
                            }
                            importAccessControlEntries(res, aceList);
                        }

                        // Add the relations for the resource
                        importRelations(res, currentElement);

                        if (OpenCms.getResourceManager().getResourceType(
                            res.getTypeId()) instanceof I_CmsLinkParseable) {
                            // store for later use
                            m_parseables.add(res);
                        }

                        if (LOG.isInfoEnabled()) {
                            LOG.info(
                                Messages.get().getBundle().key(
                                    Messages.LOG_IMPORTING_4,
                                    new Object[] {
                                        String.valueOf(i + 1),
                                        String.valueOf(importSize),
                                        translatedName,
                                        destination}));
                        }
                    } else {
                        // resource import failed, since no CmsResource was created
                        m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                        m_report.println(
                            org.opencms.report.Messages.get().container(
                                org.opencms.report.Messages.RPT_ARGUMENT_1,
                                translatedName));

                        if (LOG.isInfoEnabled()) {
                            LOG.info(
                                Messages.get().getBundle().key(
                                    Messages.LOG_SKIPPING_3,
                                    String.valueOf(i + 1),
                                    String.valueOf(importSize),
                                    translatedName));
                        }
                    }

                } else {
                    // skip the file import, just print out the information to the report

                    m_report.print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE);
                    m_report.println(
                        org.opencms.report.Messages.get().container(
                            org.opencms.report.Messages.RPT_ARGUMENT_1,
                            translatedName));

                    if (LOG.isInfoEnabled()) {
                        LOG.info(
                            Messages.get().getBundle().key(
                                Messages.LOG_SKIPPING_3,
                                String.valueOf(i + 1),
                                String.valueOf(importSize),
                                translatedName));
                    }
                }
            }
        } catch (Exception e) {
            m_report.println(e);
            m_report.addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }

            throw new CmsImportExportException(message, e);
        }
    }
874260
@SuppressWarnings("squid:S2083")
  @PostMapping("/importByUrl")
  @ResponseBody
  public ResponseEntity<String> importFileByUrl(
      HttpServletRequest request,
      @RequestParam("url") String url,
      @RequestParam(value = "entityTypeId", required = false) String entityTypeId,
      @RequestParam(value = "packageId", required = false) String packageId,
      @RequestParam(value = "metadataAction", required = false) String metadataAction,
      @RequestParam(value = "action", required = false) String action,
      @RequestParam(value = "notify", required = false) Boolean notify)
      throws URISyntaxException {
    ImportRun importRun;
    try {
      File tmpFile = fileLocationToStoredRenamedFile(url, entityTypeId);
      if (packageId != null && !dataService.getMeta().getPackage(packageId).isPresent()) {
        return ResponseEntity.badRequest()
            .contentType(TEXT_PLAIN)
            .body(MessageFormat.format("Package [{0}] does not exist.", packageId));
      }
      importRun = importFile(request, tmpFile, metadataAction, action, notify, packageId);
    } catch (Exception e) {
      LOG.error(e.getMessage());
      return ResponseEntity.badRequest().contentType(TEXT_PLAIN).body(e.getMessage());
    }
    return createCreatedResponseEntity(importRun);
  }
154800
private void createResources(CmsUploadListener listener) throws CmsException, UnsupportedEncodingException {

        CmsObject cms = getCmsObject();
        String[] isRootPathVals = m_parameterMap.get(I_CmsUploadConstants.UPLOAD_IS_ROOT_PATH_FIELD_NAME);
        if ((isRootPathVals != null) && (isRootPathVals.length > 0) && Boolean.parseBoolean(isRootPathVals[0])) {
            cms = m_rootCms;
        }
        // get the target folder
        String targetFolder = getTargetFolder(cms);
        m_uploadHook = OpenCms.getWorkplaceManager().getUploadHook(cms, targetFolder);

        List<String> filesToUnzip = getFilesToUnzip();

        // iterate over the list of files to upload and create each single resource
        for (FileItem fileItem : m_multiPartFileItems) {
            if ((fileItem != null) && (!fileItem.isFormField())) {
                // read the content of the file
                byte[] content = fileItem.get();
                fileItem.delete();

                // determine the new resource name
                String fileName = m_parameterMap.get(
                    fileItem.getFieldName() + I_CmsUploadConstants.UPLOAD_FILENAME_ENCODED_SUFFIX)[0];
                fileName = URLDecoder.decode(fileName, "UTF-8");

                if (filesToUnzip.contains(CmsResource.getName(fileName.replace('\\', '/')))) {
                    // import the zip
                    CmsImportFolder importZip = new CmsImportFolder();
                    try {
                        importZip.importZip(content, targetFolder, cms, false);
                    } finally {
                        // get the created resource names
                        for (CmsResource importedResource : importZip.getImportedResources()) {
                            m_resourcesCreated.put(
                                importedResource.getStructureId().toString(),
                                importedResource.getName());
                        }
                    }
                } else {
                    // create the resource
                    CmsResource importedResource = createSingleResource(cms, fileName, targetFolder, content);
                    // add the name of the created resource to the list of successful created resources
                    m_resourcesCreated.put(importedResource.getStructureId().toString(), importedResource.getName());
                }

                if (listener.isCanceled()) {
                    throw listener.getException();
                }
            }
        }
    }
361207
public void importRelations(CmsObject cms) throws CmsException {

        for (CmsResourceImportData resData : m_moduleData.getResourceData()) {
            if (!resData.getRelations().isEmpty()) {
                CmsResource importResource = resData.getImportResource();
                if (importResource != null) {
                    importResource = cms.readResource(importResource.getStructureId(), CmsResourceFilter.ALL);
                    updateRelations(cms, importResource, resData.getRelations());
                }
            }
        }

    }
9055
public void importOrgUnit() {

        try {
            if (m_throwable != null) {
                getReport().println(m_throwable);
                getReport().addError(m_throwable);

                CmsMessageContainer message = Messages.get().container(
                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_ORGUNITS_0);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(message.key(), m_throwable);
                }
                m_throwable = null;
                m_orgUnit = null;

                return;
            }

            getReport().print(Messages.get().container(Messages.RPT_IMPORT_ORGUNIT_0), I_CmsReport.FORMAT_NOTE);
            getReport().print(
                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, m_orgUnitName));
            getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

            try {
                m_orgUnit = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_orgUnitName);
                // the organizational unit already exists and will not be created
                getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK);
                m_orgUnitResources.remove(m_orgUnitName);
                return;
            } catch (CmsDataAccessException e) {
                // ok, continue creating the ou
            }

            // get the resources that already exist for the organizational unit
            // if there are resources that does not exist jet, there will be a second try after importing resources
            List<CmsResource> resources = new ArrayList<CmsResource>();
            String site = getCms().getRequestContext().getSiteRoot();
            try {
                getCms().getRequestContext().setSiteRoot("");

                boolean remove = true;
                List<String> ouResources = CmsCollectionsGenericWrapper.list(m_orgUnitResources.get(m_orgUnitName));
                if (ouResources != null) {
                    Iterator<String> itResNames = ouResources.iterator();
                    while (itResNames.hasNext()) {
                        String resName = itResNames.next();
                        try {
                            resources.add(getCms().readResource(resName, CmsResourceFilter.ALL));
                            itResNames.remove();
                        } catch (CmsVfsResourceNotFoundException e) {
                            // resource does not exist yet, skip it for now
                            remove = false;
                        }
                    }
                }

                if (remove) {
                    m_orgUnitResources.remove(m_orgUnitName);
                }
            } finally {
                getCms().getRequestContext().setSiteRoot(site);
            }

            // if no resource available
            if (resources.isEmpty()) {
                // meanwhile use the first one of the parent organizational unit
                resources.add(
                    OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(
                        getCms(),
                        CmsOrganizationalUnit.getParentFqn(m_orgUnitName)).get(0));
            }

            // create the organizational unit with a dummy resource, which will be corrected later
            m_orgUnit = OpenCms.getOrgUnitManager().createOrganizationalUnit(
                getCms(),
                m_orgUnitName,
                m_orgUnitDescription,
                m_orgUnitFlags,
                resources.get(0).getRootPath());
            for (int i = 1; i < resources.size(); i++) {
                OpenCms.getOrgUnitManager().addResourceToOrgUnit(
                    getCms(),
                    m_orgUnitName,
                    resources.get(i).getRootPath());
            }

            getReport().println(
                org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                I_CmsReport.FORMAT_OK);
        } catch (CmsException e) {
            getReport().println(e);
            getReport().addError(e);

            CmsMessageContainer message = Messages.get().container(
                Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_ORGUNITS_0);
            if (LOG.isDebugEnabled()) {
                LOG.debug(message.key(), e);
            }
            m_throwable = null;
            m_orgUnit = null;
        } finally {
            m_orgUnitName = null;
            m_orgUnitDescription = null;
            m_orgUnitFlags = 0;
        }

    }