Class NameUtil


  • public final class NameUtil
    extends java.lang.Object
    Utility methods for naming queries and lists.
    Author:
    Julie Sullivan
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String INVALID_NAME_MSG
      error message for bad names.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String findNewQueryName​(java.util.Set<java.lang.String> savedQueries)
      Return a query name that isn't currently in use.
      static java.lang.String findNewQueryName​(java.util.Set<java.lang.String> savedQueries, java.lang.String name)
      Return a query name that isn't currently in use, returning the given name if it is available.
      static java.lang.String generateNewName​(java.util.Set<java.lang.String> listNames, java.lang.String listName)
      Generate a new name for a list.
      static boolean isValidName​(java.lang.String name)
      Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes.
      static boolean isValidName​(java.lang.String name, boolean specialChars)
      Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes.
      static java.lang.String replaceSpecialChars​(java.lang.String name)
      Takes a string and replaces special characters with the text value, e.g.
      static java.lang.String validateName​(java.util.Collection<java.lang.String> names, java.lang.String name)
      Checks that the name doesn't already exist and returns a numbered name if it does.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INVALID_NAME_MSG

        public static final java.lang.String INVALID_NAME_MSG
        error message for bad names. should come from properties file instead, really
        See Also:
        Constant Field Values
    • Method Detail

      • isValidName

        public static boolean isValidName​(java.lang.String name)
        Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes. And spaces. And dots.
        Parameters:
        name - Name of bag/query/template to be validated
        Returns:
        isValid Returns true if this name is correct, false if this name contains a bad char
      • isValidName

        public static boolean isValidName​(java.lang.String name,
                                          boolean specialChars)
        Verifies names (bags, queries, etc) only contain A-Z, a-z, 0-9, underscores and dashes. if specialChars boolean is TRUE, then dot and space are allowed. If specialChars is FALSE, it likely means the name is going to be handled by javascript, in URLS, etc and we don't want to have to encode it. eg. template name.
        Parameters:
        name - Name of bag/query/template to be validated
        specialChars - if true, then special characters DOT and SPACE are allowed in name
        Returns:
        isValid Returns true if this name is correct, false if this name contains a bad char
      • replaceSpecialChars

        public static java.lang.String replaceSpecialChars​(java.lang.String name)
        Takes a string and replaces special characters with the text value, e.g. it would change "a&b" to "a_AMPERSAND_b". This is used in the query/template imports to handle special characters.
        Parameters:
        name - Name of query/template
        Returns:
        rebuiltName Name of query/template with the special characters removed
      • generateNewName

        public static java.lang.String generateNewName​(java.util.Set<java.lang.String> listNames,
                                                       java.lang.String listName)
        Generate a new name for a list. Used in situations where the user has a new list without creating one via the upload form, e.g. when copying or posting a list from another site
        Parameters:
        listName - original name for the list
        listNames - a list of all lists
        Returns:
        a unique name for the list
      • validateName

        public static java.lang.String validateName​(java.util.Collection<java.lang.String> names,
                                                    java.lang.String name)
        Checks that the name doesn't already exist and returns a numbered name if it does. Used in situations where prompting the user for a good name wouldn't work, eg. query import
        Parameters:
        name - the query or list name
        names - list of current names
        Returns:
        a validated name for the query
      • findNewQueryName

        public static java.lang.String findNewQueryName​(java.util.Set<java.lang.String> savedQueries)
        Return a query name that isn't currently in use.
        Parameters:
        savedQueries - the Map of current saved queries
        Returns:
        the new query name
      • findNewQueryName

        public static java.lang.String findNewQueryName​(java.util.Set<java.lang.String> savedQueries,
                                                        java.lang.String name)
        Return a query name that isn't currently in use, returning the given name if it is available.
        Parameters:
        savedQueries - the Map of current saved queries
        name - name to return if it's available
        Returns:
        the new query name