Proper Indentation Question

I used the appendRaw() method to write in my pre-written URScript to my program node, and I got it to function. However it only worked after I looked through the generated script from saving the program and found that I needed to indent the entire script 4 extra spaces for that specific program. The script itself was properly indented however when it first gets written it starts at 0 indentation so it wont work. As this is not a consistent form of making it work, how can I use java to have it automatically indented to the proper place when it is written into the script? Any input would be much appreciated.

Thanks!!