org.opencms.db
Class CmsAliasManager

java.lang.Object
  extended by org.opencms.db.CmsAliasManager

public class CmsAliasManager
extends java.lang.Object

The alias manager provides access to the aliases stored in the database.


Field Summary
protected  CmsSecurityManager m_securityManager
          The security manager for accessing the database.
 
Constructor Summary
CmsAliasManager(CmsSecurityManager securityManager)
          Creates a new alias manager instance.
 
Method Summary
protected  void checkPermissionsForMassEdit(CmsObject cms)
          Checks whether the current user has the permissions to mass edit the alias table, and throws an exception otherwise.
 java.util.List<CmsAlias> getAliasesForPath(CmsObject cms, java.lang.String siteRoot, java.lang.String aliasPath)
          Gets the list of aliases for a path in a given site.
 java.util.List<CmsAlias> getAliasesForSite(CmsObject cms, java.lang.String siteRoot)
          Gets the list of aliases for a given site root.
 java.util.List<CmsAlias> getAliasesForStructureId(CmsObject cms, CmsUUID structureId)
          Gets the aliases for a given structure id.
 java.util.List<CmsRewriteAlias> getRewriteAliases(CmsObject cms, java.lang.String siteRoot)
          Reads the rewrite aliases for a given site root.
 CmsRewriteAliasMatcher getRewriteAliasMatcher(CmsObject cms, java.lang.String siteRoot)
          Gets the rewrite alias matcher for the given site.
 boolean hasPermissionsForMassEdit(CmsObject cms, java.lang.String siteRoot)
          Checks whether the current user has permissions for mass editing the alias table.
protected  CmsAliasImportResult importAlias(CmsObject cms, java.lang.String siteRoot, java.lang.String aliasPath, java.lang.String vfsPath, CmsAliasMode mode)
          Imports a single alias.
 java.util.List<CmsAliasImportResult> importAliases(CmsObject cms, byte[] aliasData, java.lang.String siteRoot, java.lang.String separator)
          Imports alias CSV data.
protected  CmsAliasImportResult processAliasImport(CmsObject cms, java.lang.String siteRoot, java.lang.String aliasPath, java.lang.String vfsPath, CmsAliasMode mode)
          Processes a single alias import operation which has already been parsed into fields.
protected  CmsAliasImportResult processAliasLine(CmsObject cms, java.lang.String siteRoot, java.lang.String line, java.lang.String separator)
          Processes a line from a CSV file containing the alias data to be imported.
 void saveAliases(CmsObject cms, CmsUUID structureId, java.util.List<CmsAlias> aliases)
          Saves the aliases for a given structure id, completely replacing any existing aliases for the same structure id.
 void saveRewriteAliases(CmsObject cms, java.lang.String siteRoot, java.util.List<CmsRewriteAlias> newAliases)
          Saves the rewrite alias for a given site root.
 void updateAliases(CmsObject cms, java.util.Collection<CmsAlias> toDelete, java.util.Collection<CmsAlias> toAdd)
          Updates the aliases in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_securityManager

protected CmsSecurityManager m_securityManager
The security manager for accessing the database.

Constructor Detail

CmsAliasManager

public CmsAliasManager(CmsSecurityManager securityManager)
Creates a new alias manager instance.

Parameters:
securityManager - the security manager
Method Detail

getAliasesForPath

public java.util.List<CmsAlias> getAliasesForPath(CmsObject cms,
                                                  java.lang.String siteRoot,
                                                  java.lang.String aliasPath)
                                           throws CmsException
Gets the list of aliases for a path in a given site.

This should only return either an empty list or a list with a single element.

Parameters:
cms - the current CMS context
siteRoot - the site root for which we want the aliases
aliasPath - the alias path
Returns:
the aliases for the given site root and path
Throws:
CmsException - if something goes wrong

getAliasesForSite

public java.util.List<CmsAlias> getAliasesForSite(CmsObject cms,
                                                  java.lang.String siteRoot)
                                           throws CmsException
Gets the list of aliases for a given site root.

Parameters:
cms - the current CMS context
siteRoot - the site root
Returns:
the list of aliases for the given site
Throws:
CmsException - if something goes wrong

getAliasesForStructureId

public java.util.List<CmsAlias> getAliasesForStructureId(CmsObject cms,
                                                         CmsUUID structureId)
                                                  throws CmsException
Gets the aliases for a given structure id.

Parameters:
cms - the current CMS context
structureId - the structure id of a resource
Returns:
the aliases which point to the resource with the given structure id
Throws:
CmsException - if something goes wrong

