Package org.ametys.plugins.linkdirectory
Class DirectoryHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.linkdirectory.DirectoryHelper
-
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
public final class DirectoryHelper extends AbstractLogEnabled implements Component, Serviceable, Contextualizable
Link directory helper.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
DirectoryHelper.DefaultLinkSorter
Helper class to sort links (DefaultLinkSorter implementation) If both links are in the ordered links list, this order is used If one of them is in it and not the other, the one in it will be before the other If none of them is in the list, the initial order will be used
-
Field Summary
Fields Modifier and Type Field Description private static String
__LINKS_NODE_NAME
private static String
__PLUGIN_NODE_NAME
private static String
__THEMES_NODE_NAME
private static String
__USER_LINKS_NODE_NAME
private AmetysObjectResolver
_ametysObjectResolver
The Ametys object resolverprivate Context
_context
The contextprivate CurrentUserProvider
_currentUserProvider
The current user providerprivate DynamicInformationProviderExtensionPoint
_dynamicProviderEP
private LinkDAO
_linkDAO
The link DAOprivate RightManager
_rightManager
The right managerprivate SiteManager
_siteManager
The site managerprivate UserPreferencesManager
_userPreferencesManager
The user preferences managerstatic String
ROLE
The component role
-
Constructor Summary
Constructors Constructor Description DirectoryHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
_addURLAttribute(DefaultLink link, boolean hasIPRestriction, boolean isIPAuthorized, AttributesImpl attrs)
Add the URL attribute to saxprivate boolean
_isCurrentUserGrantedAccess(DefaultLink link)
Determines if the current user is allowed to see the link or notprivate boolean
_isIPAuthorized(Pattern ipRestriction)
Checks if the IP is authorized for use link internal URLprivate void
_saxThemes(ContentHandler contentHandler, DefaultLink link)
Sax the themesvoid
contextualize(Context context)
String
getAllLinksQuery(String siteName, String language)
Get all the linksMap<String,String>
getContextVars(Request request)
Retrieve the context variables from the frontString
getLanguage(Request request)
Get the site's languageAmetysObjectIterable<DefaultLink>
getLinks(String siteName, String language)
Get links of a given site and languageList<DefaultLink>
getLinks(List<String> themesIds, UserIdentity user, String siteName, String language)
Get the list of links corresponding to the given theme idsModifiableTraversableAmetysObject
getLinksForUserNode(Site site, String language, UserIdentity user)
Get the links root node for the given user.String
getLinksForUserNodePath(String siteName, String language, UserIdentity user)
Get the links root node path for the given userModifiableTraversableAmetysObject
getLinksNode(Site site, String language)
Get the links root node.String
getLinksNodePath(String siteName, String language)
Get the links root node pathString
getLinksQuery(String siteName, String language, Expression expression)
Get the link query corresponding to the expression passed as a parameterprivate ModifiableTraversableAmetysObject
getOrCreateNode(ModifiableTraversableAmetysObject parentNode, String nodeName, String nodeType)
ModifiableTraversableAmetysObject
getPluginNode(Site site)
Get the root plugin storage object.String
getPluginNodePath(String siteName)
Get the plugin node pathString
getSiteName(Request request)
Get the site's nameString
getStorageContext(String siteName, String language, String zoneItemId)
Get the appropriate storage contextString
getStorageContext(Request request, String zoneItemId)
Get the appropriate storage context from requestString
getThemeExistsQuery(String siteName, String language, String label)
Get the query verifying the existence of a themeString
getThemeIdFromThemeName(Site site, String language, String configuredThemeName)
Retrieve theme id from theme nameString
getThemeName(String themeId)
Get theme name from jcr idString
getThemeQuery(String siteName, String language, Expression expression)
Get the theme query corresponding to the expression passed as a parameterList<String>
getThemesIdsFromThemesNames(Site site, String language, List<String> configuredThemesNames)
Retrieve theme ids from theme namesMap<String,List<String>>
getThemesMap(List<String> configuredThemesNames, String siteName, String language)
Get the actual ids of the themes configured properly, their names if they were notModifiableTraversableAmetysObject
getThemesNode(Site site, String language)
Get the themes storage node.String
getThemesNodePath(String siteName, String language)
Get the themes node pathString
getUrlExistsForUserQuery(String siteName, String language, String url, UserIdentity user)
Get the query verifying the existence of an url for the given userString
getUrlExistsQuery(String siteName, String language, String url)
Get the query verifying the existence of an urlAmetysObjectIterable<DefaultLink>
getUserLinks(String siteName, String language, UserIdentity user)
Get links of a given site and language, for the given userAmetysObjectIterable<DefaultLink>
getUserLinks(String siteName, String language, UserIdentity user, String themeId)
Get links of a given site and language, for the given userString
getUserLinksQuery(String siteName, String language, UserIdentity user, Expression expression)
Get the user link query corresponding to the expression passed as a parameterboolean
hasInternalUrl(String siteName, String language, List<String> themesIds)
Checks if the links displayed in a link directory service has internal linkboolean
hasRestrictions(String siteName, String language, List<String> themesIds)
Checks if the links displayed in a link directory service has access restrictionsboolean
isAccessRestricted(AmetysObjectIterable<AmetysObject> links)
Check if the links' access is restricted or notString
normalizeString(String s)
Normalizes an input string in order to capitalize it, remove accents, and replace whitespaces with underscoresvoid
saxLink(String siteName, ContentHandler contentHandler, DefaultLink link, boolean selected, boolean hasIPRestriction, boolean isIPAuthorized, boolean userLink, boolean isHidden)
Generate a directory link.void
saxLinks(String siteName, ContentHandler contentHandler, List<DefaultLink> links, List<DefaultLink> userLinks, Map<String,String> contextVars, String storageContext, UserIdentity user)
Sax the directory linksvoid
service(ServiceManager manager)
boolean
themeExists(String themeId)
Verify the existence of a theme-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
__PLUGIN_NODE_NAME
private static final String __PLUGIN_NODE_NAME
- See Also:
- Constant Field Values
-
__LINKS_NODE_NAME
private static final String __LINKS_NODE_NAME
- See Also:
- Constant Field Values
-
__THEMES_NODE_NAME
private static final String __THEMES_NODE_NAME
- See Also:
- Constant Field Values
-
__USER_LINKS_NODE_NAME
private static final String __USER_LINKS_NODE_NAME
- See Also:
- Constant Field Values
-
_ametysObjectResolver
private AmetysObjectResolver _ametysObjectResolver
The Ametys object resolver
-
_siteManager
private SiteManager _siteManager
The site manager
-
_userPreferencesManager
private UserPreferencesManager _userPreferencesManager
The user preferences manager
-
_currentUserProvider
private CurrentUserProvider _currentUserProvider
The current user provider
-
_rightManager
private RightManager _rightManager
The right manager
-
_dynamicProviderEP
private DynamicInformationProviderExtensionPoint _dynamicProviderEP
-
-
Constructor Detail
-
DirectoryHelper
public DirectoryHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getPluginNode
public ModifiableTraversableAmetysObject getPluginNode(Site site) throws AmetysRepositoryException
Get the root plugin storage object.- Parameters:
site
- the site.- Returns:
- the root plugin storage object.
- Throws:
AmetysRepositoryException
- if a repository error occurs.
-
getLinksNode
public ModifiableTraversableAmetysObject getLinksNode(Site site, String language) throws AmetysRepositoryException
Get the links root node.- Parameters:
site
- the sitelanguage
- the language.- Returns:
- the links root node.
- Throws:
AmetysRepositoryException
- if a repository error occurs.
-
getLinksForUserNode
public ModifiableTraversableAmetysObject getLinksForUserNode(Site site, String language, UserIdentity user) throws AmetysRepositoryException
Get the links root node for the given user.- Parameters:
site
- the sitelanguage
- the language.user
- The user identity- Returns:
- the links root node for the given user.
- Throws:
AmetysRepositoryException
- if a repository error occurs.
-
getThemesNode
public ModifiableTraversableAmetysObject getThemesNode(Site site, String language) throws AmetysRepositoryException
Get the themes storage node.- Parameters:
site
- the sitelanguage
- the language.- Returns:
- the themes storage node.
- Throws:
AmetysRepositoryException
- if a repository error occurs.
-
getPluginNodePath
public String getPluginNodePath(String siteName)
Get the plugin node path- Parameters:
siteName
- the site name.- Returns:
- the plugin node path.
-
getLinksNodePath
public String getLinksNodePath(String siteName, String language)
Get the links root node path- Parameters:
siteName
- the site name.language
- the language- Returns:
- the links root node path.
-
getLinksForUserNodePath
public String getLinksForUserNodePath(String siteName, String language, UserIdentity user)
Get the links root node path for the given user- Parameters:
siteName
- the site name.language
- the languageuser
- The user identity- Returns:
- the links root node path for the given user.
-
getThemesNodePath
public String getThemesNodePath(String siteName, String language)
Get the themes node path- Parameters:
siteName
- the site name.language
- the language- Returns:
- the themes node path.
-
getAllLinksQuery
public String getAllLinksQuery(String siteName, String language)
Get all the links- Parameters:
siteName
- the site name.language
- the language.- Returns:
- all the links' nodes
-
getLinksQuery
public String getLinksQuery(String siteName, String language, Expression expression)
Get the link query corresponding to the expression passed as a parameter- Parameters:
siteName
- the site name.language
- the language.expression
- theExpression
of the links retrieval query- Returns:
- the link corresponding to the expression passed as a parameter
-
getUserLinksQuery
public String getUserLinksQuery(String siteName, String language, UserIdentity user, Expression expression)
Get the user link query corresponding to the expression passed as a parameter- Parameters:
siteName
- the site name.language
- the language.user
- the userexpression
- theExpression
of the links retrieval query- Returns:
- the user link corresponding to the expression passed as a parameter
-
getThemeQuery
public String getThemeQuery(String siteName, String language, Expression expression)
Get the theme query corresponding to the expression passed as a parameter- Parameters:
siteName
- the site name.language
- the language.expression
- theExpression
of the theme retrieval query- Returns:
- the theme corresponding to the expression passed as a parameter
-
getUrlExistsQuery
public String getUrlExistsQuery(String siteName, String language, String url)
Get the query verifying the existence of an url- Parameters:
siteName
- the site name.language
- the language.url
- the url to test.- Returns:
- the query verifying the existence of an url
-
getUrlExistsForUserQuery
public String getUrlExistsForUserQuery(String siteName, String language, String url, UserIdentity user)
Get the query verifying the existence of an url for the given user- Parameters:
siteName
- the site name.language
- the language.url
- the url to test.user
- The user identity- Returns:
- the query verifying the existence of an url for the given user
-
getThemeExistsQuery
public String getThemeExistsQuery(String siteName, String language, String label)
Get the query verifying the existence of a theme- Parameters:
siteName
- the site name.language
- the language.label
- the label of the theme to test.- Returns:
- the query verifying the existence of a theme
-
normalizeString
public String normalizeString(String s)
Normalizes an input string in order to capitalize it, remove accents, and replace whitespaces with underscores- Parameters:
s
- the string to normalize- Returns:
- the normalized string
-
getLinks
public AmetysObjectIterable<DefaultLink> getLinks(String siteName, String language)
Get links of a given site and language- Parameters:
siteName
- the site namelanguage
- the language- Returns:
- the links
-
getLinks
public List<DefaultLink> getLinks(List<String> themesIds, UserIdentity user, String siteName, String language)
Get the list of links corresponding to the given theme ids- Parameters:
themesIds
- the ids of the configured themesuser
- the current usersiteName
- the site's namelanguage
- the site's language- Returns:
- the list of default links corresponding to the given themes
-
getUserLinks
public AmetysObjectIterable<DefaultLink> getUserLinks(String siteName, String language, UserIdentity user)
Get links of a given site and language, for the given user- Parameters:
siteName
- the site namelanguage
- the languageuser
- The user identity- Returns:
- the links for the given user
-
getUserLinks
public AmetysObjectIterable<DefaultLink> getUserLinks(String siteName, String language, UserIdentity user, String themeId)
Get links of a given site and language, for the given user- Parameters:
siteName
- the site namelanguage
- the languageuser
- The user identitythemeId
- the theme id to filter user links. If null, return all user links- Returns:
- the links for the given user
-
hasRestrictions
public boolean hasRestrictions(String siteName, String language, List<String> themesIds)
Checks if the links displayed in a link directory service has access restrictions- Parameters:
siteName
- the name of the sitelanguage
- the languagethemesIds
- the list of selected theme ids- Returns:
- true if the links of the service have access restrictions, false otherwise
-
hasInternalUrl
public boolean hasInternalUrl(String siteName, String language, List<String> themesIds)
Checks if the links displayed in a link directory service has internal link- Parameters:
siteName
- the name of the sitelanguage
- the languagethemesIds
- the list of selected theme ids- Returns:
- true if the links of the service has internal link, false otherwise
-
isAccessRestricted
public boolean isAccessRestricted(AmetysObjectIterable<AmetysObject> links)
Check if the links' access is restricted or not- Parameters:
links
- the links to be tested- Returns:
- true if the link has a restricted access, false otherwise
-
getOrCreateNode
private ModifiableTraversableAmetysObject getOrCreateNode(ModifiableTraversableAmetysObject parentNode, String nodeName, String nodeType) throws AmetysRepositoryException
- Throws:
AmetysRepositoryException
-
saxLinks
public void saxLinks(String siteName, ContentHandler contentHandler, List<DefaultLink> links, List<DefaultLink> userLinks, Map<String,String> contextVars, String storageContext, UserIdentity user) throws SAXException, UserPreferencesException
Sax the directory links- Parameters:
siteName
- the site namecontentHandler
- the content handlerlinks
- the list of links to sax (can be nulluserLinks
- the user links to sax (can be null)storageContext
- the storage context, null if there is no connected usercontextVars
- the context variablesuser
- the user- Throws:
SAXException
- If an error occurs while generating the SAX eventsUserPreferencesException
- if an exception occurs while getting the user preferences
-
saxLink
public void saxLink(String siteName, ContentHandler contentHandler, DefaultLink link, boolean selected, boolean hasIPRestriction, boolean isIPAuthorized, boolean userLink, boolean isHidden) throws SAXException
Generate a directory link.- Parameters:
siteName
- the site namecontentHandler
- the content handlerlink
- the link to generate.selected
- true if a front end user has checked this link as a user preference, false otherwise (deprecated, only used for old views, isHidden should be used now)hasIPRestriction
- true if we have IP restrictionisIPAuthorized
- true if the IP is authorizeduserLink
- true if it is a user linkisHidden
- true if the link is hidden- Throws:
SAXException
- If an error occurs while generating the SAX events
-
_addURLAttribute
private void _addURLAttribute(DefaultLink link, boolean hasIPRestriction, boolean isIPAuthorized, AttributesImpl attrs)
Add the URL attribute to sax- Parameters:
link
- the linkhasIPRestriction
- true if we have IP restrictionisIPAuthorized
- true if the IP is authorizedattrs
- the attribute
-
getThemesMap
public Map<String,List<String>> getThemesMap(List<String> configuredThemesNames, String siteName, String language)
Get the actual ids of the themes configured properly, their names if they were not- Parameters:
configuredThemesNames
- the normalized ids of the configured themessiteName
- the site's namelanguage
- the site's language- Returns:
- the actual ids of the configured themes
-
getThemesIdsFromThemesNames
public List<String> getThemesIdsFromThemesNames(Site site, String language, List<String> configuredThemesNames)
Retrieve theme ids from theme names- Parameters:
site
- the sitelanguage
- the languageconfiguredThemesNames
- the names of the configured themes- Returns:
- the themes ids matching the given theme names
-
getThemeIdFromThemeName
public String getThemeIdFromThemeName(Site site, String language, String configuredThemeName)
Retrieve theme id from theme name- Parameters:
site
- the sitelanguage
- the languageconfiguredThemeName
- the name of the configured theme- Returns:
- the themes id matching the given theme name
-
themeExists
public boolean themeExists(String themeId)
Verify the existence of a theme- Parameters:
themeId
- the id of the theme to verify- Returns:
- true if the theme exists, false otherwise
-
getThemeName
public String getThemeName(String themeId)
Get theme name from jcr id- Parameters:
themeId
- the jcr theme id- Returns:
- the name of the theme. Null if the theme doesn't exist
-
getSiteName
public String getSiteName(Request request)
Get the site's name- Parameters:
request
- the request- Returns:
- the site's name
-
getLanguage
public String getLanguage(Request request)
Get the site's language- Parameters:
request
- the request- Returns:
- the site's language
-
getContextVars
public Map<String,String> getContextVars(Request request)
Retrieve the context variables from the front- Parameters:
request
- the request- Returns:
- the map of context variables
-
getStorageContext
public String getStorageContext(Request request, String zoneItemId)
Get the appropriate storage context from request- Parameters:
request
- the requestzoneItemId
- the id of the zone item if we deal with a service, null for an input data- Returns:
- the storage context in which the user preferences will be kept
-
getStorageContext
public String getStorageContext(String siteName, String language, String zoneItemId)
Get the appropriate storage context- Parameters:
siteName
- the name of the sitelanguage
- the languagezoneItemId
- the id of the zone item if we deal with a service, null for an input data- Returns:
- the storage context in which the user preferences will be kept
-
_saxThemes
private void _saxThemes(ContentHandler contentHandler, DefaultLink link) throws SAXException
Sax the themes- Parameters:
contentHandler
- the content handlerlink
- the link- Throws:
SAXException
- If an error occurs while generating the SAX events
-
_isCurrentUserGrantedAccess
private boolean _isCurrentUserGrantedAccess(DefaultLink link)
Determines if the current user is allowed to see the link or not- Parameters:
link
- the link- Returns:
- true if the current user is allowed to see the link, false otherwise
-
_isIPAuthorized
private boolean _isIPAuthorized(Pattern ipRestriction)
Checks if the IP is authorized for use link internal URL- Parameters:
ipRestriction
- The ip restriction pattern- Returns:
- true the IP is authorized for use link internal URL, false otherwise
-
-