getText can be called only when doc is not None

Add a check to make sure getText is executed only when doc is
not None.
Without this check, we can potentially get:
AttributeError: 'NoneType' object has no attribute 'getText'

Change-Id: I8e2abd3abf015733642419cb8a3b86aec09c929f
Merge "getText can be called only when doc is not None"