Package com.atlassian.confluence.util
Class LabelUtil
java.lang.Object
com.atlassian.confluence.util.LabelUtil
Utility class designed to assist dealing with the client interface. In particular, the conversion from
 a string to a label and back, and the conversion from a list of strings to a list of labels and back.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe canonical delimiter in outputstatic final StringThe characters accepted as label delimitersstatic final StringThe name of the form field containing the space separated labelsstatic final intThe maximum number of labels allowed on a page or space.static final intThe maximum number of labels we allow to be entered via a single sumbission from the user interface.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic LabeladdLabel(String labelReference, LabelManager labelManager, Labelable object) Adds the label to the specified object.static LabeladdLabel(String labelReference, LabelManager labelManager, Labelable object, ConfluenceUser user) Adds the label to the specified object.static StringconvertToDelimitedString(Labelable obj, com.atlassian.user.User user) Helper method converting list of labels associated with the labelable object into a space separated string of the label names.static StringconvertToDelimitedString(List<?> names) static intcountLabelNamesWithoutFavourites(Collection<String> labelNames) Deprecated.static intcountLabels(String input) Counts the labels present in an input string.static intcountLabelsWithoutFavourites(String labelsString) Counts the labels present in an input string.static intcountLabelsWithoutFavourites(Collection<Label> labels) Counts the labels present in an input collection.static intCounts the labels present in an input collection.extractLabelsFromLabellings(List<Labelling> labellings) Simple utility method to extract the label instances from the given list of labelling instances.static voidDeprecated, for removal: This API element is subject to removal in a future version.since 9.1, useStream.map(java.util.function.Function<? super T, ? extends R>)instead.static com.atlassian.core.util.filter.ListFiltergetLabelFilters(com.atlassian.user.User user, boolean hideSpecialLabels) returns only labels the user can see and also strips out special labels if 'hideSpecialLabels' flag is setstatic com.google.common.base.Predicate<Label> getLabelPredicate(com.atlassian.user.User user, boolean hideSpecialLabels) Deprecated.since 7.0.1.getLabelsFor(String labels, LabelManager labelManager) static StringgetLabelsHash(List<Label> labels) getRecentAndPopularLabels(String spaceKey, LabelManager labelManager, int maxResults, String user) getRecentAndPopularLabelsForEntity(ContentEntityObject entity, LabelManager labelManager, int maxResults, String user) getVisibleLabelNames(List<Label> labels, String username) Get a list of the visible label names for this content.static booleanisFavouriteLabel(@Nullable ParsedLabelName label) Checks if the given label is of "Favourite" type (LabelManager.FAVOURITE_LABELorLabelManager.FAVOURITE_LABEL_YANKEE).static booleanisFavouriteLabel(Label label) Checks if the given label is of "Favourite" type (LabelManager.FAVOURITE_LABELorLabelManager.FAVOURITE_LABEL_YANKEE).static booleanisFavouriteLabel(String labelName) Deprecated.since 6.0, useisFavouriteLabel(ParsedLabelName)static booleanisValidLabelLength(String input) static booleanisValidLabelLengths(String concatenatedLabelNames) static booleanisValidLabelLengths(Collection<String> labelNames) static booleanisValidLabelName(String labelName) static booleanisValidLabelNames(String delimitedLabelNames) static booleanisValidLabelNames(Collection<String> names) static StringlabelPredicate(com.atlassian.user.User user, boolean hideSpecialLabels) static List<RankedLabelSearchResult> rankResults(List<LabelSearchResult> results) static voidSplit the input string according to the label delimitation rules.static booleansyncState(String source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest) Neat method that will synchronize a space separated list of label names with the labels contained within the labelable object.static booleansyncState(String source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest, boolean ignored) Deprecated.since 5.1.static booleansyncState(Collection<String> labelNames, LabelManager labelManager, com.atlassian.user.User user, Labelable dest) static booleansyncState(List<Label> source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest) 
- 
Field Details- 
LABEL_DELIM_CHARSThe characters accepted as label delimiters- See Also:
 
- 
LABEL_DELIMThe canonical delimiter in output- See Also:
 
