writerfilter: refactor code to fill document grab bag

There were several chunks of identical code to add attributes to the
document grab bag. I have refactored the common code to a method.

Change-Id: Ia1de75280a7725ab9703b08b1b08e7a7d1e0a8f2