Use archivematicaFunctions.escape?  Then you won't have to check if the attribute exists first.