Class TagPlugin

  • All Implemented Interfaces:
    XWikiPluginInterface

    public class TagPlugin
    extends XWikiDefaultPlugin
    implements XWikiPluginInterface
    TagPlugin is a plugin that allows to manipulate tags easily. It allows to get, rename and delete tags.
    Version:
    $Id: f0dfbc48a94b9b2b172642b98fd8238de132991f $
    • Field Detail

      • LOGGER

        public static final org.slf4j.Logger LOGGER
        Logging helper object.
      • PLUGIN_NAME

        public static final String PLUGIN_NAME
        The identifier for this plugin; used for accessing the plugin from velocity, and as the action returning the extension content.
        See Also:
        Constant Field Values
      • DOC_COMMENT_TAG_ADDED

        public static final String DOC_COMMENT_TAG_ADDED
        L10N key for the "tag added" document edit comment.
        See Also:
        Constant Field Values
    • Method Detail

      • getAllTags

        public List<String> getAllTags​(XWikiContext context)
                                throws XWikiException
        Get all tags within the wiki.
        Parameters:
        context - XWiki context.
        Returns:
        list of tags (alphabetical order).
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
      • getTagCount

        public Map<String,​Integer> getTagCount​(XWikiContext context)
                                              throws XWikiException
        Get cardinality map of tags within the wiki.
        Parameters:
        context - XWiki context.
        Returns:
        map of tags (alphabetical order) with their occurences counts.
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
      • getTagCount

        public Map<String,​Integer> getTagCount​(String spaceReference,
                                                     XWikiContext context)
                                              throws XWikiException
        Get cardinality map of tags for a specific wiki space (including sub spaces).
        Parameters:
        spaceReference - the local reference of the space to get tags from. If blank, return tags for the whole wiki.
        context - XWiki context.
        Returns:
        map of tags (alphabetical order) with their occurrences counts.
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
        Since:
        1.2
      • getTagCountForSpaces

        public Map<String,​Integer> getTagCountForSpaces​(String spaces,
                                                              XWikiContext context)
                                                       throws XWikiException
        Get cardinality map of tags for a list of wiki spaces (including sub spaces). For example "'Main','Sandbox'" for all tags in the "Main" and "Sandbox" spaces, or "'Apo''stroph'" for all tags in the space "Apo'stroph".
        Parameters:
        spaces - the list of space to get tags in, as a comma separated, quoted space references strings.
        context - XWiki context.
        Returns:
        map of tags with their occurences counts
        Throws:
        XWikiException - if search query fails (possible failures: space list parse error, DB problems, etc).
        Since:
        8.2M1
      • getTagCountForQuery

        public Map<String,​Integer> getTagCountForQuery​(String fromHql,
                                                             String whereHql,
                                                             List<?> parameterValues,
                                                             XWikiContext context)
                                                      throws XWikiException
        Get cardinality map of tags matching a parameterized hql query.
        Parameters:
        fromHql - the from fragment of the hql query
        whereHql - the where fragment of the hql query
        parameterValues - list of parameter values for the query
        context - XWiki context.
        Returns:
        map of tags (alphabetical order) with their occurrences counts.
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
        Since:
        1.18
        See Also:
        TagPluginApi.getTagCountForQuery(String, String, java.util.List)
      • getDocumentsWithTag

        public List<String> getDocumentsWithTag​(String tag,
                                                XWikiContext context)
                                         throws XWikiException
        Get non-hidden documents with the given tags.
        Parameters:
        tag - a list of tags to match.
        context - XWiki context.
        Returns:
        list of docNames.
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
      • getDocumentsWithTag

        public List<String> getDocumentsWithTag​(String tag,
                                                boolean includeHiddenDocuments,
                                                XWikiContext context)
                                         throws XWikiException
        Get documents with the given tags.
        Parameters:
        tag - a list of tags to match.
        includeHiddenDocuments - if true then also include hidden documents
        context - XWiki context.
        Returns:
        list of docNames.
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
        Since:
        6.2M1
      • getTagsFromDocument

        public List<String> getTagsFromDocument​(String documentName,
                                                XWikiContext context)
                                         throws XWikiException
        Get tags from a document.
        Parameters:
        documentName - name of the document.
        context - XWiki context.
        Returns:
        list of tags.
        Throws:
        XWikiException - if document read fails (possible failures: insufficient rights, DB access problems, etc).
      • getTagsFromDocument

        public List<String> getTagsFromDocument​(XWikiDocument document,
                                                XWikiContext context)
                                         throws XWikiException
        Get tags from a document.
        Parameters:
        document - the document.
        context - XWiki context.
        Returns:
        list of tags.
        Throws:
        XWikiException - if document read fails (possible failures: insufficient rights, DB access problems, etc).
      • addTagToDocument

        public TagOperationResult addTagToDocument​(String tag,
                                                   String documentName,
                                                   XWikiContext context)
                                            throws XWikiException
        Add a tag to a document. The document is saved (minor edit) after this operation.
        Parameters:
        tag - tag to set.
        documentName - name of the document.
        context - XWiki context.
        Returns:
        the result of the operation
        Throws:
        XWikiException - if document save fails (possible failures: insufficient rights, DB access problems, etc).
      • addTagToDocument

        public TagOperationResult addTagToDocument​(String tag,
                                                   XWikiDocument document,
                                                   XWikiContext context)
                                            throws XWikiException
        Add a tag to a document. The document is saved (minor edit) after this operation.
        Parameters:
        tag - tag to set.
        document - the document.
        context - XWiki context.
        Returns:
        the result of the operation
        Throws:
        XWikiException - if document save fails (possible failures: insufficient rights, DB access problems, etc).
      • addTagsToDocument

        public TagOperationResult addTagsToDocument​(String tags,
                                                    String documentName,
                                                    XWikiContext context)
                                             throws XWikiException
        Add a list of tags to a document. The document is saved (minor edit) after this operation.
        Parameters:
        tags - the comma separated list of tags to set; whitespace around the tags is stripped
        documentName - the name of the target document
        context - the current request context.
        Returns:
        the result of the operation. TagOperationResult.NO_EFFECT is returned only if all the tags were already set on the document, TagOperationResult.OK is returned even if only some of the tags are new.
        Throws:
        XWikiException - if document save fails (possible failures: insufficient rights, DB access problems, etc).
      • addTagsToDocument

        public TagOperationResult addTagsToDocument​(String tags,
                                                    XWikiDocument document,
                                                    XWikiContext context)
                                             throws XWikiException
        Add a list of tags to a document. The document is saved (minor edit) after this operation.
        Parameters:
        tags - the comma separated list of tags to set; whitespace around the tags is stripped
        document - the target document
        context - the current request context
        Returns:
        the result of the operation. TagOperationResult.NO_EFFECT is returned only if all the tags were already set on the document, TagOperationResult.OK is returned even if only some of the tags are new.
        Throws:
        XWikiException - if document save fails (possible failures: insufficient rights, DB access problems, etc).
      • removeTagFromDocument

        public TagOperationResult removeTagFromDocument​(String tag,
                                                        String documentName,
                                                        XWikiContext context)
                                                 throws XWikiException
        Remove a tag from a document. The document is saved (minor edit) after this operation.
        Parameters:
        tag - tag to remove.
        documentName - name of the document.
        context - XWiki context.
        Returns:
        the result of the operation
        Throws:
        XWikiException - if document save fails for some reason (Insufficient rights, DB access, etc).
      • removeTagFromDocument

        public TagOperationResult removeTagFromDocument​(String tag,
                                                        XWikiDocument document,
                                                        XWikiContext context)
                                                 throws XWikiException
        Remove a tag from a document. The document is saved (minor edit) after this operation.
        Parameters:
        tag - tag to remove.
        document - the document.
        context - XWiki context.
        Returns:
        the result of the operation
        Throws:
        XWikiException - if document save fails for some reason (Insufficient rights, DB access, etc).