Page 1 of 1

Get the Content of a ELementNode

Posted: Wed Jun 04, 2008 8:48 am
by rparree
I understand from the JavaDoc that Content represent the text nodes of an element represented by AuthorElement. How do you get to this Content i have been searching in the provided source code but con't find anything.

In fact the implementation class ro.sync.ecss.A.B shows no state containing a Content instance. So there must be some other way...?

Tx.,

Re: Get the Content of a ELementNode

Posted: Wed Jun 04, 2008 11:52 am
by sorin_ristache
Hello,

To get the text content of an element you have to use a code fragment like the following:

Code: Select all

try {
AuthorDocumentController documentController = authorAccess.getDocumentController();
AuthorDocumentFragment documentFragment = documentController.createDocumentFragment(element, true);
Content content = documentFragment.getContent();
String string = content.getString(0, content.getLength());
string = string.replaceAll("\0", "");
} catch (BadLocationException e) {
// Exception handling here

}
In a future version we will make the text content available in a simple way.


Regards,
Sorin

Re: Get the Content of a ELementNode

Posted: Wed Jun 04, 2008 12:18 pm
by rparree
Thanks Sorin! If i understand correcly the AuthorDocumentFragment is an editable representation of a document fragment. Makes perfect sense...

Re: Get the Content of a ELementNode

Posted: Wed Jun 04, 2008 12:46 pm
by sorin_ristache
It is a fragment of the tree of the current Author document. You can edit this fragment in your Author extension component but this does not modify the Author document that you see in the Author editor panel. The fragment is only a copy of some nodes from the Author document tree.


Regards,
Sorin

Re: Get the Content of a ELementNode

Posted: Wed Jun 04, 2008 1:42 pm
by rparree
Sorin,

I am looking for a way of providing dialogs to edit some complex types. How can you in an easy way update the content?


Code: Select all

 AuthorDocumentFragment authorDocumentFragment = authorAccess.getDocumentController().createDocumentFragment(abbrElement, false);
Content content = authorDocumentFragment.getContent();
String abbreviation = content.getString(0, content.getLength());
AttrValue whole = abbrElement.getAttribute("whole");
String wholeValue = whole!=null ? whole.getValue() : null;
AttrValue footnote = abbrElement.getAttribute("whole");
boolean footnoteValue = footnote!=null ? Boolean.valueOf(footnote.getValue()) : true;
AbbreviationDialog dialog = AbbreviationDialog.prompt(abbreviation, wholeValue, footnoteValue);
if (dialog.isOk()){
// update the element
}
(this is editing an XML element like

Code: Select all

<abbreviation whole="Abcfef" footnote="true">ABC</abbreviation>

Re: Get the Content of a ELementNode

Posted: Wed Jun 04, 2008 2:26 pm
by sorin_ristache
You update the content of the current document edited in the Author mode with the methods delete, createDocumentFragment and insertFragment of the AuthorDocumentController object that you get with a call authorAccess.getDocumentController() where authorAccess is a parameter received by your Author extension.


Regards,
Sorin