Get the Content of a ELementNode

Are you missing a feature? Request its implementation here.
rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Get the Content of a ELementNode

Post 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.,
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Get the Content of a ELementNode

Post 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
rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Get the Content of a ELementNode

Post by rparree »

Thanks Sorin! If i understand correcly the AuthorDocumentFragment is an editable representation of a document fragment. Makes perfect sense...
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Get the Content of a ELementNode

Post 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
rparree
Posts: 53
Joined: Tue Aug 23, 2005 12:00 pm

Re: Get the Content of a ELementNode

Post 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>
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Get the Content of a ELementNode

Post 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
Post Reply