how to the list of which elements can be wrapped a element

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

how to the list of which elements can be wrapped a element

Post by shikhar_472 »

Hi Team,

Is there any inbuild method or way to get the list of element which can wrapped on selection.

USE CASE - suppose i am selecting a node and i want to change that selected node with the possible wrap element i need the list of element which should allow on that position while replacing the tag with another one.
<disclaimer>
<para><paratext></paratext></para>
</disclaimer>

here i want to select the disclaimer and want to change the disclaimer with the possible allowed elements which should be wrapper outside of para i want that element of list
cosminef
Site Admin
Posts: 84
Joined: Wed Aug 30, 2023 2:33 pm

Re: how to the list of which elements can be wrapped a element

Post by cosminef »

Hello,
Try to use this code, and optionally add more logging if you encounter errors to investigate them:

Code: Select all

public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
      throws AuthorOperationException {
    AuthorElement nodeToRename = ...;
    AuthorSchemaManager schemaManager = authorAccess.getDocumentController().getAuthorSchemaManager();
    Map<QName, Collection<QName>> elementToParentsMap = schemaManager.getElementToParentsMap(nodeToRename);
    try {
      WhatElementsCanGoHereContext context = schemaManager.createWhatElementsCanGoHereContext(nodeToRename.getStartOffset());
      List<CIElement> allPossibleElementsWhichCanBeInsertedInsteadOfNodeToRename = schemaManager.getChildrenElements(context);
      //Now we need to filter all possible elements and leave only the ones which can contain the selected content.
      List<AuthorNode> childrenOfNodeToRename = nodeToRename.getContentNodes();
      if(childrenOfNodeToRename != null && ! childrenOfNodeToRename.isEmpty()) {
        for (AuthorNode childInsideSelection : childrenOfNodeToRename) {
          Collection<QName> possibleParentsForChild = elementToParentsMap.get(new QName(childInsideSelection.getName()));
          if(possibleParentsForChild != null) {
            Iterator<CIElement> iter = allPossibleElementsWhichCanBeInsertedInsteadOfNodeToRename.iterator();
            while(iter.hasNext()) {
              CIElement possibleReplacement = iter.next();
              if(! possibleParentsForChild.contains(new QName(possibleReplacement.getName()))) {
                iter.remove();
              }
            }
          }
        }
      }
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
Best Regards,
Cosmin
Cosmin Eftenie
www.oxygenxml.com
shikhar_472
Posts: 99
Joined: Fri Jul 01, 2022 12:08 pm

Re: how to the list of which elements can be wrapped a element

Post by shikhar_472 »

Hi Cosmin,

Thank you very much for the solution i have one more doubt if child element is not present in that scenarion i wanted the filtered list for sure I can get all PossibleElements when child is not present but what if some tags does now allow text in that list how to differentiate that
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: how to the list of which elements can be wrapped a element

Post by mihaela »

Hello,

Can you please give us a specific example to better understand what you are trying to obtain?

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply