Class CmsLocaleGroupService
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
Modifier and TypeClassDescriptionstatic enum
Enum representing whether two resources can be linked together in a locale group. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.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.findLocalizationRoot
(CmsResource resource) Tries to find the 'best' localized subsitemap parent folder for a resource.protected CmsResource
Helper method for reading the default file of a folder.getMainLocale
(String rootPath) Gets the main translation locale configured for the given root path.getPossibleLocales
(CmsObject cms, CmsResource currentResource) Helper method for getting the possible locales for a resource.readDefaultFileLocaleGroup
(CmsResource resource) Reads the locale group of a default file.readLocaleGroup
(CmsResource resource) Reads a locale group from the VFS.
-
Constructor Details
-
CmsLocaleGroupService
Creates a new instance.- Parameters:
cms
- the CMS context to use
-
-
Method Details
-
getPossibleLocales
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
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
Removes a locale group relation between two resources.- Parameters:
firstPage
- the first resourcesecondPage
- the second resource- Throws:
CmsException
- if something goes wrong
-
findLocalizationRoot
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
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
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
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
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
-