Is the paint bubbling EVERYWHERE the shaving cream was or is it in just one spot?
If its just like a small spot on the bonnet etc only, then at worst, your friend may be asked to pay for half the cost of repainting the effected panel, if that.
There is no way in hell the magistrate will make him pay for a complete repaint, letalone a different colour, if its only damaged in one particular area.
BUT If the whole paintwork has this bubbling on it, then the magistrate may ask for a complete repaint, but not in a different colour.
Thats if you friend pleads guilty to actually doing it....If he doesnt admit to doing it and there is no proof, all the XF owner is going to be getting is court fees.