Theory of core-level spectroscopy of rare-earth oxides