getRewriteAliases

public java.util.List<CmsRewriteAlias> getRewriteAliases(CmsObject cms,
                                                         java.lang.String siteRoot)
                                                  throws CmsException
Reads the rewrite aliases for a given site root.

Parameters:
cms - the current CMS context
siteRoot - the site root for which the rewrite aliases should be retrieved
Returns:
the list of rewrite aliases for the given site root
Throws:
CmsException - if something goes wrong

getRewriteAliasMatcher

public CmsRewriteAliasMatcher getRewriteAliasMatcher(CmsObject cms,
                                                     java.lang.String siteRoot)
                                              throws CmsException
Gets the rewrite alias matcher for the given site.

Parameters:
cms - the CMS context to use
siteRoot - the site root
Returns:
the alias matcher for the site with the given site root
Throws:
CmsException - if something goes wrong

hasPermissionsForMassEdit

public boolean hasPermissionsForMassEdit(CmsObject cms,
                                         java.lang.String siteRoot)
Checks whether the current user has permissions for mass editing the alias table.

Parameters:
cms - the current CMS context
siteRoot - the site root to check
Returns:
true if the user from the CMS context is allowed to mass edit the alias table

importAliases

public java.util.List<CmsAliasImportResult> importAliases(CmsObject cms,
                                                          byte[] aliasData,
                                                          java.lang.String siteRoot,
                                                          java.lang.String separator)
                                                   throws java.lang.Exception
Imports alias CSV data.

Parameters:
cms - the current CMS context
aliasData - the alias data
siteRoot - the root of the site into which the alias data should be imported
separator - the field separator which is used by the imported data
Returns:
the list of import results
Throws:
java.lang.Exception - if something goes wrong

saveAliases

public void saveAliases(CmsObject cms,
                        CmsUUID structureId,
                        java.util.List<CmsAlias> aliases)
                 throws CmsException
Saves the aliases for a given structure id, completely replacing any existing aliases for the same structure id.

Parameters:
cms - the current CMS context
structureId - the structure id of a resource
aliases - the list of aliases which should be written
Throws:
CmsException - if something goes wrong

saveRewriteAliases

public void saveRewriteAliases(CmsObject cms,
                               java.lang.String siteRoot,
                               java.util.List<CmsRewriteAlias> newAliases)
                        throws CmsException
Saves the rewrite alias for a given site root.

Parameters:
cms - the current CMS context
siteRoot - the site root for which the rewrite aliases should be saved
newAliases - the list of aliases to save
Throws:
CmsException - if something goes wrong

updateAliases

public void updateAliases(CmsObject cms,
                          java.util.Collection<CmsAlias> toDelete,
                          java.util.Collection<CmsAlias> toAdd)
                   throws CmsException
Updates the aliases in the database.

Parameters:
cms - the current CMS context
toDelete - the collection of aliases to delete
toAdd - the collection of aliases to add
Throws:
CmsException - if something goes wrong

checkPermissionsForMassEdit

protected void checkPermissionsForMassEdit(CmsObject cms)
                                    throws CmsException
Checks whether the current user has the permissions to mass edit the alias table, and throws an exception otherwise.

Parameters:
cms - the current CMS context
Throws:
CmsException

importAlias

protected CmsAliasImportResult importAlias(CmsObject cms,
                                           java.lang.String siteRoot,
                                           java.lang.String aliasPath,
                                           java.lang.String vfsPath,
                                           CmsAliasMode mode)
                                    throws CmsException
Imports a single alias.

Parameters:
cms - the current CMS context
siteRoot - the site root
aliasPath - the alias path
vfsPath - the VFS path
mode - the alias mode
Returns:
the result of the import
Throws:
CmsException - if something goes wrong

processAliasImport

protected CmsAliasImportResult processAliasImport(CmsObject cms,
                                                  java.lang.String siteRoot,
                                                  java.lang.String aliasPath,
                                                  java.lang.String vfsPath,
                                                  CmsAliasMode mode)
Processes a single alias import operation which has already been parsed into fields.

Parameters:
cms - the current CMS context
siteRoot - the site root
aliasPath - the alias path
vfsPath - the VFS resource path
mode - the alias mode
Returns:
the result of the import operation

processAliasLine

protected CmsAliasImportResult processAliasLine(CmsObject cms,
                                                java.lang.String siteRoot,
                                                java.lang.String line,
                                                java.lang.String separator)
Processes a line from a CSV file containing the alias data to be imported.

Parameters:
cms - the current CMS context
siteRoot - the site root
line - the line with the data to import
separator - the field separator
Returns:
the import result