|Programmaticlly call XML Formatter [message #215151]
||Thu, 12 June 2008 11:43
| Anders Olsson
Registered: July 2009
Is there any way of - through another plug-in, programmatically - doing |
what WST does when you right-click an xml-file and choose:
I found someone who had a similar problem quite a while ago, but since the
thread is a monologue, it isn't very helpful.
I've been trying to use:
I've found no other (less ...provisional) Class for this.
This does work, despite the access being discouraged, but so far only for
String input. When I run the 'formatDocument(IDocument)' method, I get a
NPE on line 138 in
(R_2_0_2), because the structuredModel variable is null. The IDocument I
supply is from a JET transformation (and isn't null). Is there something
special expected of the supplied IDocument, or is there something I've
forgotten to init before calling the method?
Thanks in advance for any pointers whatsoever,
|Re: Programmaticlly call XML Formatter [message #217673 is a reply to message #217408]
||Wed, 16 July 2008 04:14
|| Nitin Dahyabhai
Registered: July 2009
Anders Olsson wrote:|
> Hello Nitin, and thank you for you reply.
> I'm sorry for my rather late response. I did not have time to work on
> this until recently.
> I've tried your suggestion and now my code looks as follows:
> IModelManager modelManager =
> org.eclipse.wst.sse.core.StructuredModelManager.getModelMana ger();
> IStructuredModel model = modelManager.getExistingModelForEdit(xmlFile);
> IStructuredDocument document = model.getStructuredDocument();
> FormatProcessorXML fp = new FormatProcessorXML();
> I have gotten this to work, but only under special conditions. It seems
> like I at least once have to have had the file opened in an editor. If I
> try to format it directly when the workbench is started, 'model' is
> null. After opening the editor it doesn't matter if I keep it open or
> not. From my tests it does not seem like the Action in "Source>Format"
> has this limitation. Is there some IStructuredModel defined, which the
> WST Action uses? In that case, can I find and use that one too?
You just need to use the same method without the "existing" part,
Eclipse WTP Source Editing
Eclipse WTP, IBM
Powered by FUDForum
. Page generated in 0.02104 seconds