Resource.getSourceText();

Typically you will use this in concert with Element.getEndOffset() - find the location of something of interest and then check the text around it for something.

Source: NetBeans FAQ