public static void validate ( final License license ) { // A license should have a name if ( license . getName ( ) == null || license . getName ( ) . isEmpty ( ) ) { throw new WebApplicationException ( Response . status ( Response . Status . BAD_REQUEST ) . entity ( "License name should not be empty!" ) . build ( ) ) ; } // A license should have a long name if ( license . getLongName ( ) == null || license . getLongName ( ) . isEmpty ( ) ) { throw new WebApplicationException ( Response . status ( Response . Status . BAD_REQUEST ) . entity ( "License long name should not be empty!" ) . build ( ) ) ; } // If there is a regexp, it should compile if ( license . getRegexp ( ) != null && ! license . getRegexp ( ) . isEmpty ( ) ) { try { Pattern . compile ( license . getRegexp ( ) ) ; } catch ( PatternSyntaxException e ) { throw new WebApplicationException ( Response . status ( Response . Status . BAD_REQUEST ) . entity ( "License regexp does not compile!" ) . build ( ) ) ; } Pattern regex = Pattern . compile ( "[&%//]" ) ; if ( regex . matcher ( license . getRegexp ( ) ) . find ( ) ) { throw new WebApplicationException ( Response . status ( Response . Status . BAD_REQUEST ) . entity ( "License regexp does not compile!" ) . build ( ) ) ; } } }
Checks if the provided license is valid and could be stored into the database