private String getExternalLinkTOCNodeURLOrNull()

in freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/Transform.java [2062:2104]


    private String getExternalLinkTOCNodeURLOrNull(Element elem) {
        if (elem.getParentNode() instanceof Document) {
            // The document element is never an external link ToC node.
            return null;
        }

        Element title = getTitle(elem);
        if (title == null) {
            // An element without title can't be an external link ToC node
            return null;
        }

        Iterator<Element> it = XMLUtil.childrenElementsOf(title).iterator();
        if (it.hasNext()) {
            Element firstChild = it.next();
            if (!it.hasNext()) { // It's the only child
                String firstChildName = firstChild.getLocalName();
                if (firstChildName.equals(E_LINK)) {
                    String href = XMLUtil.getAttributeNS(firstChild, XMLNS_XLINK, A_XLINK_HREF);
                    if (href == null) {
                        throw new DocgenException(XMLUtil.theSomethingElement(firstChild, true)
                                + " inside a title has no xlink:" + A_XLINK_HREF + " attribute, thus it can't be "
                                + "used as ToC link.");
                    }
                    return href;
                } else if (firstChildName.equals(E_OLINK)) {
                    String targetdoc = XMLUtil.getAttributeNS(firstChild, null, A_TARGETDOC);
                    if (targetdoc == null) {
                        throw new DocgenException(XMLUtil.theSomethingElement(firstChild, true)
                                + " has no xlink:" + A_TARGETDOC + " attribute");
                    }
                    String url = olinks.get(targetdoc);
                    if (url == null) {
                        throw new DocgenException(XMLUtil.theSomethingElement(firstChild, true)
                                + " refers to undefined olink name " + StringUtil.jQuote(targetdoc)
                                + "; check configuration.");
                    }
                    return url;
                }
            }
        }
        return null;
    }