- 
MAX_ALLOWED_LABELS_PER_INPUTpublic static final int MAX_ALLOWED_LABELS_PER_INPUTThe maximum number of labels we allow to be entered via a single sumbission from the user interface.- See Also:
 
- 
MAX_ALLOWED_LABELSpublic static final int MAX_ALLOWED_LABELSThe maximum number of labels allowed on a page or space.- See Also:
 
- 
LABELS_STRINGThe name of the form field containing the space separated labels- See Also:
 
 
- 
- 
Constructor Details- 
LabelUtilpublic LabelUtil()
 
- 
- 
Method Details- 
convertToDelimitedStringHelper method converting list of labels associated with the labelable object into a space separated string of the label names.
- 
convertToDelimitedString
- 
joinIds
- 
isValidLabelNames- Parameters:
- delimitedLabelNames- contains a list of label names delimited by- LABEL_DELIM_CHARS
- Returns:
- true if the delimitedLabelNames represents a string of valid label names, false otherwise.
 
- 
isValidLabelNames- Parameters:
- names- a collection of label names as- Strings.
- Returns:
- true if the delimitedLabelNames represents a string of valid label names, false otherwise.
 
- 
isValidLabelName
- 
isValidLabelLengths
- 
isValidLabelLengths
- 
isValidLabelLength
- 
getVisibleLabelNamesGet a list of the visible label names for this content. System labels and personal labels that do not belong to this user will be stripped. Visible non-global label names will have their namespace prefixed( i.e. my:foo, team:bar)
- 
splitSplit the input string according to the label delimitation rules.- Parameters:
- input- space separated string of labels
- Returns:
- a collection of strings, each representing a label name, in the order in which they appeared in the original input. Duplicates excluded.
 
- 
countLabelsCounts the labels present in an input string. Counts each appearance of duplicate labels.- Parameters:
- input- a string of labels delimited by the characters in- LABEL_DELIM_CHARS. May be null or empty.
- Returns:
- the number of labels present in the string. Returns 0 for empty or null strings.
 
- 
isFavouriteLabelDeprecated.since 6.0, useisFavouriteLabel(ParsedLabelName)Checks if the given label is of "Favourite" type (LabelManager.FAVOURITE_LABELorLabelManager.FAVOURITE_LABEL_YANKEE).- Parameters:
- labelName- labelName
- Returns:
- trueif the argument name represents "favourite" label
 
- 
isFavouriteLabelChecks if the given label is of "Favourite" type (LabelManager.FAVOURITE_LABELorLabelManager.FAVOURITE_LABEL_YANKEE).- Parameters:
- label- parsed label
- Returns:
- trueif the argument name represents "favourite" label
 
- 
isFavouriteLabelChecks if the given label is of "Favourite" type (LabelManager.FAVOURITE_LABELorLabelManager.FAVOURITE_LABEL_YANKEE).- Parameters:
- label- label
- Returns:
- trueif the argument name represents "favourite" label
 
- 
countLabelsWithoutFavouritesCounts the labels present in an input string. Counts each appearance of duplicate labels. Labels of type "Favourite" (LabelManager.FAVOURITE_LABELandLabelManager.FAVOURITE_LABEL_YANKEE) are ignored.- Parameters:
- labelsString- a string of labels delimited by the characters in- LABEL_DELIM_CHARS. May be null or empty.
- Returns:
- the number of labels present in the string. Returns 0 for empty or null strings.
 
- 
countLabelNamesWithoutFavouritesDeprecated.since 6.0 , use {countParsedLabelNamesWithoutFavourites(Collection)}Counts the labels present in an input collection. Counts each appearance of duplicate labels. Labels of type "Favourite" (LabelManager.FAVOURITE_LABELandLabelManager.FAVOURITE_LABEL_YANKEE) are ignored.- Parameters:
- labelNames- a collection of labels names
- Returns:
- the number of labels present in the collection.
 
