Search in sources :

Example 6 with XMLException

use of com.ibm.commons.xml.XMLException in project org.openntf.nsfodp by OpenNTF.

the class AbstractSchemaServlet method outComponentDefinition.

private void outComponentDefinition(FacesDefinition def, Element schema, SharableRegistryImpl registry, boolean noTag) {
    Document doc = schema.getOwnerDocument();
    String name = toElementName(def, noTag);
    // Check if one already exists, as shows up with com.ibm.xsp.extlib.component.dojo.UIDojoWidgetBase
    try {
        if (DOMUtil.nodes(schema, "*[@name=\"" + name + "\"]").length > 0) {
            return;
        }
    } catch (XMLException e) {
        throw new RuntimeException(e);
    }
    Element complexType = DOMUtil.createElement(doc, schema, "xs:complexType");
    complexType.setAttribute("name", name);
    // UIComponents can have any children, while bindings and resources are special cases with similar needs
    if (UIComponent.class.isAssignableFrom(def.getJavaClass()) || MethodBinding.class.equals(def.getJavaClass()) || ValueBinding.class.equals(def.getJavaClass())) {
        complexType.setAttribute("mixed", "true");
    }
    Element all = DOMUtil.createElement(doc, complexType, "xs:choice");
    all.setAttribute("minOccurs", "0");
    all.setAttribute("maxOccurs", "unbounded");
    outProperties(def, complexType, registry);
    if (UIComponent.class.isAssignableFrom(def.getJavaClass())) {
        // Declare that it allows any children
        DOMUtil.createElement(doc, all, "xs:any").setAttribute("processContents", "lax");
    }
    outAnnotations(def, complexType);
    if (!noTag) {
        // Output the concrete definition
        Element element = DOMUtil.createElement(doc, schema, "xs:element");
        element.setAttribute("name", def.getTagName());
        String prefix = extMap.get(def.getNamespaceUri()) + ':';
        element.setAttribute("type", prefix + def.getTagName());
        outAnnotations(def, element);
    }
}
Also used : XMLException(com.ibm.commons.xml.XMLException) Element(org.w3c.dom.Element) ValueBinding(javax.faces.el.ValueBinding) Document(org.w3c.dom.Document)

Example 7 with XMLException

use of com.ibm.commons.xml.XMLException 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)7 Document (org.w3c.dom.Document)7 Element (org.w3c.dom.Element)7 ComplexContainerTreeNode (com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode)4 FacesComplexDefinition (com.ibm.xsp.registry.FacesComplexDefinition)4 FacesComponentDefinition (com.ibm.xsp.registry.FacesComponentDefinition)4 FacesContainerProperty (com.ibm.xsp.registry.FacesContainerProperty)3 FacesValidatorDefinition (com.ibm.xsp.registry.FacesValidatorDefinition)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Collection (java.util.Collection)3 Properties (java.util.Properties)3 ValueBinding (javax.faces.el.ValueBinding)3 ExtensionManager (com.ibm.commons.extension.ExtensionManager)2 PathUtil (com.ibm.commons.util.PathUtil)2 StringUtil (com.ibm.commons.util.StringUtil)2 DOMUtil (com.ibm.commons.xml.DOMUtil)2 Format (com.ibm.commons.xml.Format)2 ActionGroup (com.ibm.xsp.actions.ActionGroup)2 LibraryServiceLoader (com.ibm.xsp.library.LibraryServiceLoader)2