Oxygen Eclipse plugin - get the whole content function

Questions about XML that are not covered by the other forums should go here.
vanchev
Posts: 4
Joined: Mon Dec 14, 2009 8:37 pm

Oxygen Eclipse plugin - get the whole content function

Post by vanchev » Mon Dec 14, 2009 9:08 pm

Hello,
I am using <oXygen/> 10.3 as an Eclipse plugin. My question is whether it is possible to write an action for <oXygen/> Editor/Author that will get the whole text of the .xml file and replace it with an editted version of it. One possible use case of this would be to automatically place a tag everywhere, where the word "someExampleWordHere" appears. If it is possible, which function returns the whole content of the currently editted file?

Best Regards,
Vanchev

P.S. I am sorry if this question was already posted.

Radu
Posts: 7028
Joined: Fri Jul 09, 2004 5:18 pm

Re: Oxygen Eclipse plugin - get the whole content function

Post by Radu » Tue Dec 15, 2009 4:03 pm

Dear Vanchev,

The operation could get implemented like:

Code: Select all

  /**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
try {
//Get a reader over the content in the editor
Reader contentReader = authorAccess.getEditorAccess().createContentReader();
//Read the whole content in a string builder
StringBuilder content = new StringBuilder();
char[] buf = new char[1024];
int len = -1;
while((len = contentReader.read(buf)) != -1) {
content.append(buf, 0, len);
}

//Replace "someExampleWordHere" with <someTag>someExampleWordHere</someTag>
String replacedContent = content.toString().replaceAll("someExampleWordHere", "<someTag>someExampleWordHere</someTag>");

//And set the whole content back
authorAccess.getEditorAccess().reloadContent(new StringReader(replacedContent));
} catch (IOException e) {
e.printStackTrace();
}
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

vanchev
Posts: 4
Joined: Mon Dec 14, 2009 8:37 pm

Re: Oxygen Eclipse plugin - get the whole content function

Post by vanchev » Tue Dec 15, 2009 6:36 pm

Dear Radu,
thank you so much for you fast an thorough reply of my question.

Best Regards,
Vanchev

Post Reply