public class CmsLocaleGroupService extends java.lang.Object
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:
Modifier and Type | Class and Description |
---|---|
static class |
CmsLocaleGroupService.Status
Enum representing whether two resources can be linked together in a locale group.
|
Constructor and Description |
---|
CmsLocaleGroupService(CmsObject cms)
Creates a new instance.
|
Modifier and Type | Method and 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 status
This 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.
|
void |
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.
|
public CmsLocaleGroupService(CmsObject cms)
cms
- the CMS context to usepublic static java.util.List<java.util.Locale> getPossibleLocales(CmsObject cms, CmsResource currentResource)
cms
- the CMS contextcurrentResource
- the resourcepublic void attachLocaleGroup(CmsResource secondaryPage, CmsResource primaryPage) throws CmsException
Note: This is a low level method that is hard to use correctly. Please use attachLocaleGroupIndirect if at all possible.
secondaryPage
- the page to addprimaryPage
- the primary resource of the locale group which the resource should be added toCmsException
- if something goes wrongpublic void attachLocaleGroupIndirect(CmsResource first, CmsResource second) throws CmsException
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.
first
- a resourcesecond
- a resourceCmsException
- if something goes wrongpublic CmsLocaleGroupService.Status checkLinkable(CmsResource firstResource, CmsResource secondResource)
This 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.
firstResource
- a resourcesecondResource
- a resourcepublic void detachLocaleGroup(CmsResource firstPage, CmsResource secondPage) throws CmsException
firstPage
- the first resourcesecondPage
- the second resourceCmsException
- if something goes wrongpublic CmsResource findLocalizationRoot(CmsResource resource) throws CmsException
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.
resource
- the resource for which to find the localization rootCmsException
- if something goes wrongpublic java.util.Locale getMainLocale(java.lang.String rootPath)
rootPath
- a root pathpublic CmsLocaleGroup readDefaultFileLocaleGroup(CmsResource resource) throws CmsException
resource
- a resource which might be a folder or a fileCmsException
- if something goes wrongpublic CmsLocaleGroup readLocaleGroup(CmsResource resource) throws CmsException
resource
- the resource for which to read the locale groupCmsException
- if something goes wrongprotected CmsResource getDefaultFileOrSelf(CmsResource res)
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.
res
- the resource whose default file to read