|
Re: parsing a jst to a dom tree [message #168992 is a reply to message #168976] |
Thu, 11 May 2006 02:34 |
David Williams Messages: 722 Registered: July 2009 |
Senior Member |
|
|
On Wed, 10 May 2006 19:53:49 -0400, Alessandro Fredianelli
<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.
|
|
|
Powered by
FUDForum. Page generated in 0.02421 seconds