This should work but you also need to update the paths within the XAR. For instance if you rename the page A.B.C in X.Y.Z then you need to rename/move the file A/B/C.xml into X/Y/Z.xml within the XAR. And you probably have to update the XAR package descriptor (pacakge.xml).
Could work, but might not be that easy. Depends on your groovy skills and how well you know the XWiki API.