public final class DirectoryHelper extends AbstractLogEnabled implements Component, Serviceable, Contextualizable
Modifier and Type | Field and 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 resolver
|
private Context |
_context
The context
|
private CurrentUserProvider |
_currentUserProvider
The current user provider
|
private GroupManager |
_groupManager
The groups manager
|
private SiteConfigurationExtensionPoint |
_siteConfiguration
The site configuration extension point
|
private SiteManager |
_siteManager
The site manager
|
private UserManager |
_userManager
The users manager
|
private UserPreferencesManager |
_userPreferencesManager
The user preferences manager
|
static String |
ROLE
The component role
|
Constructor and Description |
---|
DirectoryHelper() |
Modifier and Type | Method and Description |
---|---|
private void |
_addURLAttribute(DefaultLink link,
boolean hasIPRestriction,
boolean isIPAuthorized,
AttributesImpl attrs)
Add the URL attribute to sax
|
private boolean |
_isCurrentUserGrantedAccess(DefaultLink link)
Determines if the current user is allowed to see the link or not
|
private boolean |
_isGrantedAccess(UserIdentity user,
UserIdentity[] grantedUsers,
GroupIdentity[] grantedGroups)
Checks if the user has access to the page or not
|
private boolean |
_isIPAuthorized(Pattern ipRestriction)
Checks if the IP is authorized for use link internal URL
|
private void |
_saxGrantedGroups(ContentHandler contentHandler,
DefaultLink link)
Sax the granted groups
|
private void |
_saxGrantedUsers(ContentHandler contentHandler,
DefaultLink link)
Sax the granted users
|
private void |
_saxThemes(ContentHandler contentHandler,
DefaultLink link)
Sax the themes
|
private void |
_saxThemesLabel(ContentHandler contentHandler,
DefaultLink link)
Sax the label of the themes
|
void |
contextualize(Context context) |
String |
getAllLinksQuery(String siteName,
String language)
Get all the links
|
Map<String,String> |
getContextVars(Request request)
Retrieve the context variables from the front
|
String |
getLanguage(Request request)
Get the site's language
|
List<DefaultLink> |
getLinks(List<String> themesIds,
UserIdentity user,
String siteName,
String language)
Get the list of links corresponding to the given theme ids
|
AmetysObjectIterable<DefaultLink> |
getLinks(String siteName,
String language)
Get links of a given site and language
|
ModifiableTraversableAmetysObject |
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 user
|
ModifiableTraversableAmetysObject |
getLinksNode(Site site,
String language)
Get the links root node.
|
String |
getLinksNodePath(String siteName,
String language)
Get the links root node path
|
String |
getLinksQuery(String siteName,
String language,
Expression expression)
Get the link query corresponding to the expression passed as a parameter
|
private 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 path
|
String |
getSiteName(Request request)
Get the site's name
|
String |
getThemeExistsQuery(String siteName,
String language,
String label)
Get the query verifying the existence of a theme
|
String |
getThemeQuery(String siteName,
String language,
Expression expression)
Get the theme query corresponding to the expression passed as a parameter
|
List<String> |
getThemesIdsFromThemesNames(Site site,
String language,
List<String> configuredThemesNames)
Retrieve theme ids from theme names
|
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
|
ModifiableTraversableAmetysObject |
getThemesNode(Site site,
String language)
Get the themes storage node.
|
String |
getThemesNodePath(String siteName,
String language)
Get the themes node path
|
String |
getUrlExistsForUserQuery(String siteName,
String language,
String url,
UserIdentity user)
Get the query verifying the existence of an url for the given user
|
String |
getUrlExistsQuery(String siteName,
String language,
String url)
Get the query verifying the existence of an url
|
AmetysObjectIterable<DefaultLink> |
getUserLinks(String siteName,
String language,
UserIdentity user)
Get links of a given site and language, for the given user
|
boolean |
hasInternalUrl(String siteName,
String language,
List<String> themesIds)
Checks if the links displayed in a link directory service has internal link
|
boolean |
hasRestrictions(String siteName,
String language,
List<String> themesIds)
Checks if the links displayed in a link directory service has access restrictions
|
boolean |
isAccessRestricted(AmetysObjectIterable<AmetysObject> links)
Check if the links' access is restricted or not
|
String |
normalizeString(String s)
Normalizes an input string in order to capitalize it, remove accents, and replace whitespaces with underscores
|
void |
saxLink(String siteName,
ContentHandler contentHandler,
DefaultLink link,
boolean saxThemesLabelOnly,
boolean selected,
boolean saxLinksOnly,
boolean hasIPRestriction,
boolean isIPAuthorized,
boolean userLink)
Generate a directory link.
|
void |
saxLinks(String siteName,
ContentHandler contentHandler,
List<DefaultLink> links,
Map<String,String> contextVars,
String storageContext,
UserIdentity user,
boolean saxThemesLabelOnly,
boolean saxLinksOnly,
boolean userLinks)
Sax the directory links
|
void |
service(ServiceManager manager) |
boolean |
themeExists(String themeId)
Verify the existence of a theme
|
getLogger, setLogger
private static final String __PLUGIN_NODE_NAME
private static final String __LINKS_NODE_NAME
private static final String __THEMES_NODE_NAME
private static final String __USER_LINKS_NODE_NAME
private AmetysObjectResolver _ametysObjectResolver
private UserManager _userManager
private GroupManager _groupManager
private SiteManager _siteManager
private UserPreferencesManager _userPreferencesManager
private CurrentUserProvider _currentUserProvider
private SiteConfigurationExtensionPoint _siteConfiguration
public DirectoryHelper()
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
ServiceException
public void contextualize(Context context) throws ContextException
contextualize
in interface Contextualizable
ContextException
public ModifiableTraversableAmetysObject getPluginNode(Site site) throws AmetysRepositoryException
site
- the site.AmetysRepositoryException
- if a repository error occurs.public ModifiableTraversableAmetysObject getLinksNode(Site site, String language) throws AmetysRepositoryException
site
- the sitelanguage
- the language.AmetysRepositoryException
- if a repository error occurs.public ModifiableTraversableAmetysObject getLinksForUserNode(Site site, String language, UserIdentity user) throws AmetysRepositoryException
site
- the sitelanguage
- the language.user
- The user identityAmetysRepositoryException
- if a repository error occurs.public ModifiableTraversableAmetysObject getThemesNode(Site site, String language) throws AmetysRepositoryException
site
- the sitelanguage
- the language.AmetysRepositoryException
- if a repository error occurs.public String getPluginNodePath(String siteName)
siteName
- the site name.public String getLinksNodePath(String siteName, String language)
siteName
- the site name.language
- the languagepublic String getLinksForUserNodePath(String siteName, String language, UserIdentity user)
siteName
- the site name.language
- the languageuser
- The user identitypublic String getThemesNodePath(String siteName, String language)
siteName
- the site name.language
- the languagepublic String getAllLinksQuery(String siteName, String language)
siteName
- the site name.language
- the language.public String getLinksQuery(String siteName, String language, Expression expression)
siteName
- the site name.language
- the language.expression
- the Expression
of the links retrieval querypublic String getThemeQuery(String siteName, String language, Expression expression)
siteName
- the site name.language
- the language.expression
- the Expression
of the theme retrieval querypublic String getUrlExistsQuery(String siteName, String language, String url)
siteName
- the site name.language
- the language.url
- the url to test.public String getUrlExistsForUserQuery(String siteName, String language, String url, UserIdentity user)
siteName
- the site name.language
- the language.url
- the url to test.user
- The user identitypublic String getThemeExistsQuery(String siteName, String language, String label)
siteName
- the site name.language
- the language.label
- the label of the theme to test.public String normalizeString(String s)
s
- the string to normalizepublic AmetysObjectIterable<DefaultLink> getLinks(String siteName, String language)
siteName
- the site namelanguage
- the languagepublic List<DefaultLink> getLinks(List<String> themesIds, UserIdentity user, String siteName, String language)
themesIds
- the ids of the configured themesuser
- the current usersiteName
- the site's namelanguage
- the site's languagepublic AmetysObjectIterable<DefaultLink> getUserLinks(String siteName, String language, UserIdentity user)
siteName
- the site namelanguage
- the languageuser
- The user identitypublic boolean hasRestrictions(String siteName, String language, List<String> themesIds)
siteName
- the name of the sitelanguage
- the languagethemesIds
- the list of selected theme idspublic boolean hasInternalUrl(String siteName, String language, List<String> themesIds)
siteName
- the name of the sitelanguage
- the languagethemesIds
- the list of selected theme idspublic boolean isAccessRestricted(AmetysObjectIterable<AmetysObject> links)
links
- the links to be testedprivate ModifiableTraversableAmetysObject getOrCreateNode(ModifiableTraversableAmetysObject parentNode, String nodeName, String nodeType) throws AmetysRepositoryException
AmetysRepositoryException
public void saxLinks(String siteName, ContentHandler contentHandler, List<DefaultLink> links, Map<String,String> contextVars, String storageContext, UserIdentity user, boolean saxThemesLabelOnly, boolean saxLinksOnly, boolean userLinks) throws SAXException, UserPreferencesException
siteName
- the site namecontentHandler
- the content handlerlinks
- the list of links to saxstorageContext
- the storage context, null if there is no connected usercontextVars
- the context variablesuser
- the usersaxThemesLabelOnly
- true to sax themes label onlysaxLinksOnly
- true if the only the links need to be saxed, false otherwiseuserLinks
- true if it is user linksSAXException
- If an error occurs while generating the SAX eventsUserPreferencesException
- if an exception occurs while getting the user preferencespublic void saxLink(String siteName, ContentHandler contentHandler, DefaultLink link, boolean saxThemesLabelOnly, boolean selected, boolean saxLinksOnly, boolean hasIPRestriction, boolean isIPAuthorized, boolean userLink) throws SAXException
siteName
- the site namecontentHandler
- the content handlerlink
- the link to generate.saxThemesLabelOnly
- true to sax themes label onlyselected
- true if a front end user has checked this link as a user preference, false otherwisesaxLinksOnly
- true if we want to sax a link for an input datahasIPRestriction
- true if we have IP restrictionisIPAuthorized
- true if the IP is authorizeduserLink
- true if it is a user linkSAXException
- If an error occurs while generating the SAX eventsprivate void _addURLAttribute(DefaultLink link, boolean hasIPRestriction, boolean isIPAuthorized, AttributesImpl attrs)
link
- the linkhasIPRestriction
- true if we have IP restrictionisIPAuthorized
- true if the IP is authorizedattrs
- the attributepublic Map<String,List<String>> getThemesMap(List<String> configuredThemesNames, String siteName, String language)
configuredThemesNames
- the normalized ids of the configured themessiteName
- the site's namelanguage
- the site's languagepublic List<String> getThemesIdsFromThemesNames(Site site, String language, List<String> configuredThemesNames)
site
- the sitelanguage
- the languageconfiguredThemesNames
- the names of the configured themespublic boolean themeExists(String themeId)
themeId
- the id of the theme to verifypublic String getSiteName(Request request)
request
- the requestpublic String getLanguage(Request request)
request
- the requestpublic Map<String,String> getContextVars(Request request)
request
- the requestprivate void _saxThemes(ContentHandler contentHandler, DefaultLink link) throws SAXException
contentHandler
- the content handlerlink
- the linkSAXException
- If an error occurs while generating the SAX eventsprivate void _saxThemesLabel(ContentHandler contentHandler, DefaultLink link) throws SAXException
contentHandler
- the content handlerlink
- the linkSAXException
- if an error occurs while saxingprivate void _saxGrantedUsers(ContentHandler contentHandler, DefaultLink link) throws SAXException
contentHandler
- the content handlerlink
- the linkSAXException
- if an exception occurs while saxingprivate void _saxGrantedGroups(ContentHandler contentHandler, DefaultLink link) throws SAXException
contentHandler
- the content handlerlink
- the linkSAXException
- if an exception occurs while saxingprivate boolean _isCurrentUserGrantedAccess(DefaultLink link)
link
- the linkprivate boolean _isGrantedAccess(UserIdentity user, UserIdentity[] grantedUsers, GroupIdentity[] grantedGroups)
user
- the identity of the usergrantedUsers
- the list of granted usersgrantedGroups
- the list of granted groupsprivate boolean _isIPAuthorized(Pattern ipRestriction)
ipRestriction
- The ip restriction pattern