Determine if opened file was just created from a custom template
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 110
- Joined: Fri May 14, 2010 12:14 am
Determine if opened file was just created from a custom template
We'd like to know if the current editor document in Author mode was just created from one of our custom DITA templates and hasn't been touched by anyone so we can apply some custom logic to generate some initial content based on a live lookup that cannot be accomplished with a custom editor variable.
One thought is to include a processing instruction in the template topic that we can detect through when a DITA topic is opened by Oxygen's New action, insert our generated content, and then remove the processing instruction so that it's no longer applied when the file is next opened.
Is there a better way to determine if a file that was just opened was created from one of our templates?
I noticed that the XML Refactoring operation for deleting processing instructions will only remove it if it's within the topic's root element and not before. Is this a restriction throughout the SDK, or is there a method that could detect and delete a specific processing instruction before the root topic declaration?
One thought is to include a processing instruction in the template topic that we can detect through when a DITA topic is opened by Oxygen's New action, insert our generated content, and then remove the processing instruction so that it's no longer applied when the file is next opened.
Is there a better way to determine if a file that was just opened was created from one of our templates?
I noticed that the XML Refactoring operation for deleting processing instructions will only remove it if it's within the topic's root element and not before. Is this a restriction throughout the SDK, or is there a method that could detect and delete a specific processing instruction before the root topic declaration?
-
- Site Admin
- Posts: 125
- Joined: Wed Dec 12, 2018 5:33 pm
Re: Determine if opened file was just created from a custom template
Post by Cosmin Duna »
Hi John,
I think using a processing instruction for marking your template is a good idea.
We have an example in one of our add-on when it listens when an editor is opened and checks if it's a new document. See line
52 from here https://github.com/oxygenxml/oxygen-dit ... nsion.java. It was also needed to check the creation time of the files for the cases when the new document was created from the contextual menu of Project or DITA Maps Manager view.
After, you can execute an XPath for finding the PI node from the custom DITA template. Then, use the "deleteNode" method for removing the marker. Something like this:
Best regards,
Cosmin
I think using a processing instruction for marking your template is a good idea.
We have an example in one of our add-on when it listens when an editor is opened and checks if it's a new document. See line
52 from here https://github.com/oxygenxml/oxygen-dit ... nsion.java. It was also needed to check the creation time of the files for the cases when the new document was created from the contextual menu of Project or DITA Maps Manager view.
After, you can execute an XPath for finding the PI node from the custom DITA template. Then, use the "deleteNode" method for removing the marker. Something like this:
Code: Select all
final WSEditor editor = workspace.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
WSEditorPage page = editor.getCurrentPage();
if (page instanceof WSAuthorEditorPage) {
AuthorDocumentController documentController = ((WSAuthorEditorPage) page).getDocumentController();
String piXPath = "/processing-instruction('xml-stylesheet')";
AuthorNode[] piNodes = documentController.findNodesByXPath(piXPath, false, false, false);
documentController.deleteNode(node[0]);
}
Cosmin
Cosmin Duna
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
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