Package com.day.cq.dam.commons.util
Class DamLanguageUtil
- java.lang.Object
 - 
- com.day.cq.dam.commons.util.DamLanguageUtil
 
 
- 
public class DamLanguageUtil extends java.lang.ObjectThis class provides utility method for Language Copy used by sites 
- 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringATTRIBUTE_ASSET_LINKS_RELATIONstatic java.lang.StringATTRIBUTE_ASSET_SOURCE_RELATIONstatic java.lang.StringATTRIBUTE_ASSET_UPDATE_REQUIREDstatic java.lang.StringATTRIBUTE_COLLECTION_SOURCE_LANGUAGE_COPYstatic java.lang.StringATTRIBUTE_CQ_TRANSLATION_LAST_UPDATEstatic java.lang.StringCQ_LASTMODIFIED 
- 
Constructor Summary
Constructors Constructor Description DamLanguageUtil() 
- 
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddSmartAssetUpdateFlag(Asset destinationAsset)Deprecated.static voidaddSmartAssetUpdateSource(Asset destinationAsset, java.lang.String sourcePath)static voidafterReplacingUpdatedAsset(java.lang.String destinationPath, javax.jcr.Session userSession, java.lang.String prefixPath, ResourceResolver resourceResolver)static java.util.List<java.lang.String>createLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes)This method creates language copy of an asset/folder Adds Smart translation properties when language copy is presentstatic java.util.List<java.lang.String>createLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes)This method creates language copy of an asset/folder and its source(for example psd for jpeg).static java.util.List<java.lang.String>createLanguageCopyWithAssetRelationsForAsset(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes)static java.util.List<java.lang.String>createLanguageCopyWithAssetRelationsForNTFolder(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes)static java.lang.StringcreateUpdateLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String targetLanguageCode, java.lang.String prefixPath)This method creates update language copy of an asset/folderstatic java.lang.StringcreateUpdateLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String destinationPath, java.lang.String targetLanguageCode, java.lang.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 java.lang.StringfindLanguageCopyPathWithAutoCreatedRoots(java.lang.String assetPath, java.lang.String languageCode, ResourceResolver resolver)static AssetfindLanguageCopyWithAutoCreatedRoots(java.lang.String assetPath, java.lang.String languageCode, ResourceResolver resolver)static ResourcefindLanguageCopyWithAutoCreatedRootsForAssetOrNTFolder(Resource resource, java.lang.String languageCode, ResourceResolver resolver)static java.util.ArrayList<Asset>getAssetsFromAssociatedContent(javax.jcr.Node contentFragmentNode, java.lang.String destinationLanguage, ResourceResolver resourceResolver)static LanguagegetLanguage(java.lang.String path)Deprecated.since 6.2, useLanguageUtilinsteadstatic AssetgetLanguageCopy(java.lang.String assetPath, java.lang.String languageCode, ResourceResolver resolver)This method returns the Language copy asset if language copy exists, for the asked localestatic java.lang.StringgetLanguageDisplayName(ResourceResolver resolver, java.lang.String langCode)static java.lang.StringgetLanguageRoot(java.lang.String path)Deprecated.since 6.2, useLanguageUtilinsteadstatic java.lang.StringgetLanguageRootLocale(java.lang.String path)Returns the locale for the given path.static java.util.Collection<Resource>getLanguageRoots(ResourceResolver resolver, java.lang.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 java.util.List<Asset>getRelatedAssets(Resource resource, java.lang.String relationName)static booleanhasLanguageCopy(java.lang.String assetPath, java.lang.String languageCode, ResourceResolver resolver)This method returns true if language copy of an asset exists, for the asked localestatic booleanisSmartAssetUpdateRequired(Asset sourceAsset, Asset destinationAsset)static voidmoveUpdatedAsset(java.lang.String sourcePath, java.lang.String destinationPath, javax.jcr.Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver)static voidmoveUpdatedAsset(java.lang.String sourcePath, java.lang.String destinationPath, javax.jcr.Session userSession, PageManagerFactory pageManagerFactory, ResourceResolverFactory resolverFactory)Deprecated.since 6.2, usemoveUpdatedAsset(String, String, Session, PageManagerFactory, ResourceResolver)insteadstatic voidreplaceUpdatedAsset(java.lang.String sourcePath, java.lang.String destinationPath, javax.jcr.Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver)static java.util.List<java.lang.String>replaceWithExistingLanguageCopiesIfPossible(java.util.List<java.lang.String> paths, java.lang.String destinationLanguageCode, ResourceResolver resourceResolver)Returns a list after replacing paths with their existing language copies. 
 - 
 
- 
- 
Field Detail
- 
ATTRIBUTE_ASSET_LINKS_RELATION
public static final java.lang.String ATTRIBUTE_ASSET_LINKS_RELATION
- See Also:
 - Constant Field Values
 
 
- 
ATTRIBUTE_ASSET_SOURCE_RELATION
public static final java.lang.String ATTRIBUTE_ASSET_SOURCE_RELATION
- See Also:
 - Constant Field Values
 
 
- 
ATTRIBUTE_ASSET_UPDATE_REQUIRED
public static final java.lang.String ATTRIBUTE_ASSET_UPDATE_REQUIRED
- See Also:
 - Constant Field Values
 
 
- 
ATTRIBUTE_COLLECTION_SOURCE_LANGUAGE_COPY
public static final java.lang.String ATTRIBUTE_COLLECTION_SOURCE_LANGUAGE_COPY
- See Also:
 - Constant Field Values
 
 
- 
CQ_LASTMODIFIED
public static final java.lang.String CQ_LASTMODIFIED
- See Also:
 - Constant Field Values
 
 
- 
ATTRIBUTE_CQ_TRANSLATION_LAST_UPDATE
public static final java.lang.String ATTRIBUTE_CQ_TRANSLATION_LAST_UPDATE
- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Method Detail
- 
hasLanguageCopy
public static boolean hasLanguageCopy(java.lang.String assetPath, java.lang.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(java.lang.String assetPath, java.lang.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 java.util.List<java.lang.String> createLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes)
This method creates language copy of an asset/folder Adds Smart translation properties when language copy is present- Parameters:
 resourceResolver-pageManagerFactory-sourcePath- - source for creating language copytargetLanguageCodes- - array of language codes- Returns:
 
 
- 
getLanguageRoot
@Deprecated public static java.lang.String getLanguageRoot(java.lang.String path)
Deprecated.since 6.2, useLanguageUtilinsteadReturns 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 
nullif not found 
 
- 
getLanguage
@Deprecated public static Language getLanguage(java.lang.String path)
Deprecated.since 6.2, useLanguageUtilinsteadReturns 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 
nullif not found 
 
- 
getLanguageRoots
public static java.util.Collection<Resource> getLanguageRoots(ResourceResolver resolver, java.lang.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 java.lang.String createUpdateLanguageCopy(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String targetLanguageCode, java.lang.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(java.lang.String sourcePath, java.lang.String destinationPath, javax.jcr.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(java.lang.String sourcePath, java.lang.String destinationPath, javax.jcr.Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver) 
- 
replaceUpdatedAsset
public static void replaceUpdatedAsset(java.lang.String sourcePath, java.lang.String destinationPath, javax.jcr.Session userSession, PageManagerFactory pageManagerFactory, ResourceResolver resourceResolver) 
- 
isSmartAssetUpdateRequired
public static boolean isSmartAssetUpdateRequired(Asset sourceAsset, Asset destinationAsset)
 
- 
addSmartAssetUpdateFlag
@Deprecated public static void addSmartAssetUpdateFlag(Asset destinationAsset) throws javax.jcr.RepositoryException
Deprecated.- Throws:
 javax.jcr.RepositoryException
 
- 
addSmartAssetUpdateSource
public static void addSmartAssetUpdateSource(Asset destinationAsset, java.lang.String sourcePath) throws javax.jcr.RepositoryException
- Throws:
 javax.jcr.RepositoryException
 
- 
createLanguageCopyWithAssetRelations
public static java.util.List<java.lang.String> createLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes) throws javax.jcr.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:
 javax.jcr.RepositoryException
 
- 
createLanguageCopyWithAssetRelationsForAsset
public static java.util.List<java.lang.String> createLanguageCopyWithAssetRelationsForAsset(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes) throws javax.jcr.RepositoryException
- Throws:
 javax.jcr.RepositoryException
 
- 
createLanguageCopyWithAssetRelationsForNTFolder
public static java.util.List<java.lang.String> createLanguageCopyWithAssetRelationsForNTFolder(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String sourcePath, java.lang.String[] targetLanguageCodes) throws javax.jcr.RepositoryException
- Throws:
 javax.jcr.RepositoryException
 
- 
getRelatedAssets
public static java.util.List<Asset> getRelatedAssets(Resource resource, java.lang.String relationName)
 
- 
createUpdateLanguageCopyWithAssetRelations
public static java.lang.String createUpdateLanguageCopyWithAssetRelations(ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, java.lang.String destinationPath, java.lang.String targetLanguageCode, java.lang.String prefixPath) throws javax.jcr.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:
 javax.jcr.RepositoryException
 
- 
findLanguageCopyPathWithAutoCreatedRoots
public static java.lang.String findLanguageCopyPathWithAutoCreatedRoots(java.lang.String assetPath, java.lang.String languageCode, ResourceResolver resolver) 
- 
findLanguageCopyWithAutoCreatedRootsForAssetOrNTFolder
public static Resource findLanguageCopyWithAutoCreatedRootsForAssetOrNTFolder(Resource resource, java.lang.String languageCode, ResourceResolver resolver) throws javax.jcr.RepositoryException
- Throws:
 javax.jcr.RepositoryException
 
- 
findLanguageCopyWithAutoCreatedRoots
public static Asset findLanguageCopyWithAutoCreatedRoots(java.lang.String assetPath, java.lang.String languageCode, ResourceResolver resolver)
 
- 
afterReplacingUpdatedAsset
public static void afterReplacingUpdatedAsset(java.lang.String destinationPath, javax.jcr.Session userSession, java.lang.String prefixPath, ResourceResolver resourceResolver) throws javax.jcr.RepositoryException- Throws:
 javax.jcr.RepositoryException
 
- 
getLanguageRootLocale
public static java.lang.String getLanguageRootLocale(java.lang.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 java.lang.String getLanguageDisplayName(ResourceResolver resolver, java.lang.String langCode)
 
- 
replaceWithExistingLanguageCopiesIfPossible
public static java.util.List<java.lang.String> replaceWithExistingLanguageCopiesIfPossible(java.util.List<java.lang.String> paths, java.lang.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 java.util.ArrayList<Asset> getAssetsFromAssociatedContent(javax.jcr.Node contentFragmentNode, java.lang.String destinationLanguage, ResourceResolver resourceResolver) throws javax.jcr.RepositoryException
- Throws:
 javax.jcr.RepositoryException
 
 - 
 
 -