Edit online

ID Element Locator

The IDElementLocator is an implementation of the abstract class ro.sync.ecss.extensions.api.link.ElementLocator for links that use an ID.

The constructor only assigns field values and the method endElement is empty for this implementation.

The method startElement checks each of the element's attribute values and when one matches the link, it considers the element found if one of the following conditions is satisfied:

  • The qualified name of the attribute is xml:id.
  • The attribute type is ID.

The attribute type is checked with the help of the method IDTypeVerifier.hasIDType.

public boolean startElement(String uri, String localName, 
        String name, Attr[] atts) {
  boolean elementFound = false;
  for (int i = 0; i < atts.length; i++) {
    if (link.equals(atts[i].getValue())) {
      if("xml:id".equals(atts[i].getQName())) {
        // xml:id attribute
        elementFound = true;          
      } else {
        // check if attribute has ID type
        String attrLocalName = 
          ExtensionUtil.getLocalName(atts[i].getQName());
        String attrUri = atts[i].getNamespace();
        if (idVerifier.hasIDType(localName, uri, attrLocalName, attrUri)) {
          elementFound = true;
        }
      }
    }
  }
  
  return elementFound;
}