Package com.day.cq.dam.commons.util
Class DamLanguageUtil
- java.lang.Object
-
- com.day.cq.dam.commons.util.DamLanguageUtil
-
public class DamLanguageUtil extends Object
This class provides utility method for Language Copy used by sites
-
-
Field Summary
Fields Modifier and Type Field Description static String
ATTRIBUTE_ASSET_LINKS_RELATION
static String
ATTRIBUTE_ASSET_SOURCE_RELATION
static String
ATTRIBUTE_ASSET_UPDATE_REQUIRED
static String
ATTRIBUTE_COLLECTION_SOURCE_LANGUAGE_COPY
static String
ATTRIBUTE_CQ_TRANSLATION_LAST_UPDATE
static String
CQ_LASTMODIFIED
-
Constructor Summary
Constructors Constructor Description DamLanguageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addSmartAssetUpdateFlag(Asset destinationAsset)
Deprecated.static void
addSmartAssetUpdateSource(Asset destinationAsset, String sourcePath)
static void
afterReplacingUpdatedAsset(String destinationPath, Session userSession, String prefixPath, ResourceResolver resourceResolver)
static List<String>
createLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes)
This method creates language copy of an asset/folderstatic List<String>
createLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes)
This method creates language copy of an asset/folder and its source(for example psd for jpeg).static List<String>
createLanguageCopyWithAssetRelationsForAsset(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes)
static List<String>
createLanguageCopyWithAssetRelationsForNTFolder(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes)
static String
createUpdateLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String targetLanguageCode, String prefixPath)
This method creates update language copy of an asset/folderstatic String
createUpdateLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String destinationPath, String targetLanguageCode, String prefixPath)
This method creates temporary language copy of an asset/folder and its source(for example psd for jpeg) in case temporary asset translation is required.static String
findLanguageCopyPathWithAutoCreatedRoots(String assetPath, String languageCode, ResourceResolver resolver)
static Asset
findLanguageCopyWithAutoCreatedRoots(String assetPath, String languageCode, ResourceResolver resolver)
static Resource
findLanguageCopyWithAutoCreatedRootsForAssetOrNTFolder(Resource resource, String languageCode, ResourceResolver resolver)
static ArrayList<Asset>
getAssetsFromAssociatedContent(Node contentFragmentNode, String destinationLanguage, ResourceResolver resourceResolver)
static Language
getLanguage(String path)
Deprecated.since 6.2, useLanguageUtil
insteadstatic Asset
getLanguageCopy(String assetPath, String languageCode, ResourceResolver resolver)
This method returns the Language copy asset if language copy exists, for the asked localestatic String
getLanguageDisplayName(ResourceResolver resolver, String langCode)
static String
getLanguageRoot(String path)
Deprecated.since 6.2, useLanguageUtil
insteadstatic String
getLanguageRootLocale(String path)
Returns the locale for the given path.static Collection<Resource>
getLanguageRoots(ResourceResolver resolver, String path)
Modified version of com.day.cq.wcm.core.impl.LanguageManagerImpl for Resources Returns a collection of language root pages for the given asset.static List<Asset>
getRelatedAssets(Resource resource, String relationName)
static ResourceResolver
getUserResourceResolverFromUserId(SlingRepository slingRepository, ResourceResolverFactory resolverFactory, String userId, String serviceUser)
static boolean
hasLanguageCopy(String assetPath, String languageCode, ResourceResolver resolver)
This method returns true if language copy of an asset exists, for the asked localestatic boolean
isSmartAssetUpdateRequired(Asset sourceAsset, Asset destinationAsset)
static void
moveUpdatedAsset(String sourcePath, String destinationPath, Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver)
static void
moveUpdatedAsset(String sourcePath, String destinationPath, Session userSession, PageManagerFactory pageManagerFactory, ResourceResolverFactory resolverFactory)
Deprecated.since 6.2, usemoveUpdatedAsset(String, String, Session, PageManagerFactory, ResourceResolver)
insteadstatic void
replaceUpdatedAsset(String sourcePath, String destinationPath, Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver)
Update the destination asset with all updates done on source asset.static List<String>
replaceWithExistingLanguageCopiesIfPossible(List<String> paths, String destinationLanguageCode, ResourceResolver resourceResolver)
Returns a list after replacing paths with their existing language copies.
-
-
-
Field Detail
-
ATTRIBUTE_ASSET_LINKS_RELATION
public static final String ATTRIBUTE_ASSET_LINKS_RELATION
- See Also:
- Constant Field Values
-
ATTRIBUTE_ASSET_SOURCE_RELATION
public static final String ATTRIBUTE_ASSET_SOURCE_RELATION
- See Also:
- Constant Field Values
-
ATTRIBUTE_ASSET_UPDATE_REQUIRED
public static final String ATTRIBUTE_ASSET_UPDATE_REQUIRED
- See Also:
- Constant Field Values
-
ATTRIBUTE_COLLECTION_SOURCE_LANGUAGE_COPY
public static final String ATTRIBUTE_COLLECTION_SOURCE_LANGUAGE_COPY
- See Also:
- Constant Field Values
-
CQ_LASTMODIFIED
public static final String CQ_LASTMODIFIED
- See Also:
- Constant Field Values
-
ATTRIBUTE_CQ_TRANSLATION_LAST_UPDATE
public static final String ATTRIBUTE_CQ_TRANSLATION_LAST_UPDATE
- See Also:
- Constant Field Values
-
-
Method Detail
-
hasLanguageCopy
public static boolean hasLanguageCopy(String assetPath, String languageCode, ResourceResolver resolver)
This method returns true if language copy of an asset exists, for the asked locale- Parameters:
assetPath
- The path of an asset for which language copy is askedlanguageCode
- Language for which language copy is askedresolver
- ResourceResolver- Returns:
-
getLanguageCopy
public static Asset getLanguageCopy(String assetPath, String languageCode, ResourceResolver resolver)
This method returns the Language copy asset if language copy exists, for the asked locale- Parameters:
assetPath
- The path of an asset for which language copy is askedlanguageCode
- Language for which language copy is askedresolver
- ResourceResolver- Returns:
-
createLanguageCopy
public static List<String> createLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes)
This method creates language copy of an asset/folder- Parameters:
resourceResolver
-pageManagerFactory
-sourcePath
- - source for creating language copytargetLanguageCodes
- - array of language codes- Returns:
-
getLanguageRoot
@Deprecated public static String getLanguageRoot(String path)
Deprecated.since 6.2, useLanguageUtil
insteadReturns the language root for the given asset path by only analyzing the path names starting at the root. For this implementation, language root for dam was suffix of folder name joined by "-" ex. geometrixx-en.- Parameters:
path
- path- Returns:
- the language root or
null
if not found
-
getLanguage
@Deprecated public static Language getLanguage(String path)
Deprecated.since 6.2, useLanguageUtil
insteadReturns the language for the given asset path by only analyzing the path names starting at the root. For this implementation, language root for dam was suffix of folder name joined by "-" ex. geometrixx-en.- Parameters:
path
- path- Returns:
- the language or
null
if not found
-
getLanguageRoots
public static Collection<Resource> getLanguageRoots(ResourceResolver resolver, String path)
Modified version of com.day.cq.wcm.core.impl.LanguageManagerImpl for Resources Returns a collection of language root pages for the given asset. Note that only the path names are respected for the determination of the language.- Parameters:
resolver
- resource resolverpath
- path of the current page- Returns:
- collection of language root paths
-
createUpdateLanguageCopy
public static String createUpdateLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String targetLanguageCode, String prefixPath)
This method creates update language copy of an asset/folder- Parameters:
resourceResolver
-pageManagerFactory
-sourcePath
- - source for creating language copytargetLanguageCode
- - destination language codeprefixPath
- - Root path where language copies are created- Returns:
-
moveUpdatedAsset
@Deprecated public static void moveUpdatedAsset(String sourcePath, String destinationPath, Session userSession, PageManagerFactory pageManagerFactory, ResourceResolverFactory resolverFactory)
Deprecated.since 6.2, usemoveUpdatedAsset(String, String, Session, PageManagerFactory, ResourceResolver)
instead- Parameters:
sourcePath
-destinationPath
-userSession
-pageManagerFactory
-resolverFactory
-
-
moveUpdatedAsset
public static void moveUpdatedAsset(String sourcePath, String destinationPath, Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver)
-
replaceUpdatedAsset
public static void replaceUpdatedAsset(String sourcePath, String destinationPath, Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver)
Update the destination asset with all updates done on source asset. It will not trigger Asset Processor or Update Asset workflow for the updated asset. Caller of the method should trigger Asset Processor or Update Workflow for the updated asset to create the renditions of the updated asset.- Parameters:
sourcePath
- Source Path of AssetdestinationPath
- Destination Path of AssetuserSession
- Will be used to save the session.pageManagerFactory
- Will be use to get pageManagerresourceResolver
- Will be used to get the resource
-
isSmartAssetUpdateRequired
public static boolean isSmartAssetUpdateRequired(Asset sourceAsset, Asset destinationAsset)
-
addSmartAssetUpdateFlag
@Deprecated public static void addSmartAssetUpdateFlag(Asset destinationAsset) throws RepositoryException
Deprecated.- Throws:
RepositoryException
-
addSmartAssetUpdateSource
public static void addSmartAssetUpdateSource(Asset destinationAsset, String sourcePath) throws RepositoryException
- Throws:
RepositoryException
-
createLanguageCopyWithAssetRelations
public static List<String> createLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes) throws RepositoryException
This method creates language copy of an asset/folder and its source(for example psd for jpeg). Information about language copy which triggered translation is added in case temporary asset translation is required. Finally, relations are changed with their language copies.- Parameters:
resourceResolver
-pageManagerFactory
-sourcePath
- - source for creating language copytargetLanguageCodes
- - array of language codes- Returns:
- list of created language copies
- Throws:
RepositoryException
-
createLanguageCopyWithAssetRelationsForAsset
public static List<String> createLanguageCopyWithAssetRelationsForAsset(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes) throws RepositoryException
- Throws:
RepositoryException
-
createLanguageCopyWithAssetRelationsForNTFolder
public static List<String> createLanguageCopyWithAssetRelationsForNTFolder(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String sourcePath, String[] targetLanguageCodes) throws RepositoryException
- Throws:
RepositoryException
-
getRelatedAssets
public static List<Asset> getRelatedAssets(Resource resource, String relationName)
-
createUpdateLanguageCopyWithAssetRelations
public static String createUpdateLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String destinationPath, String targetLanguageCode, String prefixPath) throws RepositoryException
This method creates temporary language copy of an asset/folder and its source(for example psd for jpeg) in case temporary asset translation is required. Finally, relations are changed with their temporary copies.- Parameters:
resourceResolver
-pageManagerFactory
-destinationPath
- - source for creating language copytargetLanguageCode
- - destination language codeprefixPath
- - Root path where language copies are created- Returns:
- created variant temporary language copy path if created, otherwise returns destinationPath
- Throws:
RepositoryException
-
findLanguageCopyPathWithAutoCreatedRoots
public static String findLanguageCopyPathWithAutoCreatedRoots(String assetPath, String languageCode, ResourceResolver resolver)
-
findLanguageCopyWithAutoCreatedRootsForAssetOrNTFolder
public static Resource findLanguageCopyWithAutoCreatedRootsForAssetOrNTFolder(Resource resource, String languageCode, ResourceResolver resolver) throws RepositoryException
- Throws:
RepositoryException
-
findLanguageCopyWithAutoCreatedRoots
public static Asset findLanguageCopyWithAutoCreatedRoots(String assetPath, String languageCode, ResourceResolver resolver)
-
afterReplacingUpdatedAsset
public static void afterReplacingUpdatedAsset(String destinationPath, Session userSession, String prefixPath, ResourceResolver resourceResolver) throws RepositoryException
- Throws:
RepositoryException
-
getLanguageRootLocale
public static String getLanguageRootLocale(String path)
Returns the locale for the given path. Supports language root structures /<root>/\<path>lt;Language>_\<Country> and /\<root>lt;path>lt;Language>- Parameters:
path
-- Returns:
- locale or null in case any supported locale does not exist in the given path
-
getLanguageDisplayName
public static String getLanguageDisplayName(ResourceResolver resolver, String langCode)
-
replaceWithExistingLanguageCopiesIfPossible
public static List<String> replaceWithExistingLanguageCopiesIfPossible(List<String> paths, String destinationLanguageCode, ResourceResolver resourceResolver)
Returns a list after replacing paths with their existing language copies. If a language copy of a path does not exist, the path is retained in the returned list.- Parameters:
paths
- The list of paths whose language copy has to be replaceddestinationLanguageCode
- language code of destination language copyresourceResolver
-- Returns:
- a list after replacing paths with their existing language copies.
-
getAssetsFromAssociatedContent
public static ArrayList<Asset> getAssetsFromAssociatedContent(Node contentFragmentNode, String destinationLanguage, ResourceResolver resourceResolver) throws RepositoryException
- Throws:
RepositoryException
-
getUserResourceResolverFromUserId
public static ResourceResolver getUserResourceResolverFromUserId(SlingRepository slingRepository, ResourceResolverFactory resolverFactory, String userId, String serviceUser) throws LoginException, RepositoryException
- Throws:
LoginException
RepositoryException
-
-