Performs the move operation for a single VFS resource.<p>

@param source the source VFS path
@param target the target VFS path
@param sitePrefix the site prefix

@throws CmsException if moving the resource fails
3875
protected void performSingleMoveOperation(String source, String target, String sitePrefix) throws CmsException {

        // calculate the target name
        String finalTarget = getCms().getRequestContext().getFileTranslator().translateResource(target);
        finalTarget = CmsLinkManager.getAbsoluteUri(finalTarget, CmsResource.getParentFolder(source));

        if (finalTarget.equals(source) || (isMultiOperation() && finalTarget.startsWith(source))) {
            throw new CmsVfsException(Messages.get().container(Messages.ERR_MOVE_ONTO_ITSELF_1, finalTarget));
        }

        try {
            CmsResource res = getCms().readResource(finalTarget, CmsResourceFilter.ALL);
            if (res.isFolder()) {
                // target folder already exists, so we add the current folder name
                if (!finalTarget.endsWith("/")) {
                    finalTarget += "/";
                }
                finalTarget = finalTarget + CmsResource.getName(source);
                if (finalTarget.endsWith("/")) {
                    finalTarget = finalTarget.substring(0, finalTarget.length() - 1);
                }
            }
        } catch (CmsVfsResourceNotFoundException e) {
            // target folder does not already exist, so target name is o.k.
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage());
            }
        }

        // set the target parameter value
        setParamTarget(finalTarget);

        // could not overwrite a resource in a move operation
        if (getCms().existsResource(finalTarget, CmsResourceFilter.ALL)) {
            // throw exception to indicate that the target exists
            throw new CmsVfsResourceAlreadyExistsException(
                Messages.get().container(
                    Messages.ERR_MOVE_FAILED_TARGET_EXISTS_2,
                    source,
                    getJsp().getRequestContext().removeSiteRoot(finalTarget)));
        }

        // lock resource if autolock is enabled
        checkLock(sitePrefix + source);
        // move the resource
        getCms().moveResource(sitePrefix + source, finalTarget);
    }
24232
public static void checkMoveToOK(Resource source, Resource target) throws IOException {
	if (!source.exists()) {
	    throw new IOException("can't move [" + source.getPath() + "] to [" + target.getPath() + "], source file does not exist");
	}
	if (source.isDirectory() && target.isFile()) throw new IOException("can't move [" + source.getPath() + "] directory to [" + target.getPath() + "], target is a file");
	if (source.isFile() && target.isDirectory()) throw new IOException("can't move [" + source.getPath() + "] file to [" + target.getPath() + "], target is a directory");
    }
108645
public function write($source, string $target): void
    {
        $source->move(\dirname($target), basename($target));
    }
744968
public static void copyResourceFile(String source, Path target) throws IOException {
        InputStream resource = FsCrawlerUtil.class.getResourceAsStream(source);
        FileUtils.copyInputStreamToFile(resource, target.toFile());
    }
1303182
public boolean run(I_CmsReport report, CmsSiteManagerImpl siteManager) {

        synchronized (LOCK) {
            // *not* using getAvailable sites here, because the result does not include sites with unpublished site folders if called with a CmsObject in the Online project
            // Instead we use getSites() and avoid duplicates using an IdentityHashMap
            IdentityHashMap<CmsSite, CmsSite> siteIdMap = new IdentityHashMap<CmsSite, CmsSite>();
            for (CmsSite site : siteManager.getSites().values()) {
                if (site.getSSLMode() == CmsSSLMode.LETS_ENCRYPT) {
                    siteIdMap.put(site, site);
                }
            }
            List<CmsSite> sites = Lists.newArrayList(siteIdMap.values());
            List<String> workplaceServers = siteManager.getWorkplaceServers(CmsSSLMode.LETS_ENCRYPT);
            return run(report, sites, workplaceServers);
        }
    }
