Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forumsparsing a jst to a dom tree
https://www.eclipse.org/forums/index.php/mv/msg/52939/168976/#msg_168976
This is the way i'm doing it now, but i'm guessing it's not the suitable
one:
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new
Path("/test/page.jsp"));
JSPModelLoader l = new JSPModelLoader();
DocumentFactoryForJSP f = new DocumentFactoryForJSP();
DOMModelForJSP jspModel=(DOMModelForJSP)l.newModel();
jspModel.setStructuredDocument((IStructuredDocument)f.create Document());
l.load(file,jspModel);
is there a view other then the content outline useful to display a dom tree?
thanks]]>Alessandro Fredianelli2006-05-10T23:53:49-00:00Re: parsing a jst to a dom tree
https://www.eclipse.org/forums/index.php/mv/msg/52939/168992/#msg_168992
<alessandro.fredianelli@italtbs.com> wrote:
> what's the best way to parse a jsp file and produce a dom tree?
Like you were to get an IFile, then ...
IModelManager mm = StructuredModelManger.getModelManger();
// every 'get' needs a 'release'
IStrucutredModel sm = mm.getModelForEdit(file);
try {
// you should check instanceof and cast here, etc., here, to be sure model
is what you
// expected, and plan to deal with.
Docuemnt dom = sm.getDocument();
// do your DOM work here
}
finally {
if (sm != null) {
sm.release();
}
}
This DOM is, as you'd expect, sort of special (since for possibly
illformed text) and
is "shared" by others accessing it via the model manager ... which is
usually what you'd
want ... but, that's why the try/finally release is needed (as it is with
any shared resource).
the getModelForEdit and getModelForRead differ only in that those who get
it "for edit" are expected so save it if they are the last one hold it
before released. Where as "for read" means you don't care about saving it
... you just want to display what it is, etc.]]>David Williams2006-05-11T02:34:54-00:00