Issue with custom ElementLocator

Having trouble installing Oxygen? Got a bug to report? Post it all here.
lhopkins
Posts: 4
Joined: Thu Nov 16, 2023 10:28 pm

Issue with custom ElementLocator

Post by lhopkins »

Hello,

Our xml documents use an xs:String for the ID instead of an xs:ID, where when we create a cross reference at a location, we generate that string (for the element we want to link to) and give that ID as an attribute to our cross-reference element.

I have not been able to get a custom Element Locator working such that it jumps to the linked location in the document. As a way around that, when I load the document (and when IDs are generated), I build a Map of all the nodes with an ID attribute where the ID is the key. The ElementLocatorProvider checks the selected link string with the IDs in the Map to find the node to jump and then moves the caret there.

The issue is that returning an ElementLocator seems to call an internal method that does one of two things: 1) if I return null instead of the ElementLocator, I jump to the position correctly, but I get a Bad Reference ID in the results window...OR 2) I return the elementLocator which does find the link, but stays at the top of the document.

Does anyone have a suggestion to solve this problem? I would get away from the ElementLocator altogether, but I haven't found another way to have Oxygen recognize a specific tag as a link with which I could jump locations.
Radu
Posts: 9116
Joined: Fri Jul 09, 2004 5:18 pm

Re: Issue with custom ElementLocator

Post by Radu »

Hi,

So you have a custom XML document, with your own CSS used for visual editing.
I assume you have set the oxy-link property in your CSS:

https://www.oxygenxml.com/doc/ug-editor ... ments.html

something like:

Code: Select all

sourceElementName:before{
    content: "CLICK ME";
    -oxy-link: "#" attr(targetAttrName);
}
And if that targetAttrName would be defined in your schema as having xs:ID type, things would work out of the box. But it is not.
So once you click that link in the Author visual editing mode, by default Oxygen calls a class named ro.sync.ecss.extensions.commons.DefaultElementLocatorProvider which creates a ro.sync.ecss.extensions.commons.IDElementLocator, you can find the source code for both classes here:

https://www.oxygenxml.com/maven/com/oxy ... ources.jar

But our default IDElementLocator (and you can look at its code) will recognize only xml:id's and attributes defined as IDs in the schemas.
So you implemented your own ro.sync.ecss.extensions.api.ExtensionsBundle.createElementLocatorProvider() which means your code should now be called instead. Maybe the implementations of our default locator provider that are in the jar linked above will help you further.

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