List of attributes for a node

maxim.kovalev
Posts: 35

List of attributes for a node

Tue Nov 22, 2011 12:42 pm

How can I get a list of attributes for a node?
I found this way. Get a node on the spot where the cursor is positioned. The following is a AuthorNode AuthorElement. And call the AuthorElement.getAttributeAtIndex(i);
However, this method returns only attributes that are installed. And how can you get a complete list of attributes that are possible for this node (as in panel attributes).
mihaela
Posts: 188

Re: List of attributes for a node

Tue Nov 22, 2011 3:41 pm

Hi Maxim,

To find all the possible attributes for a node you have to get the WhatAttributesCanGoHereContext from the document schema manager and then ask the schema manager what attributes are available in this context.
The following code sample list the names of all attributes available for the element at caret position:

Code: Select all

  int caretOffset = authorAcess.getEditorAccess().getCaretOffset();
 
  AuthorDocumentController controller = authorAcess.getDocumentController();
  // Get the node at caret position
  AuthorNode node = controller.getNodeAtOffset(caretOffset);
 
  if (node instanceof AuthorElement) {
    AuthorSchemaManager authorSchemaManager = controller.getAuthorSchemaManager();
    // From schema manager get the current context
    WhatAttributesCanGoHereContext context = authorSchemaManager.createWhatAttributesCanGoHereContext((AuthorElement) node);
    // Find the list of all possible attributes for the current context
    List<CIAttribute> possibleAttrs = authorSchemaManager.whatAttributesCanGoHere(context);
    if (possibleAttrs != null) {
      for (CIAttribute ciAttribute : possibleAttrs) {
        System.out.println("Attr: " + ciAttribute.getName());
      }
    }
  }


Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
maxim.kovalev
Posts: 35

Re: List of attributes for a node

Tue Nov 22, 2011 4:43 pm

mihaela wrote:Hi Maxim,

To find all the possible attributes for a node you have to get the WhatAttributesCanGoHereContext from the document schema manager and then ask the schema manager what attributes are available in this context.
The following code sample list the names of all attributes available for the element at caret position:

Code: Select all

  int caretOffset = authorAcess.getEditorAccess().getCaretOffset();
 
  AuthorDocumentController controller = authorAcess.getDocumentController();
  // Get the node at caret position
  AuthorNode node = controller.getNodeAtOffset(caretOffset);
 
  if (node instanceof AuthorElement) {
    AuthorSchemaManager authorSchemaManager = controller.getAuthorSchemaManager();
    // From schema manager get the current context
    WhatAttributesCanGoHereContext context = authorSchemaManager.createWhatAttributesCanGoHereContext((AuthorElement) node);
    // Find the list of all possible attributes for the current context
    List<CIAttribute> possibleAttrs = authorSchemaManager.whatAttributesCanGoHere(context);
    if (possibleAttrs != null) {
      for (CIAttribute ciAttribute : possibleAttrs) {
        System.out.println("Attr: " + ciAttribute.getName());
      }
    }
  }


Regards,
Mihaela


Cool, thanks

Return to “DITA (Editing and Publishing DITA Content)”

Who is online

Users browsing this forum: No registered users and 0 guests