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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
contextualize
(Context context) getAllLinksQuery
(String siteName, String language) Get all the linksgetContextVars
(Request request) Retrieve the context variables from the frontgetLanguage
(Request request) Get the site's languageGet links of a given site and languageGet the list of links corresponding to the given theme idsgetLinksForUserNode
(Site site, String language, UserIdentity user) Get the links root node for the given user.getLinksForUserNodePath
(String siteName, String language, UserIdentity user) Get the links root node path for the given usergetLinksNode
(Site site, String language) Get the links root node.getLinksNodePath
(String siteName, String language) Get the links root node pathgetLinksQuery
(String siteName, String language, Expression expression) Get the link query corresponding to the expression passed as a parametergetPluginNode
(Site site) Get the root plugin storage object.getPluginNodePath
(String siteName) Get the plugin node pathgetSiteName
(Request request) Get the site's namegetSkinLinksConfiguration
(String skinName) Get the configuration of links brought by skingetStorageContext
(String siteName, String language, String zoneItemId) Get the appropriate storage contextgetStorageContext
(Request request, String zoneItemId) Get the appropriate storage context from requestgetThemesMap
(List<String> configuredThemesNames, String siteName, String language) Get the actual ids of the themes configured properly, their names if they were notgetThemeTitle
(String themeName, String siteName, String language) Get theme's title from its namegetUrlExistsForUserQuery
(String siteName, String language, String url, UserIdentity user) Get the query verifying the existence of an url for the given usergetUrlExistsQuery
(String siteName, String language, String url) Get the query verifying the existence of an urlgetUserLinks
(String siteName, String language, UserIdentity user) Get links of a given site and language, for the given usergetUserLinks
(String siteName, String language, UserIdentity user, String themeName) Get links of a given site and language, for the given usergetUserLinksQuery
(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
Check if the links' access is restricted or notNormalizes 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 themeMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The component role -
_themesDAO
Themes DAO
-
-
Constructor Details
-
DirectoryHelper
public DirectoryHelper()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getPluginNode
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
Get the plugin node path- Parameters:
siteName
- the site name.- Returns:
- the plugin node path.
-
getLinksNodePath
Get the links root node path- Parameters:
siteName
- the site name.language
- the language- Returns:
- the links root node path.
-
getLinksForUserNodePath
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
Get all the links- Parameters:
siteName
- the site name.language
- the language.- Returns:
- all the links' nodes
-
getLinksQuery
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
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
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
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
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
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
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
-
getSkinLinksConfiguration
public Configuration getSkinLinksConfiguration(String skinName) throws IOException, ConfigurationException, SAXException Get the configuration of links brought by skin- Parameters:
skinName
- the skin name- Returns:
- the skin configuration
- Throws:
IOException
- if an error occuredConfigurationException
- if an error occuredSAXException
- if an error occured
-
saxLinks
public void saxLinks(String siteName, ContentHandler contentHandler, List<DefaultLink> links, List<DefaultLink> userLinks, Map<String, String> contextVars, String storageContext, UserIdentity user) throws SAXException, UserPreferencesExceptionSax 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
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
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
Get the site's name- Parameters:
request
- the request- Returns:
- the site's name
-
getLanguage
Get the site's language- Parameters:
request
- the request- Returns:
- the site's language
-
getContextVars
Retrieve the context variables from the front- Parameters:
request
- the request- Returns:
- the map of context variables
-
getStorageContext
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
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
-