A general factorization approach to the extension theory of nonnegative operators and relations