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.
-
-
Field Summary
Fields Modifier and Type Field Description protected ThemesDAO
_themesDAO
Themes DAOstatic String
ROLE
The component role
-
Constructor Summary
Constructors Constructor Description DirectoryHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 parameterModifiableTraversableAmetysObject
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 requestMap<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 notI18nizableText
getThemeTitle(String themeName, String siteName, String language)
Get theme's title from its nameString
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 themeName)
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 themeName, String siteName, String language)
Verify the existence of a theme-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_themesDAO
protected ThemesDAO _themesDAO
Themes DAO
-
-
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.
-
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.
-
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
-
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
-
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 themeName)
Get links of a given site and language, for the given user- Parameters:
siteName
- the site namelanguage
- the languageuser
- The user identitythemeName
- 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
-
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
-
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
-
themeExists
public boolean themeExists(String themeName, String siteName, String language)
Verify the existence of a theme- Parameters:
themeName
- the id of the theme to verifysiteName
- the site's namelanguage
- the site's language- Returns:
- true if the theme exists, false otherwise
-
getThemeTitle
public I18nizableText getThemeTitle(String themeName, String siteName, String language)
Get theme's title from its name- Parameters:
themeName
- the theme namesiteName
- the site's namelanguage
- the site's language- Returns:
- the title 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
-
-