1086591
public void actionMove() throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        try {
            boolean isFolder = false;
            String source = getResourceList().get(0);
            String target = CmsLinkManager.getAbsoluteUri(getParamTarget(), CmsResource.getParentFolder(source));
            if (!isMultiOperation()) {
                CmsResource resource = getCms().readResource(source, CmsResourceFilter.ALL);
                isFolder = resource.isFolder();
            } else {
                String siteRootFolder = null;
                CmsResource resource;
                try {
                    // check if a site root was added to the target name
                    if (OpenCms.getSiteManager().getSiteRoot(target) != null) {
                        siteRootFolder = getCms().getRequestContext().getSiteRoot();
                        if (siteRootFolder.endsWith("/")) {
                            siteRootFolder = siteRootFolder.substring(0, siteRootFolder.length() - 1);
                        }
                        getCms().getRequestContext().setSiteRoot("/");
                    }
                    resource = getCms().readResource(target, CmsResourceFilter.ALL);
                } finally {
                    if (siteRootFolder != null) {
                        getCms().getRequestContext().setSiteRoot(siteRootFolder);
                    }
                }
                if (!resource.isFolder()) {
                    // no folder selected for multi operation, throw exception
                    throw new CmsVfsException(
                        Messages.get().container(Messages.ERR_MOVE_MULTI_TARGET_NOFOLDER_1, target));
                }
            }
            if (performDialogOperation()) {
                // if no exception is caused and "true" is returned move operation was successful
                if (isMultiOperation() || isFolder) {
                    // set request attribute to reload the explorer tree view
                    List<String> folderList = new ArrayList<String>(2);
                    String sourceParent = CmsResource.getParentFolder(source);
                    folderList.add(sourceParent);
                    try {
                        String targetParent = CmsResource.getParentFolder(target);
                        if (!targetParent.equals(sourceParent)) {
                            // update target folder if its not the same as the source folder
                            folderList.add(targetParent);
                        }
                    } catch (Exception e) {
                        if (LOG.isInfoEnabled()) {
                            LOG.info(e);
                        }
                    }
                    getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
                }
                actionCloseDialog();
            } else {
                // "false" returned, display "please wait" screen
                getJsp().include(FILE_DIALOG_SCREEN_WAIT);
            }
        } catch (Throwable e) {
            // error during move, show error dialog
            includeErrorpage(this, e);
        }
    }
955610
public void setTargetForlder(CmsResource resource) {

        if (resource.isFolder()) {
            if (m_context.getResources().size() == 1) {
                try {
                    if (m_dialogMode.equals(DialogMode.copy)
                        | (m_dialogMode.equals(DialogMode.copy_and_move)
                            && CmsResource.getParentFolder(m_context.getResources().get(0).getRootPath()).equals(
                                resource.getRootPath()))) {
                        m_targetPath.setValue(getTargetName(m_context.getResources().get(0), resource));
                    } else {

                        m_targetPath.setValue(
                            getCms().getSitePath(resource) + getTargetName(m_context.getResources().get(0), resource));
                    }
                } catch (CmsException e) {
                    m_targetPath.setValue(getCms().getSitePath(resource));
                }
            } else {
                m_targetPath.setValue(getCms().getSitePath(resource));
            }

            updateDefaultActions(resource.getRootPath());
        } else {
            throw new CmsIllegalArgumentException(
                org.opencms.workplace.commons.Messages.get().container(
                    org.opencms.workplace.commons.Messages.ERR_COPY_MULTI_TARGET_NOFOLDER_1,
                    A_CmsUI.getCmsObject().getSitePath(resource)));
        }
    }
94674
private boolean hasChangedPosition(I_CmsDropTarget target) {

        if ((m_currentTarget != target) || (m_currentIndex != target.getPlaceholderIndex())) {
            m_currentTarget = target;
            m_currentIndex = target.getPlaceholderIndex();
            return true;
        }
        return false;
    }
721355
public void addSite(CmsObject cms, CmsSite site) throws CmsException {

        // check permissions
        if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_1_CORE_OBJECT) {
            // simple unit tests will have runlevel 1 and no CmsObject
            OpenCms.getRoleManager().checkRole(cms, CmsRole.DATABASE_MANAGER);
        }

        // un-freeze
        m_frozen = false;

        // set aliases and parameters, they will be used in the addSite method
        // this is necessary because of a digester workaround
        m_siteParams = site.getParameters();
        m_aliases = site.getAliases();

        String secureUrl = null;
        if (site.hasSecureServer()) {
            secureUrl = site.getSecureUrl();
        }

        // add the site
        addSite(
            site.getUrl(),
            site.getSiteRoot(),
            site.getTitle(),
            Float.toString(site.getPosition()),
            site.getErrorPage(),
            Boolean.toString(site.isWebserver()),
            site.getSSLMode().getXMLValue(),
            secureUrl,
            Boolean.toString(site.isExclusiveUrl()),
            Boolean.toString(site.isExclusiveError()),
            Boolean.toString(site.usesPermanentRedirects()));

        // re-initialize, will freeze the state when finished
        initialize(cms);
        OpenCms.writeConfiguration(CmsSitesConfiguration.class);
    }
282659
public void addSite(String site) {
		if (siteModel.getIndexOf(site) < 0) {
			siteModel.addElement(site);
			if (currentSite == null) {
				// First site added, automatically select it
				siteModel.setSelectedItem(site);
			}
		}
	}
