Skip to content

Commit

Permalink
A sample operation that builds an element fragment based on the schem…
Browse files Browse the repository at this point in the history
…a model and inserts it in the document.
  • Loading branch information
AlexJitianu committed Sep 25, 2018
1 parent 7809fe4 commit 70509eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions insert-schema-element-fragment/Readme.txt
@@ -0,0 +1 @@
This sample Javascript code creates a fragment for an element based on the schema model.
31 changes: 31 additions & 0 deletions insert-schema-element-fragment/insert-schema-element-fragment.js
@@ -0,0 +1,31 @@
function doOperation() {
insert("step");
}

function insert(elementName) {
var authorSchemaManager = authorAccess.getDocumentController().getAuthorSchemaManager();

var searchedElementCI = null;
var allPossibleElements = authorSchemaManager.getAllPossibleElements();
for (var i = 0; i < allPossibleElements.size();
i++) {
var ciElement = allPossibleElements. get (i);
if (ciElement.getQName().equals(elementName)) {
searchedElementCI = ciElement;
break;
}
}

try {
if (searchedElementCI != null) {
var createAuthorDocumentFragment = authorSchemaManager.createAuthorDocumentFragment(searchedElementCI);
authorAccess.getDocumentController().insertFragment(authorAccess.getCaretOffset(), createAuthorDocumentFragment);
} else {
Packages.java.lang.System.out.println("not found");
}
}
catch (e) {
// Bad location
e.printStackTrace();
}
}

0 comments on commit 70509eb

Please sign in to comment.