Move factorizable code in ol.TileUrlFunction.expandUrl
Remove expandUrl duplicated code from createFromTemplate

and make use of expandUrl function instead.