static public boolean isValidTemplateName ( String name ) { // First do the easy check to make sure that the string isn't empty and // contains only valid characters. if ( ! validTemplateNameChars . matcher ( name ) . matches ( ) ) { return false ; } // Split the string on slashes and ensure that each one of the terms is // valid. Cannot be empty or start with a period. (Above check already // guarantees that only allowed characters are in the string.) for ( String t : name . split ( "/" ) ) { if ( "" . equals ( t ) || t . startsWith ( "." ) ) { return false ; } } // If we make it to this point, then the string has passed all of the // checks and is valid. return true ; }
Check to see if the given name is a valid template name . Valid template names may include only letters digits underscores hyphens periods pluses and slashes . In addition each term when split by slashes must not be empty and must not start with a period . The second case excludes potential hidden files and special names like . and .. .