Class 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.
    The point of the primary resource is to act as a 'master' resource which translators then use to translate to different locales.
    • 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.

        cms - the CMS context
        currentResource - the resource
        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.

        secondaryPage - the page to add
        primaryPage - the primary resource of the locale group which the resource should be added to
        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.

        first - a resource
        second - a resource
        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 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.

        firstResource - a resource
        secondResource - a resource
        the result of the linkability check
      • 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.

        resource - the resource for which to find the localization root
        the localization root
        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.

        rootPath - a root path
        the main translation locale configured for the given path, or null if none was found
      • 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.

        res - the resource whose default file to read
        the default file