Implementing UniqueAttributesRecognizer for multiple attribute types

Post here questions and problems related to oXygen frameworks/document types.
hatchjk
Posts: 10

Implementing UniqueAttributesRecognizer for multiple attribute types

Wed Mar 09, 2016 8:16 pm

Our implementation of (x)html5 requires some governance over what attributes' values are allowed to be copied on split, and on paste. In particular, we have two attributes, id and data-aid, that need to be recognized as "unique" so their values aren't replicated, causing validation errors. Extending the DefaultAttributesRecognizer class seems to only allow a single attribute type to be passed to the constructor. Any suggestions? Has anyone solved this issue for their own implementations?

By the way, this may be easily solved for those more fluent in Java than me. I'm working on it ... thanks for your patience ...
Radu
Posts: 5386

Re: Implementing UniqueAttributesRecognizer for multiple attribute types

Thu Mar 10, 2016 10:49 am

Hi,

How about if you create your own implementation of the UniqueAttributesRecognizer interface which delegates to two default recognizers?
Something like:

Code: Select all

public class UniqueAttrsRecognizerWrapper implements UniqueAttributesRecognizer, ClipboardFragmentProcessor {
  private DefaultUniqueAttributesRecognizer rec1;
  private DefaultUniqueAttributesRecognizer rec2;
  public UniqueAttrsRecognizerWrapper() {
    rec1 = new DefaultUniqueAttributesRecognizer("id");
    rec2 = new DefaultUniqueAttributesRecognizer("data-aid");
  }
  @Override
  public void activated(AuthorAccess authorAccess) {
    rec1.activated(authorAccess);
    rec2.activated(authorAccess);
  }
  @Override
  public void deactivated(AuthorAccess authorAccess) {
    rec1.deactivated(authorAccess);
    rec2.deactivated(authorAccess);
  }
  @Override
  public String getDescription() {
    return "Recognizer";
  }
  /**
   * @see ro.sync.ecss.extensions.api.UniqueAttributesProcessor#copyAttributeOnSplit(java.lang.String, ro.sync.ecss.extensions.api.node.AuthorElement)
   */
  @Override
  public boolean copyAttributeOnSplit(String attrQName, AuthorElement element) {
    return rec1.copyAttributeOnSplit(attrQName, element) && rec2.copyAttributeOnSplit(attrQName, element);
  }
  @Override
  public void assignUniqueIDs(int startOffset, int endOffset, boolean forceGeneration) {
    //Probably not interesting, you do not want to generate unique IDs.
  }
  @Override
  public boolean isAutoIDGenerationActive() {
    return false;
  }
  @Override
  public void process(ClipboardFragmentInformation fragmentInformation) {
    rec1.process(fragmentInformation);
    rec2.process(fragmentInformation);
  }
}


Or as an alternative based on the Java code of the default unique attributes recognizer which you should find in the SDK you can create your own unique attributes recognizer changing the original code in certain places.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 1 guest