Page 1 of 1

Oxygen Eclipse plugin - get the whole content function

Posted: Mon Dec 14, 2009 9:08 pm
by vanchev
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.

Re: Oxygen Eclipse plugin - get the whole content function

Posted: Tue Dec 15, 2009 4:03 pm
by Radu
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

Re: Oxygen Eclipse plugin - get the whole content function

Posted: Tue Dec 15, 2009 6:36 pm
by vanchev
Dear Radu,
thank you so much for you fast an thorough reply of my question.

Best Regards,
Vanchev