Oxygen Eclipse plugin - get the whole content function
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 4
- Joined: Mon Dec 14, 2009 8:37 pm
Oxygen Eclipse plugin - get the whole content function
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.
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.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Oxygen Eclipse plugin - get the whole content function
Dear Vanchev,
The operation could get implemented like:
Regards,
Radu
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();
}
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service