Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Programmatically adding imports to jsp file
Programmatically adding imports to jsp file [message #205931] Mon, 17 December 2007 13:22 Go to next message
Eclipse UserFriend
Originally posted by: Tanyu.Krasimirov.Trifonov.sap.com

Hi All,

I want to programmatically add some code to existing jsp file. First I
have to check if the required classes are already imported and if they’re
not – I have to add import statements. The problem is that I cannot find a
way how I can check if the import statement is already present – I tried
to use

IModelManager mm = StructuredModelManager.getModelManager();
IStructuredModel sm = null;
try {
sm = mm.getModelForEdit(jspFile);
} catch (IOException e) {}
catch(CoreException e){}

if (sm !=null && sm instanceof DOMModelForJSP){
DOMModelForJSP model = (DOMModelForJSP)sm;
IDOMDocument dom = model.getDocument();
}

if (sm != null){
sm.releaseFromEdit();
}

But I cannot figure out how I can get the already existing import
statements. Any help is appreciated.

Best regards,
Tanyu Trifonov
Re: Programmatically adding imports to jsp file [message #206000 is a reply to message #205931] Tue, 18 December 2007 00:25 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Tanyu Trifonov wrote:
> I want to programmatically add some code to existing jsp file. First I
> have to check if the required classes are already imported and if
> they�re not � I have to add import statements. The problem is that I
> cannot find a way how I can check if the import statement is already
> present � I tried to use
>
> IModelManager mm = StructuredModelManager.getModelManager();
> IStructuredModel sm = null;
> try {
> sm = mm.getModelForEdit(jspFile);
> } catch (IOException e) {}
> catch(CoreException e){}
>
> if (sm !=null && sm instanceof DOMModelForJSP){
> DOMModelForJSP model = (DOMModelForJSP)sm;
> IDOMDocument dom = model.getDocument();
> }
>
> if (sm != null){
> sm.releaseFromEdit();
> }
>
> But I cannot figure out how I can get the already existing import
> statements. Any help is appreciated.

You'll want to use org.w3c.dom.Document.getElementsByTagName(String)
on the IDOMDocument to find the jsp:directive.page elements
representing the page directives. From there you can look at the
attributes defining the import list.

---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Programmatically adding imports to jsp file [message #206062 is a reply to message #206000] Thu, 20 December 2007 08:35 Go to previous message
Eclipse UserFriend
Originally posted by: Tanyu.Krasimirov.Trifonov.sap.com

Hi Nitin,

Thank you very much for your help.

Regards,
Tanyu

Nitin Dahyabhai wrote:

> Tanyu Trifonov wrote:
>> I want to programmatically add some code to existing jsp file. First I
>> have to check if the required classes are already imported and if
>> theyᅵre not ᅵ I have to add import statements. The problem is that I
>> cannot find a way how I can check if the import statement is already
>> present ᅵ I tried to use
>>
>> IModelManager mm = StructuredModelManager.getModelManager();
>> IStructuredModel sm = null;
>> try {
>> sm = mm.getModelForEdit(jspFile);
>> } catch (IOException e) {}
>> catch(CoreException e){}
>>
>> if (sm !=null && sm instanceof DOMModelForJSP){
>> DOMModelForJSP model = (DOMModelForJSP)sm;
>> IDOMDocument dom = model.getDocument();
>> }
>>
>> if (sm != null){
>> sm.releaseFromEdit();
>> }
>>
>> But I cannot figure out how I can get the already existing import
>> statements. Any help is appreciated.

> You'll want to use org.w3c.dom.Document.getElementsByTagName(String)
> on the IDOMDocument to find the jsp:directive.page elements
> representing the page directives. From there you can look at the
> attributes defining the import list.

> ---
> Nitin Dahyabhai
> Eclipse WTP Source Editing
> IBM Rational
Previous Topic:Utility Module
Next Topic:Custom positioning of the dependency libraries when publishing EAR file to the JBoss server
Goto Forum:
  


Current Time: Tue Apr 16 21:19:39 GMT 2024

Powered by FUDForum. Page generated in 0.28863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top