- 
countParsedLabelNamesWithoutFavouritesCounts the labels present in an input collection. Counts each appearance of duplicate labels. Labels of type "Favourite" (LabelManager.FAVOURITE_LABELandLabelManager.FAVOURITE_LABEL_YANKEE) are ignored.- Parameters:
- labels- a collection of parsed labels
- Returns:
- the number of labels present in the collection.
 
- 
countLabelsWithoutFavouritesCounts the labels present in an input collection. Counts each appearance of duplicate labels. Labels of type "Favourite" (LabelManager.FAVOURITE_LABELandLabelManager.FAVOURITE_LABEL_YANKEE) are ignored.- Parameters:
- labels- a collection of labels
- Returns:
- the number of labels present in the collection.
 
- 
syncState@Deprecated public static boolean syncState(String source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest, boolean ignored) Deprecated.since 5.1. UsesyncState(String, LabelManager, User, Labelable)Neat method that will synchronize a space separated list of label names with the labels contained within the labelable object. Labels that do not exist in the comma separated list will be removed, and labels that appear in the comma separated list will be created.- Parameters:
- source- is a space separated list of label names, eg: the following list "LabelA LabelB LabelC" will be converted into label instances with the names 'LabelA', 'LabelB' and 'LabelC'
- ignored- is ignored
 
- 
syncStatepublic static boolean syncState(String source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest) Neat method that will synchronize a space separated list of label names with the labels contained within the labelable object. Labels that do not exist in the comma separated list will be removed, and labels that appear in the comma separated list will be created.- Parameters:
- source- is a space separated list of label names, eg: the following list "LabelA LabelB LabelC" will be converted into label instances with the names 'LabelA', 'LabelB' and 'LabelC'
 
- 
syncStatepublic static boolean syncState(List<Label> source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest) 
- 
syncStatepublic static boolean syncState(Collection<String> labelNames, LabelManager labelManager, com.atlassian.user.User user, Labelable dest) 
- 
addLabelAdds the label to the specified object. The label is a string in the form of an unparsed label, and is validated byisValidLabelName(String)andisValidLabelLength(String).If the label can't be added, already exists, or is invalid, this method returns null. - Returns:
- the label that was created and added or null if no label was added.
 
- 
addLabelpublic static Label addLabel(String labelReference, LabelManager labelManager, Labelable object, ConfluenceUser user) Adds the label to the specified object. The label is a string in the form of an unparsed label, and is validated byisValidLabelName(String)andisValidLabelLength(String).If the label can't be added, already exists, or is invalid, this method returns null. - Parameters:
- user- The user to associate with the label, regardless of the label reference.
- Returns:
- the label that was created and added or null if no label was added.
 
- 
recordLabelInteractionInHistory
- 
rankResults
- 
getRecentAndPopularLabelsForEntitypublic static List<Label> getRecentAndPopularLabelsForEntity(ContentEntityObject entity, LabelManager labelManager, int maxResults, String user) 
- 
getRecentAndPopularLabelspublic static List<Label> getRecentAndPopularLabels(String spaceKey, LabelManager labelManager, int maxResults, String user) 
- 
fixLabelsDeprecated, for removal: This API element is subject to removal in a future version.since 9.1, useStream.map(java.util.function.Function<? super T, ? extends R>)instead.
- 
extractLabelsFromLabellingsSimple utility method to extract the label instances from the given list of labelling instances.- Returns:
- a new list containing the referenced Labelinstances.
 
- 
getLabelPredicate@Deprecated public static com.google.common.base.Predicate<Label> getLabelPredicate(com.atlassian.user.User user, boolean hideSpecialLabels) Deprecated.since 7.0.1. UselabelPredicate(User, boolean)
- 
labelPredicatepublic static Predicate<Label> labelPredicate(com.atlassian.user.User user, boolean hideSpecialLabels) - Since:
- 7.0.1
 
- 
getLabelFilterspublic static com.atlassian.core.util.filter.ListFilter getLabelFilters(com.atlassian.user.User user, boolean hideSpecialLabels) returns only labels the user can see and also strips out special labels if 'hideSpecialLabels' flag is set
- 
getLabelsFor
- 
getLabelsHash
 
- 
countParsedLabelNamesWithoutFavourites(Collection)}