*
* @param filename @return
*/
public boolean parse(String filePathString) {
boolean parsed = false;
IStructuredDocument document = null;
String contents = null;
IPath filePath = new Path(filePathString);
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
if (f == null || !f.isAccessible()) {
f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filePath);
}
if (f != null && f.isAccessible()) {
/*
* using a real document allows us to pull out text in the
* translator for dealing with TEI variables
*/
try {
IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerFor(f, false);
if (handler == null)
handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId(ContentTypeIdForJSP.ContentTypeID_JSPFRAGMENT);
document = (IStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
contents = FileContentCache.getInstance().getContents(f.getFullPath());
}
catch (CoreException e) {
Logger.logException(e);
}
}
if (contents != null && document != null) {
// from outer class
List blockMarkers = this.fTranslator.getBlockMarkers();
// this adds the current markers from the outer class list
// to this parser so parsing works correctly
for (int i = 0; i < blockMarkers.size(); i++) {
addBlockMarker((BlockMarker) blockMarkers.get(i));
}
reset(contents);
// forces parse
document.set(contents);
IStructuredDocumentRegion cursor = document.getFirstStructuredDocumentRegion();
while (cursor != null) {
nodeParsed(cursor);
cursor = cursor.getNext();
}
parsed = true;