Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A sample operation that builds an element fragment based on the schem…
…a model and inserts it in the document.
- Loading branch information
1 parent
7809fe4
commit 70509eb
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This sample Javascript code creates a fragment for an element based on the schema model. |
31 changes: 31 additions & 0 deletions
31
insert-schema-element-fragment/insert-schema-element-fragment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |