Class CmsLocaleGroupService
- java.lang.Object
-
- org.opencms.i18n.CmsLocaleGroupService
-
public class CmsLocaleGroupService extends java.lang.Object
Helper class for manipulating locale groups.A locale group is a construct used to group pages which are translations of each other. * A locale group consists of a set of resources connected by relations in the following way:
- There is a primary resource and a set of secondary resources.
- Each secondary resource has a relation to the primary resource of type LOCALE_VARIANT.
- Ideally, each resource has a different locale.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsLocaleGroupService.Status
Enum representing whether two resources can be linked together in a locale group.
-
Constructor Summary
Constructors Constructor Description CmsLocaleGroupService(CmsObject cms)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attachLocaleGroup(CmsResource secondaryPage, CmsResource primaryPage)
Adds a resource to a locale group.void
attachLocaleGroupIndirect(CmsResource first, CmsResource second)
Smarter method to connect a resource to a locale group.CmsLocaleGroupService.Status
checkLinkable(CmsResource firstResource, CmsResource secondResource)
Checks if the two resources are linkable as locale variants and returns an appropriate statusvoid
detachLocaleGroup(CmsResource firstPage, CmsResource secondPage)
Removes a locale group relation between two resources.CmsResource
findLocalizationRoot(CmsResource resource)
Tries to find the 'best' localized subsitemap parent folder for a resource.protected CmsResource
getDefaultFileOrSelf(CmsResource res)
Helper method for reading the default file of a folder.java.util.Locale
getMainLocale(java.lang.String rootPath)
Gets the main translation locale configured for the given root path.static java.util.List<java.util.Locale>
getPossibleLocales(CmsObject cms, CmsResource currentResource)
Helper method for getting the possible locales for a resource.CmsLocaleGroup
readDefaultFileLocaleGroup(CmsResource resource)
Reads the locale group of a default file.CmsLocaleGroup
readLocaleGroup(CmsResource resource)
Reads a locale group from the VFS.
-
-
-
Constructor Detail
-
CmsLocaleGroupService
public CmsLocaleGroupService(CmsObject cms)
Creates a new instance.- Parameters:
cms
- the CMS context to use
-
-
Method Detail
-
getPossibleLocales
public static java.util.List<java.util.Locale> getPossibleLocales(CmsObject cms, CmsResource currentResource)
Helper method for getting the possible locales for a resource.- Parameters:
cms
- the CMS contextcurrentResource
- the resource- Returns:
- the possible locales for a resource
-
attachLocaleGroup
public void attachLocaleGroup(CmsResource secondaryPage, CmsResource primaryPage) throws CmsException
Adds a resource to a locale group.Note: This is a low level method that is hard to use correctly. Please use attachLocaleGroupIndirect if at all possible.
- Parameters:
secondaryPage
- the page to addprimaryPage
- the primary resource of the locale group which the resource should be added to- Throws:
CmsException
- if something goes wrong
-
attachLocaleGroupIndirect
public void attachLocaleGroupIndirect(CmsResource first, CmsResource second) throws CmsException
Smarter method to connect a resource to a locale group.Exactly one of the resources given as an argument must represent a locale group, while the other should be the locale that you wish to attach to the locale group.
- Parameters:
first
- a resourcesecond
- a resource- Throws:
CmsException
- if something goes wrong
-
checkLinkable
public CmsLocaleGroupService.Status checkLinkable(CmsResource firstResource, CmsResource secondResource)
Checks if the two resources are linkable as locale variants and returns an appropriate statusThis is the case if exactly one of the resources represents a locale group, the locale of the other resource is not already present in the locale group, and if some other permission / validity checks are passed.
- Parameters:
firstResource
- a resourcesecondResource
- a resource- Returns:
- the result of the linkability check
-
detachLocaleGroup
public void detachLocaleGroup(CmsResource firstPage, CmsResource secondPage) throws CmsException
Removes a locale group relation between two resources.- Parameters:
firstPage
- the first resourcesecondPage
- the second resource- Throws:
CmsException
- if something goes wrong
-
findLocalizationRoot
public CmsResource findLocalizationRoot(CmsResource resource) throws CmsException
Tries to find the 'best' localized subsitemap parent folder for a resource.This is used when we use locale group dialogs outside the sitemap editor, so we don't have a clearly defined 'root resource' - this method is used to find a replacement for the root resource which we would have in the sitemap editor.
- Parameters:
resource
- the resource for which to find the localization root- Returns:
- the localization root
- Throws:
CmsException
- if something goes wrong
-
getMainLocale
public java.util.Locale getMainLocale(java.lang.String rootPath)
Gets the main translation locale configured for the given root path.- Parameters:
rootPath
- a root path- Returns:
- the main translation locale configured for the given path, or null if none was found
-
readDefaultFileLocaleGroup
public CmsLocaleGroup readDefaultFileLocaleGroup(CmsResource resource) throws CmsException
Reads the locale group of a default file.- Parameters:
resource
- a resource which might be a folder or a file- Returns:
- the locale group corresponding to the default file
- Throws:
CmsException
- if something goes wrong
-
readLocaleGroup
public CmsLocaleGroup readLocaleGroup(CmsResource resource) throws CmsException
Reads a locale group from the VFS.- Parameters:
resource
- the resource for which to read the locale group- Returns:
- the locale group for the resource
- Throws:
CmsException
- if something goes wrong
-
getDefaultFileOrSelf
protected CmsResource getDefaultFileOrSelf(CmsResource res)
Helper method for reading the default file of a folder.If the resource given already is a file, it will be returned, otherwise the default file (or null, if none exists) of the folder will be returned.
- Parameters:
res
- the resource whose default file to read- Returns:
- the default file
-
-