Could not determine conref targets

<oXygen/> general issues.
Posts: 1
Joined: Thu Oct 24, 2019 2:43 pm

Could not determine conref targets

Post by boopathyks » Thu Oct 24, 2019 2:51 pm

I have created the new XRef menu in the Oxygen Web Author by using the below code on the web/framework.js

Code: Select all

var insertXrefActionId =
    sync.docbook.DocbookExtension.prototype.version == 5 ? "insert.cross.reference.xref" : "";

var originalInsertXrefAction = actionsManager.getActionById(insertXrefActionId);
if (originalInsertXrefAction) {
    var xrefOperationClass = sync.docbook.DocbookExtension.prototype.version == 5 ?
        "" :
    var insertXrefAction = new sync.actions.InsertXref(
    actionsManager.registerAction(insertXrefActionId, insertXrefAction);
The Menu is working well, But when I select the Xml file for cross Reference. I'm getting the below error

Could not determine conref targets


TypeError: Cannot read property 'focus' of null
at sync.actions.InsertXref.sync.actions.InsertReference.focusElemChooser

Kindly help me to find the solution.

Posts: 264
Joined: Thu Sep 04, 2014 4:22 pm

Re: Could not determine conref targets

Post by cristi_talau » Fri Oct 25, 2019 3:39 pm


The "sync.actions.InsertXref" action was designed to work for DITA documents. I registered an issue to make add similar functionality for DocBook and I will update this thread when it will be available in a released version of Web Author.

Let us know if you want to test beta version of the DocBook framework that includes this functionality, please write us an email on .

Meanwhile, you can implement your own action in your DocBook framework extension. To do this you need to:

1. Create a custom action that prompts the user to choose the destination file and the ID of the target element. The code for this action needs to be added in the "web" folder of you framework in a new JS file. You can find below a minimal working example:

Code: Select all

var DocBookCrossRefXrefAction = function (editor) {;
  this.editor = editor;
  this.xrefTargetsDialog = null;
DocBookCrossRefXrefAction.prototype = Object.create(sync.actions.AbstractAction.prototype);
DocBookCrossRefXrefAction.prototype.constructor = DocBookCrossRefXrefAction;

DocBookCrossRefXrefAction.prototype.getDisplayName = function () {
  return 'Insert cross reference (xref)';

DocBookCrossRefXrefAction.prototype.actionPerformed = function (callback) {
  // This callback might have to be called at a later point, so save it until then.
  this.callback = callback || function () {};

  var chooser = workspace.getUrlChooser();
  var context = new sync.api.UrlChooser.Context(sync.api.UrlChooser.Type.EXTERNAL_REF);
  chooser.chooseUrl(context, this.showXrefTargetChooser.bind(this), sync.api.UrlChooser.Purpose.CHOOSE);

DocBookCrossRefXrefAction.prototype.showXrefTargetChooser = function (url) {
  if (url) {
    // Create a dialog to display all targets, so the user can select one to insert cross reference.
    this.xrefTargetsDialog = this.createXrefTargetsDialog();

    this.xrefTargetsDialog.onSelect(function (key, e) {
      if (key === 'ok') {
      } else {
  } else {

DocBookCrossRefXrefAction.prototype.createXrefTargetsDialog = function () {
  var dialog = workspace.createDialog();
  dialog.setTitle('Choose cross reference');
  dialog.setPreferredSize(700, 500);
  return dialog;

DocBookCrossRefXrefAction.prototype.populateXrefTargetsDialog = function (url) {
    .invokeOperation('ro.sync.servlet.operation.FindXrefTargetsOperation', {url: url})
    .then(function(str) { return JSON.parse(str);})

DocBookCrossRefXrefAction.prototype.xrefTargetsReceived = function (targets) {
  var container = this.xrefTargetsDialog.getElement();
  if (!targets || !targets.length) {
    container.textContent = 'No cross reference targets found in the chosen file';
  } else {
    for (var i = 0; i < targets.length; i++) {
      var radio = document.createElement('input'); = 'docbook-ref-table-radio';
      radio.type = 'radio'; = targets[i].id;

      var label = document.createElement('label'); = 'display: block';
      label.appendChild(document.createTextNode(targets[i].nodeName + ' (#' + targets[i].id  + ') - ' + targets[i].content.substring(0, 50)));


DocBookCrossRefXrefAction.prototype.xrefTargetChosen = function() {
  var targetRadio = this.xrefTargetsDialog.getElement().querySelector('input[name="docbook-ref-table-radio"]:checked');
  if (targetRadio) {
      {fragment: '<xref linkend="' + + '"/>'})

DocBookCrossRefXrefAction.prototype.xrefInserted = function () {
  this.xrefTargetsDialog && this.xrefTargetsDialog.dispose();

DocBookCrossRefXrefAction.prototype.dispose = function() {
  this.xrefTargetsDialog && this.xrefTargetsDialog.dispose();
};, sync.api.Workspace.EventType.EDITOR_LOADED, function(e) {
  var editor = e.editor;, sync.api.Editor.EventTypes.ACTIONS_LOADED, function(e) {
    editor.getActionsManager().registerAction('insert.cross.reference.xref', new DocBookCrossRefXrefAction(editor));
2. This action uses a server-side AuthorOperationWithResult to collect xref targets from the chosen file. You can find below the code of this Java operation:

Code: Select all

package ro.sync.servlet.operation;

import java.util.ArrayList;

import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

import ro.sync.basic.util.URLUtil;
import ro.sync.ecss.extensions.api.ArgumentsMap;
import ro.sync.ecss.extensions.api.AuthorOperationException;
import ro.sync.ecss.extensions.api.webapp.AuthorDocumentModel;
import ro.sync.ecss.extensions.api.webapp.AuthorOperationWithResult;
import ro.sync.ecss.extensions.api.webapp.WebappRestSafe;
import ro.sync.xml.parser.ParserCreator;

public class FindXrefTargetsOperation extends AuthorOperationWithResult {

  public String doOperation(AuthorDocumentModel model, ArgumentsMap args) throws AuthorOperationException {
    String urlString = (String) args.getArgumentValue("url");
    try {
      URL url = URLUtil.addAuthenticationInfo(model.getAuthorAccess().getEditorAccess().getEditorLocation(), new URL(urlString));
      InputSource is = new InputSource(url.toString());
      DocumentBuilder docBuilder = ParserCreator.newSchemaAwareDocumentBuilder();
      Document document = docBuilder.parse(is);
      ArrayList<XrefTarget> xrefTargets = new ArrayList<>();
      gatherXrefTargets(document, xrefTargets);
      return new ObjectMapper().writeValueAsString(xrefTargets);
    } catch (Exception e) {
      throw new AuthorOperationException(e.getMessage(), e);
  public static class XrefTarget {
    public final String id;
    public final String nodeName;
    public final String content;
    public XrefTarget(Element elem) { = getIDValue(elem);
      this.nodeName = elem.getTagName();
      this.content = elem.getTextContent();

  private static void gatherXrefTargets(Node node, ArrayList<XrefTarget> xrefTargets) {
    if (node.getNodeType() == Node.ELEMENT_NODE) {
      Element elem = (Element) node;
      if (getIDValue(elem) != null) {
        xrefTargets.add(new XrefTarget(elem));
    NodeList childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) { 
      gatherXrefTargets(childNodes.item(i), xrefTargets);
  public static String getIDValue(Element elem) {
    NamedNodeMap attributes = elem.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
      Attr attribute = (Attr)attributes.item(i);
      // There are some ID attributes defined as such in the schema file.
      if (attribute.isId() || "xml:id".equals(attribute.getName()) || "id".equals(attribute.getName())) {
        return attribute.getValue();
    return null;
You need to compile this Java class and add it as a JAR file in the classpath of your framework. More details here: ... h-tab.html .


Posts: 1
Joined: Thu Mar 19, 2020 2:29 pm

Re: Could not determine conref targets

Post by mixa999999 » Thu Mar 19, 2020 4:49 pm

cristi_talau wrote:
Fri Oct 25, 2019 3:39 pm
You need to compile this Java class and add it as a JAR file in the classpath of your framework.
is there any way to make this work in author standalone, not on the web?

Posts: 264
Joined: Thu Sep 04, 2014 4:22 pm

Re: Could not determine conref targets

Post by cristi_talau » Fri Mar 20, 2020 12:53 pm


This thread is about adding actions to insert cross references to the Docbook framework in Web Author. Currently, these actions are supported out-of-the-box in both Web Author and standalone Author.

In this context, it would be helpful to give us more details about what you are trying to achieve.

To implement an "Insert Reference" action for some other XML vocabulary, you may find these tutorials useful: Best regards,

Post Reply