Page 1 of 1

Implementing UniqueAttributesRecognizer for multiple attribute types

Posted: Wed Mar 09, 2016 8:16 pm
by hatchjk
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 ...

Re: Implementing UniqueAttributesRecognizer for multiple attribute types

Posted: Thu Mar 10, 2016 10:49 am
by Radu
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