Characterization of Riesz and Bessel potentials on variable Lebesgue spaces