Class TagPluginApi


  • public class TagPluginApi
    extends PluginApi<TagPlugin>
    API for the TagPlugin. TagPlugin is a plugin that allows to manipulate tags easily. It allows to get, rename and delete tags.
    Version:
    $Id: 1104af5e5b05d00e47db4e19049e34febd060299 $
    See Also:
    PluginApi
    • Method Detail

      • getAllTags

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

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

        public Map<String,​Integer> getTagCount​(String space)
                                              throws XWikiException
        Get cardinality map of tags for a specific wiki space.
        Parameters:
        space - the space to get tags in
        Returns:
        map of tags with their occurences counts
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
        Since:
        1.2
      • getTagCountForSpaces

        public Map<String,​Integer> getTagCountForSpaces​(String spaces)
                                                       throws XWikiException
        Get cardinality map of tags for list wiki spaces.
        Parameters:
        spaces - the list of space to get tags in, as a comma separated, quoted string
        Returns:
        map of tags with their occurences counts
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
        Since:
        8.1
      • getTagCountForQuery

        public Map<String,​Integer> getTagCountForQuery​(String from,
                                                             String where)
                                                      throws XWikiException
        Get cardinality map of tags matching an hql query. Examples of usage:
        • $xwiki.tag.getTagCountForQuery("","doc.creator='XWiki.JohnDoe'") will return the cardinality map of tags for documents created by user XWiki.JohnDoe
        • $xwiki.tag.getTagCountForQuery(", BaseObject as obj", "obj.name=doc.fullName and obj.className='Blog.BlogPostClass'") will return the cardinality map of tags associated to blog post documents
        • $xwiki.tag.getTagCountForQuery("", "") will return all tags within the wiki
        Parameters:
        from - the from fragment of the query
        where - the where fragment from the query
        Returns:
        map of tags with their occurrences counts
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, incorrect query fragments).
        Since:
        1.2
        See Also:
        getTagCountForQuery(String, String, java.util.List)
      • getTagCountForQuery

        public Map<String,​Integer> getTagCountForQuery​(String from,
                                                             String where,
                                                             List<?> parameterValues)
                                                      throws XWikiException
        Get cardinality map of tags matching an hql query (parameterized version). Example of usage:
        • $xwiki.tag.getTagCountForQuery("", "doc.creator = ?1", ["$!{request.creator}"]) will return the cardinality map of tags for documents created by user-provided creator name
        Parameters:
        from - the from fragment of the query
        where - the parameterized where fragment from the query
        parameterValues - list of parameter values for the query
        Returns:
        map of tags with their occurrences counts
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, incorrect query fragments).
        Since:
        1.18
      • getTagCountForQuery

        public Map<String,​Integer> getTagCountForQuery​(String from,
                                                             String where,
                                                             Map<String,​?> parameters)
                                                      throws XWikiException
        Get cardinality map of tags matching an hql query (parameterized version). Example of usage:
        • $xwiki.tag.getTagCountForQuery("", "doc.creator = :creator", {'creator' : "$!{request.creator}"}) will return the cardinality map of tags for documents created by user-provided creator name
        Parameters:
        from - the from fragment of the query
        where - the parameterized where fragment from the query
        parameters - map of named parameters for the query
        Returns:
        map of tags with their occurrences counts
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, incorrect query fragments).
        Since:
        11.7RC1
      • getDocumentsWithTag

        public List<String> getDocumentsWithTag​(String tag)
                                         throws XWikiException
        Get all the documents containing the given tag.
        Parameters:
        tag - tag to match.
        Returns:
        list of pages.
        Throws:
        XWikiException - if search query fails (possible failures: DB access problems, etc).
      • getTagsFromDocument

        public List<String> getTagsFromDocument​(String documentName)
                                         throws XWikiException
        Get tags from a document.
        Parameters:
        documentName - name of the document.
        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)
        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.
        Returns:
        the result of the operation
      • addTagsToDocument

        public TagOperationResult addTagsToDocument​(String tags,
                                                    String documentName)
        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
        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.
      • removeTagFromDocument

        public TagOperationResult removeTagFromDocument​(String tag,
                                                        String documentName)
        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.
        Returns:
        the result of the operation
      • renameTag

        public TagOperationResult renameTag​(String tag,
                                            String newTag)
        Rename a tag in all the documents that contains it. Requires admin rights. Document containing this tag are saved (minor edit) during this operation.
        Parameters:
        tag - tag to rename.
        newTag - new tag.
        Returns:
        the result of the operation
      • deleteTag

        public TagOperationResult deleteTag​(String tag)
        Delete a tag from all the documents that contains it. Requires admin rights. Document containing this tag are saved (minor edit) during this operation.
        Parameters:
        tag - tag to delete.
        Returns:
        the result of the operation