1080213
private void updateProjectResources() throws CmsException {

        CmsObject cms = A_CmsUI.getCmsObject();
        Set<String> resourceRootPaths = getResourcePaths();
        // write the edited project resources
        CmsProject currentProject = cms.getRequestContext().getCurrentProject();
        // change the current project
        cms.getRequestContext().setCurrentProject(m_project);
        // store the current site root
        String currentSite = cms.getRequestContext().getSiteRoot();
        // copy the resources to the current project
        try {
            // switch to the root site
            cms.getRequestContext().setSiteRoot("");
            // remove deleted resources
            for (String resName : cms.readProjectResources(m_project)) {
                if (!resourceRootPaths.contains(resName)) {
                    cms.removeResourceFromProject(resName);
                }
            }
            // read project resources again!
            List<String> currentResNames = cms.readProjectResources(m_project);
            // copy missing resources
            for (String resName : resourceRootPaths) {
                if (!currentResNames.contains(resName)) {
                    cms.copyResourceToProject(resName);
                }
            }
        } finally {
            // switch back to current site and project
            cms.getRequestContext().setSiteRoot(currentSite);
            cms.getRequestContext().setCurrentProject(currentProject);
        }
    }
184855
public function move(string $sourceInterface, string $sourceName, string $targetInterface, string $targetName)
    {
        $sourceIndex = $sourceInterface . '-' . $sourceName;
        if (! isset($this->container[$sourceIndex])) {
            throw $this->unbound($sourceIndex);
        }
        $targetIndex = $targetInterface . '-' . $targetName;
        $this->container[$targetIndex] = $this->container[$sourceIndex];
        unset($this->container[$sourceIndex]);
    }
412858
@Override
    public void move(final Path source, final Path target, final CopyOption... options) throws IOException {

        // Precondition checks
        if (source == null) {
            throw new IllegalArgumentException("source must be specified");
        }
        if (target == null) {
            throw new IllegalArgumentException("target must be specified");
        }

        // Source exists?
        if (!Files.exists(source, new LinkOption[] {})) {
            throw new IllegalArgumentException("Source file doesn't exist: " + source.toString());
        }

        // If equal, NOOP
        if (source == target) {
            return;
        }

        final Archive<?> archive = this.getArchive(target);
        final Node node = archive.get(target.toString());
        // Copying to something already present?
        if (node != null) {
            final Asset asset = node.getAsset();
            // Directory
            if (asset == null) {
                // Not empty
                if (node.getChildren().size() > 0) {
                    throw new DirectoryNotEmptyException("Cannot move to non-empty directory: " + target.toString());
                }
            }
        }

        // Move
        archive.move(source.toString(), target.toString());
    }
860356
private String getTargetName(CmsResource source, CmsResource target) throws CmsException {

        String name;
        String folderRootPath = target.getRootPath();
        if (!folderRootPath.endsWith("/")) {
            folderRootPath += "/";
        }
        if (folderRootPath.equals(CmsResource.getParentFolder(source.getRootPath()))) {
            name = OpenCms.getResourceManager().getNameGenerator().getCopyFileName(
                getRootCms(),
                folderRootPath,
                source.getName());
        } else {
            name = source.getName();
        }
        return name;
    }
425480
public void changeSite(String siteRoot) {

        if (!getCmsObject().getRequestContext().getSiteRoot().equals(siteRoot)) {
            getCmsObject().getRequestContext().setSiteRoot(siteRoot);
            getWorkplaceSettings().setSite(siteRoot);
            OpenCms.getSessionManager().updateSessionInfo(getCmsObject(), getHttpSession());
        }
    }
718050
private void initWorkplaceCmsContext(CmsWorkplaceSettings settings, CmsObject cms) {

        CmsRequestContext reqCont = cms.getRequestContext();

        // check project setting
        if (!settings.getProject().equals(reqCont.getCurrentProject().getUuid())) {
            try {
                reqCont.setCurrentProject(cms.readProject(settings.getProject()));
            } catch (CmsDbEntryNotFoundException e) {
                try {
                    // project not found, set current project and settings to online project
                    reqCont.setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
                    settings.setProject(CmsProject.ONLINE_PROJECT_ID);
                } catch (CmsException ex) {
                    // log error
                    if (LOG.isInfoEnabled()) {
                        LOG.info(ex.getLocalizedMessage());
                    }
                }
            } catch (CmsException e1) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(e1.getLocalizedMessage());
                }
            }
        }

        // check site setting
        if (!(settings.getSite().equals(reqCont.getSiteRoot()))) {
            // site was switched, set new site root
            reqCont.setSiteRoot(settings.getSite());
            // removed setting explorer resource to "/" to get the stored folder
        }
    }
1220028
public function move($target, $source)
    {
        $this->copy($target, $source);

        $this->delete($target);
    }