Search in sources :

Example 1 with FacesComplexDefinition

use of com.ibm.xsp.registry.FacesComplexDefinition in project org.openntf.nsfodp by OpenNTF.

the class AbstractSchemaServlet method findDefinitionElement.

/**
 * Finds the XML element for the given definition in its original .xsp-config file.
 *
 * @param def the {@link FacesDefinition} to search for
 * @return an {@link Element} describing the definition, or {@code null} if it cannot be found
 */
private Element findDefinitionElement(FacesDefinition def) {
    String filePath = def.getFile().getFilePath();
    Document xspConfig = getXspConfig(filePath);
    if (xspConfig != null) {
        try {
            String elementName;
            if (def instanceof FacesComplexDefinition) {
                elementName = "complex-class";
            } else if (def instanceof FacesComponentDefinition) {
                elementName = "component-class";
            } else {
                return null;
            }
            Object[] elements = DOMUtil.nodes(xspConfig, "/faces-config/*/" + elementName + "[normalize-space(text())='" + def.getJavaClass().getName() + "']");
            return elements.length == 0 ? null : (Element) ((Element) elements[0]).getParentNode();
        } catch (XMLException e) {
            throw new RuntimeException(e);
        }
    }
    return null;
}
Also used : FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) XMLException(com.ibm.commons.xml.XMLException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) FacesComplexDefinition(com.ibm.xsp.registry.FacesComplexDefinition)

Example 2 with FacesComplexDefinition

use of com.ibm.xsp.registry.FacesComplexDefinition in project org.openntf.nsfodp by OpenNTF.

the class AbstractSchemaServlet method outAnnotations.

private void outAnnotations(FacesDefinition def, Element element) {
    Document doc = element.getOwnerDocument();
    Element annotation = doc.createElement("xs:annotation");
    if (element.getFirstChild() != null) {
        element.insertBefore(annotation, element.getFirstChild());
    } else {
        element.appendChild(annotation);
    }
    Element component = findDefinitionElement(def);
    {
        Element appinfo = DOMUtil.createElement(doc, annotation, "xs:appinfo");
        if (component != null) {
            appinfo.setTextContent(component.getElementsByTagName("display-name").item(0).getTextContent());
        } else {
            appinfo.setTextContent(def.getTagName());
        }
    }
    {
        Element documentation = DOMUtil.createElement(doc, annotation, "xs:documentation");
        documentation.setAttribute("source", "version");
        String since = def.getSince();
        if (StringUtil.isEmpty(since)) {
            since = "8.5.0";
        }
        documentation.setTextContent(since + "+");
    }
    {
        // This appears to be treated as HTML
        Element documentation = DOMUtil.createElement(doc, annotation, "xs:documentation");
        documentation.setAttribute("source", "description");
        StringBuilder description = new StringBuilder();
        if (component != null) {
            p(description, component.getElementsByTagName("description").item(0).getTextContent());
        }
        if (def instanceof FacesComponentDefinition) {
            FacesComponentDefinition fcd = (FacesComponentDefinition) def;
            Collection<String> facets = fcd.getFacetNames();
            if (facets != null && !facets.isEmpty()) {
                p(description, "Facets:");
                description.append("<ul>");
                facets.stream().map(f -> "<li>" + f + "</li>").forEach(description::append);
                description.append("</ul>");
            }
            dt(description, "Component Type", fcd.getComponentType());
            dt(description, "Component Family", fcd.getComponentFamily());
            dt(description, "Renderer Type", fcd.getRendererType());
        } else if (def instanceof FacesComplexDefinition) {
            dt(description, "Complex ID", ((FacesComplexDefinition) def).getComplexId());
            if (def instanceof FacesValidatorDefinition) {
                dt(description, "Validator ID", ((FacesValidatorDefinition) def).getValidatorId());
            }
        }
        if (component != null) {
            try {
                Object[] catNodes = DOMUtil.nodes(component, "*/designer-extension/category/text()");
                if (catNodes.length > 0) {
                    dt(description, "Group", ((Node) catNodes[0]).getTextContent());
                }
            } catch (XMLException e) {
                throw new RuntimeException(e);
            }
        }
        dt(description, "Class", def.getJavaClass().getName());
        documentation.setTextContent(description.toString());
    }
}
Also used : FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) XMLException(com.ibm.commons.xml.XMLException) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ComplexContainerTreeNode(com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode) Collection(java.util.Collection) Document(org.w3c.dom.Document) FacesComplexDefinition(com.ibm.xsp.registry.FacesComplexDefinition) FacesValidatorDefinition(com.ibm.xsp.registry.FacesValidatorDefinition)

Aggregations

XMLException (com.ibm.commons.xml.XMLException)2 FacesComplexDefinition (com.ibm.xsp.registry.FacesComplexDefinition)2 FacesComponentDefinition (com.ibm.xsp.registry.FacesComponentDefinition)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 ComplexContainerTreeNode (com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode)1 FacesValidatorDefinition (com.ibm.xsp.registry.FacesValidatorDefinition)1 Collection (java.util.Collection)1 Node (org.w3c.dom.Node)1