Class CmsLocaleGroupService

java.lang.Object
org.opencms.i18n.CmsLocaleGroupService

public class CmsLocaleGroupService extends 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.
  • Constructor Details

  • Method Details

    • getPossibleLocales

      public static List<Locale> getPossibleLocales(CmsObject cms, CmsResource currentResource)
      Helper method for getting the possible locales for a resource.

      Parameters:
      cms - the CMS context
      currentResource - 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 add
      primaryPage - 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 resource
      second - 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 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.

      Parameters:
      firstResource - a resource
      secondResource - 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 resource
      secondPage - 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

      public Locale getMainLocale(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

      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