protected synchronized CmsAliasImportResult importAlias(
        CmsObject cms,
        String siteRoot,
        String aliasPath,
        String vfsPath,
        CmsAliasMode mode)
    throws CmsException {

        CmsResource resource;
        Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
        String originalSiteRoot = cms.getRequestContext().getSiteRoot();
        try {
            cms.getRequestContext().setSiteRoot(siteRoot);
            resource = cms.readResource(vfsPath);
        } catch (CmsException e) {
            return new CmsAliasImportResult(
                CmsAliasImportStatus.aliasImportError,
                messageImportCantReadResource(locale, vfsPath),
                aliasPath,
                vfsPath,
                mode);
        } finally {
            cms.getRequestContext().setSiteRoot(originalSiteRoot);
        }
        if (!CmsAlias.ALIAS_PATTERN.matcher(aliasPath).matches()) {
            return new CmsAliasImportResult(
                CmsAliasImportStatus.aliasImportError,
                messageImportInvalidAliasPath(locale, aliasPath),
                aliasPath,
                vfsPath,
                mode);
        }
        List<CmsAlias> maybeAlias = getAliasesForPath(cms, siteRoot, aliasPath);
        if (maybeAlias.isEmpty()) {
            CmsAlias newAlias = new CmsAlias(resource.getStructureId(), siteRoot, aliasPath, mode);
            m_securityManager.addAlias(cms.getRequestContext(), newAlias);
            touch(cms, resource);
            return new CmsAliasImportResult(
                CmsAliasImportStatus.aliasNew,
                messageImportOk(locale),
                aliasPath,
                vfsPath,
                mode);
        } else {
            CmsAlias existingAlias = maybeAlias.get(0);
            CmsAliasFilter deleteFilter = new CmsAliasFilter(
                siteRoot,
                existingAlias.getAliasPath(),
                existingAlias.getStructureId());
            m_securityManager.deleteAliases(cms.getRequestContext(), deleteFilter);
            CmsAlias newAlias = new CmsAlias(resource.getStructureId(), siteRoot, aliasPath, mode);
            m_securityManager.addAlias(cms.getRequestContext(), newAlias);
            touch(cms, resource);
            return new CmsAliasImportResult(
                CmsAliasImportStatus.aliasChanged,
                messageImportUpdate(locale),
                aliasPath,
                vfsPath,
                mode);
        }
    }
protected synchronized CmsAliasImportResult importAlias ( CmsObject cms , String siteRoot , String aliasPath , String vfsPath , CmsAliasMode mode ) throws CmsException { CmsResource resource ; Locale locale = OpenCms . getWorkplaceManager ( ) . getWorkplaceLocale ( cms ) ; String originalSiteRoot = cms . getRequestContext ( ) . getSiteRoot ( ) ; try { cms . getRequestContext ( ) . setSiteRoot ( siteRoot ) ; resource = cms . readResource ( vfsPath ) ; } catch ( CmsException e ) { return new CmsAliasImportResult ( CmsAliasImportStatus . aliasImportError , messageImportCantReadResource ( locale , vfsPath ) , aliasPath , vfsPath , mode ) ; } finally { cms . getRequestContext ( ) . setSiteRoot ( originalSiteRoot ) ; } if ( ! CmsAlias . ALIAS_PATTERN . matcher ( aliasPath ) . matches ( ) ) { return new CmsAliasImportResult ( CmsAliasImportStatus . aliasImportError , messageImportInvalidAliasPath ( locale , aliasPath ) , aliasPath , vfsPath , mode ) ; } List < CmsAlias > maybeAlias = getAliasesForPath ( cms , siteRoot , aliasPath ) ; if ( maybeAlias . isEmpty ( ) ) { CmsAlias newAlias = new CmsAlias ( resource . getStructureId ( ) , siteRoot , aliasPath , mode ) ; m_securityManager . addAlias ( cms . getRequestContext ( ) , newAlias ) ; touch ( cms , resource ) ; return new CmsAliasImportResult ( CmsAliasImportStatus . aliasNew , messageImportOk ( locale ) , aliasPath , vfsPath , mode ) ; } else { CmsAlias existingAlias = maybeAlias . get ( 0 ) ; CmsAliasFilter deleteFilter = new CmsAliasFilter ( siteRoot , existingAlias . getAliasPath ( ) , existingAlias . getStructureId ( ) ) ; m_securityManager . deleteAliases ( cms . getRequestContext ( ) , deleteFilter ) ; CmsAlias newAlias = new CmsAlias ( resource . getStructureId ( ) , siteRoot , aliasPath , mode ) ; m_securityManager . addAlias ( cms . getRequestContext ( ) , newAlias ) ; touch ( cms , resource ) ; return new CmsAliasImportResult ( CmsAliasImportStatus . aliasChanged , messageImportUpdate ( locale ) , aliasPath , vfsPath , mode ) ; } }
Imports a single alias.<p>

@param cms the current CMS context
@param siteRoot the site root
@param aliasPath the alias path
@param vfsPath the VFS path
@param mode the alias mode

@return the result of the import

@throws CmsException if something goes wrong