org.molgenis.omx.decorators
Class NameConvention

java.lang.Object
  extended by org.molgenis.omx.decorators.NameConvention

public class NameConvention
extends Object

This class contains functions to enforce the XGAP naming policy for entities and storing files that belong to certain entities.

Author:
joerivandervelde

Constructor Summary
NameConvention()
           
 
Method Summary
static String escapeEntityNameStrict(String name)
          Converts an entity name into its safe version, so that they can be used in contexts such as programming environments where strict names are needed.
static String escapeFileName(String name)
          Converts file name into its safe version, so that they can be safely stored on any file system.
static void validateEntityName(String name)
          Validates an entity name, checking that only characters from the set [<>/a-zA-Z0-9_\\s\\-:.(),;\\+] are used.
static
<E extends Identifiable>
void
validateEntityNames(List<E> entities)
          Validate names of Entities by wrapping NameConvention.validateEntityName(name)
static
<E extends Identifiable>
void
validateEntityNamesStrict(List<E> entities)
          Validate names of Entities by wrapping NameConvention.validateEntityNameStrict(name)
static void validateEntityNameStrict(String name)
          Validates an entity name, so that they can be used in contexts such as programming environments where strict names are needed.
static void validateFileName(String name)
          Validates a file name, so that they can be safely stored on any file system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NameConvention

public NameConvention()
Method Detail

escapeFileName

public static String escapeFileName(String name)
                             throws DatabaseException
Converts file name into its safe version, so that they can be safely stored on any file system. Trims, then converts uppercase alphabetic characters to lowercase. Then only leaves alphabetic characters, numbers and underscore in the output. The output is then truncated at 50 characters. If the output ends up with length 0, a DatabaseException is thrown. Note that filenames are allowed to start with numerals, while entitynames are not. In practice however, to-be filenames are already checked as being valid entitynames first.

Parameters:
input -
Returns:
Throws:
Exception
DatabaseException

escapeEntityNameStrict

public static String escapeEntityNameStrict(String name)
                                     throws DatabaseException
Converts an entity name into its safe version, so that they can be used in contexts such as programming environments where strict names are needed. Trims, then leaves only alphabetic characters, numerals and underscores. Then removes any heading numerals. A DatabaseException is thrown if the final output has length 0. Eg. "123name" becomes "name", "x123nAmE" stays "x123nAmE", and "@#23" becomes "", which will throw an exception. This is the inverse of 'validateEntityNameStrict'.

Parameters:
name -
Returns:
Throws:
Exception
DatabaseException

validateFileName

public static void validateFileName(String name)
                             throws DatabaseException
Validates a file name, so that they can be safely stored on any file system. Throws a DatabaseException when input is empty or untrimmed, if other characters than lowercase alphabetics, numbers or underscore are used, or when the name is longer than 50 characters. Note that filenames are allowed to start with numerals, while entitynames are not. In practice however, to-be filenames are already checked as being valid entitynames first.

Throws:
DatabaseException

validateEntityName

public static void validateEntityName(String name)
                               throws DatabaseException
Validates an entity name, checking that only characters from the set [<>/a-zA-Z0-9_\\s\\-:.(),;\\+] are used.

Parameters:
name -
Throws:
DatabaseException

validateEntityNameStrict

public static void validateEntityNameStrict(String name)
                                     throws DatabaseException
Validates an entity name, so that they can be used in contexts such as programming environments where strict names are needed. Throws a DatabaseException when this name is empty or untrimmed, if other characters than alphabetics, numerals or underscore are used, or when the name starts with a numeral.

Parameters:
name -
Throws:
DatabaseException

validateEntityNames

public static <E extends Identifiable> void validateEntityNames(List<E> entities)
                                throws DatabaseException
Validate names of Entities by wrapping NameConvention.validateEntityName(name)

Type Parameters:
E -
Parameters:
entities -
Throws:
DatabaseException

validateEntityNamesStrict

public static <E extends Identifiable> void validateEntityNamesStrict(List<E> entities)
                                      throws DatabaseException
Validate names of Entities by wrapping NameConvention.validateEntityNameStrict(name)

Type Parameters:
E -
Parameters:
entities -
Throws:
DatabaseException


Copyright © 2013. All Rights Reserved.