com.atlassian.confluence.util
Class LabelUtil

java.lang.Object
  extended by com.atlassian.confluence.util.LabelUtil

public final class LabelUtil
extends java.lang.Object

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 Summary
static java.lang.String LABEL_DELIM
          The canonical delimiter in output
static java.lang.String LABEL_DELIM_CHARS
          The characters accepted as label delimiters
static int MAX_ALLOWED_LABELS
          The maximum number of labels allowed on a page or space.
static int MAX_ALLOWED_LABELS_PER_INPUT
          The maximum number of labels we allow to be entered via a single sumbission from the user interface.
 
Constructor Summary
LabelUtil()
           
 
Method Summary
static Label addLabel(java.lang.String labelReference, LabelManager labelManager, Labelable object)
          Adds the label to the specified object.
static boolean addLabel(java.lang.String labelReference, LabelManager labelManager, com.atlassian.user.User user, Labelable dest)
          Deprecated. since 2.9
static java.lang.String convertToDelimitedString(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 java.lang.String convertToDelimitedString(java.util.List names)
           
static int countLabels(java.lang.String input)
          Counts the labels present in an input string.
static java.util.List<Label> extractLabelsFromLabellings(java.util.List<Labelling> labellings)
          Simple utility method to extract the label instances from the given list of labelling instances.
static void fixLabels(java.util.List suggestedLabels)
           
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
static java.util.List getRecentAndPopularLabels(java.lang.String spaceKey, LabelManager labelManager, int maxResults, java.lang.String user)
           
static java.util.List getRecentAndPopularLabelsForEntity(ContentEntityObject entity, LabelManager labelManager, int maxResults, java.lang.String user)
           
static java.util.List getVisibleLabelNames(java.util.List labels, java.lang.String username)
          Get a list of the visible label names for this content.
static boolean isValidLabelLength(java.lang.String input)
           
static boolean isValidLabelLengths(java.util.Collection labelNames)
           
static boolean isValidLabelLengths(java.lang.String concatenatedLabelNames)
           
static boolean isValidLabelName(java.lang.String labelName)
           
static boolean isValidLabelNames(java.util.Collection names)
           
static boolean isValidLabelNames(java.lang.String delimitedLabelNames)
           
static java.lang.String joinIds(java.util.List labels, java.lang.String separator)
           
static java.util.List rankResults(java.util.List results)
           
static void recordLabelInteractionInHistory(Label label)
           
static java.util.List<java.lang.String> split(java.lang.String input)
          Split the input string according to the label delimitation rules.
static boolean syncState(java.lang.String source, LabelManager labelManager, com.atlassian.user.User user, Labelable dest, boolean removeUnusedLabels)
          Neat method that will synchronize a space separated list of label names with the labels contained within the labelable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LABEL_DELIM_CHARS

public static final java.lang.String LABEL_DELIM_CHARS
The characters accepted as label delimiters

See Also:
Constant Field Values

LABEL_DELIM

public static final java.lang.String LABEL_DELIM
The canonical delimiter in output

See Also:
Constant Field Values

MAX_ALLOWED_LABELS_PER_INPUT

public static final int MAX_ALLOWED_LABELS_PER_INPUT
The maximum number of labels we allow to be entered via a single sumbission from the user interface.

See Also:
Constant Field Values

MAX_ALLOWED_LABELS

public static final int MAX_ALLOWED_LABELS
The maximum number of labels allowed on a page or space.

See Also:
Constant Field Values
Constructor Detail

LabelUtil

public LabelUtil()
Method Detail

convertToDelimitedString

public static java.lang.String convertToDelimitedString(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.


convertToDelimitedString

public static java.lang.String convertToDelimitedString(java.util.List names)

joinIds

public static java.lang.String joinIds(java.util.List labels,
                                       java.lang.String separator)

isValidLabelNames

public static boolean isValidLabelNames(java.lang.String delimitedLabelNames)
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

public static boolean isValidLabelNames(java.util.Collection names)
Parameters:
names - a collection of label names as Strings.
Returns:
true if the delimitedLabelNames represents a string of valid label names, false otherwise.

isValidLabelName

public static boolean isValidLabelName(java.lang.String labelName)

isValidLabelLengths

public static boolean isValidLabelLengths(java.lang.String concatenatedLabelNames)

isValidLabelLengths

public static boolean isValidLabelLengths(java.util.Collection labelNames)

isValidLabelLength

public static boolean isValidLabelLength(java.lang.String input)

getVisibleLabelNames

public static java.util.List getVisibleLabelNames(java.util.List labels,
                                                  java.lang.String username)
Get 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)

Parameters:
labels - the list of Label objects to filter
username - the user who the list is being filtered for
Returns:
a list of the names of the labels as Strings that the user can see

split

public static java.util.List<java.lang.String> split(java.lang.String input)
Split the input string according to the label delimitation rules.

Parameters:
input -
Returns:
a collection of strings, each representing a label name, in the order in which they appeared in the original input.

countLabels

public static int countLabels(java.lang.String input)
Counts 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.

syncState

public static boolean syncState(java.lang.String source,
                                LabelManager labelManager,
                                com.atlassian.user.User user,
                                Labelable dest,
                                boolean removeUnusedLabels)
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.

If a label is removed and that label no longer labels any labelable content, then it will be deleted if the removeUnusedLabels is set to true.

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'

addLabel

public static boolean addLabel(java.lang.String labelReference,
                               LabelManager labelManager,
                               com.atlassian.user.User user,
                               Labelable dest)
Deprecated. since 2.9

See Also:
addLabel(String, LabelManager, Labelable)

addLabel

public static Label addLabel(java.lang.String labelReference,
                             LabelManager labelManager,
                             Labelable object)
Adds the label to the specified object. The label is a string in the form of an unparsed label, and is validated by isValidLabelName(String) and isValidLabelLength(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.

recordLabelInteractionInHistory

public static void recordLabelInteractionInHistory(Label label)

rankResults

public static java.util.List rankResults(java.util.List results)

getRecentAndPopularLabelsForEntity

public static java.util.List getRecentAndPopularLabelsForEntity(ContentEntityObject entity,
                                                                LabelManager labelManager,
                                                                int maxResults,
                                                                java.lang.String user)

getRecentAndPopularLabels

public static java.util.List getRecentAndPopularLabels(java.lang.String spaceKey,
                                                       LabelManager labelManager,
                                                       int maxResults,
                                                       java.lang.String user)

fixLabels

public static void fixLabels(java.util.List suggestedLabels)

extractLabelsFromLabellings

public static java.util.List<Label> extractLabelsFromLabellings(java.util.List<Labelling> labellings)
Simple utility method to extract the label instances from the given list of labelling instances.

Returns:
a new list containing the referenced Label instances.

getLabelFilters

public 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



Copyright © 2003-2010 Atlassian. All Rights Reserved.