Energy-preserving methods for nonlinear Schrödinger equations