Search in sources :

Example 1 with FacesComponentDefinition

use of com.ibm.xsp.registry.FacesComponentDefinition 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 FacesComponentDefinition

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

the class StockComponentsServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setBufferSize(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    resp.setHeader("Content-Type", "text/json");
    ServletOutputStream os = resp.getOutputStream();
    try {
        if (componentInfo == null) {
            SharableRegistryImpl facesRegistry = new SharableRegistryImpl(getClass().getPackage().getName());
            // $NON-NLS-1$
            List<Object> libraries = ExtensionManager.findServices((List<Object>) null, LibraryServiceLoader.class, "com.ibm.xsp.Library");
            libraries.stream().filter(lib -> lib instanceof XspLibrary).map(XspLibrary.class::cast).map(lib -> new LibraryWrapper(lib.getLibraryId(), lib)).map(wrapper -> {
                SimpleRegistryProvider provider = new SimpleRegistryProvider();
                provider.init(wrapper);
                return provider;
            }).map(XspRegistryProvider::getRegistry).forEach(facesRegistry::addDepend);
            facesRegistry.refreshReferences();
            componentInfo = new JsonJavaObject();
            JsonArray defs = new JsonJavaArray();
            facesRegistry.findComponentDefs().stream().filter(FacesComponentDefinition::isTag).map(def -> {
                try {
                    JsonObject defObj = new JsonJavaObject();
                    // $NON-NLS-1$
                    defObj.putJsonProperty("namespaceUri", def.getNamespaceUri());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("tagName", def.getTagName());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("class", def.getJavaClass().getName());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("since", def.getSince());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("defaultPrefix", def.getFirstDefaultPrefix());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("componentFamily", def.getComponentFamily());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("componentType", def.getComponentType());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("id", def.getId());
                    JsonArray facetNames = new JsonJavaArray();
                    for (String facetName : def.getFacetNames()) {
                        facetNames.add(facetName);
                    }
                    // $NON-NLS-1$
                    defObj.putJsonProperty("facetNames", facetNames);
                    FacesProperty defaultProp = def.getDefaultFacesProperty();
                    if (defaultProp != null) {
                        JsonObject defaultPropObj = new JsonJavaObject();
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("name", defaultProp.getName());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("since", defaultProp.getSince());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("class", defaultProp.getJavaClass().getName());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("required", defaultProp.isRequired());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("attribute", defaultProp.isAttribute());
                    }
                    JsonArray properties = new JsonJavaArray();
                    for (String propName : def.getPropertyNames()) {
                        FacesProperty prop = def.getProperty(propName);
                        JsonObject propObj = new JsonJavaObject();
                        // $NON-NLS-1$
                        propObj.putJsonProperty("name", propName);
                        // $NON-NLS-1$
                        propObj.putJsonProperty("class", prop.getJavaClass().getName());
                        // $NON-NLS-1$
                        propObj.putJsonProperty("since", prop.getSince());
                        // $NON-NLS-1$
                        propObj.putJsonProperty("required", prop.isRequired());
                        // $NON-NLS-1$
                        propObj.putJsonProperty("attribute", prop.isAttribute());
                        properties.add(propObj);
                    }
                    // $NON-NLS-1$
                    defObj.putJsonProperty("properties", properties);
                    return defObj;
                } catch (JsonException e) {
                    throw new RuntimeException(e);
                }
            }).forEach(defObj -> {
                try {
                    defs.add(defObj);
                } catch (JsonException e) {
                    throw new RuntimeException(e);
                }
            });
            // $NON-NLS-1$
            componentInfo.putJsonProperty("components", defs);
        }
        os.print(componentInfo.toString());
    } catch (Throwable e) {
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintWriter out = new PrintWriter(baos);
        e.printStackTrace(out);
        out.flush();
        os.println(LineDelimitedJsonProgressMonitor.message(// $NON-NLS-1$ //$NON-NLS-2$
        "type", // $NON-NLS-1$ //$NON-NLS-2$
        "error", // $NON-NLS-1$
        "stackTrace", // $NON-NLS-1$
        baos.toString()));
    }
}
Also used : PrintWriter(java.io.PrintWriter) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpServlet(javax.servlet.http.HttpServlet) ServletException(javax.servlet.ServletException) JsonObject(com.ibm.commons.util.io.json.JsonObject) ExtensionManager(com.ibm.commons.extension.ExtensionManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) IOException(java.io.IOException) XspLibrary(com.ibm.xsp.library.XspLibrary) FacesProperty(com.ibm.xsp.registry.FacesProperty) LibraryServiceLoader(com.ibm.xsp.library.LibraryServiceLoader) List(java.util.List) HttpServletRequest(javax.servlet.http.HttpServletRequest) JsonJavaArray(com.ibm.commons.util.io.json.JsonJavaArray) JsonException(com.ibm.commons.util.io.json.JsonException) FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) ServletOutputStream(javax.servlet.ServletOutputStream) LineDelimitedJsonProgressMonitor(org.openntf.nsfodp.commons.LineDelimitedJsonProgressMonitor) JsonArray(com.ibm.commons.util.io.json.JsonArray) XspRegistryProvider(com.ibm.xsp.registry.config.XspRegistryProvider) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) JsonException(com.ibm.commons.util.io.json.JsonException) JsonJavaArray(com.ibm.commons.util.io.json.JsonJavaArray) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) ServletOutputStream(javax.servlet.ServletOutputStream) XspLibrary(com.ibm.xsp.library.XspLibrary) JsonObject(com.ibm.commons.util.io.json.JsonObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonArray(com.ibm.commons.util.io.json.JsonArray) FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonObject(com.ibm.commons.util.io.json.JsonObject) FacesProperty(com.ibm.xsp.registry.FacesProperty) PrintWriter(java.io.PrintWriter)

Example 3 with FacesComponentDefinition

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

the class StockComponentsServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setBufferSize(0);
    // $NON-NLS-1$ //$NON-NLS-2$
    resp.setHeader("Content-Type", "text/json");
    ServletOutputStream os = resp.getOutputStream();
    try {
        if (componentInfo == null) {
            SharableRegistryImpl facesRegistry = new SharableRegistryImpl(getClass().getPackage().getName());
            // $NON-NLS-1$
            List<Object> libraries = ExtensionManager.findServices((List<Object>) null, LibraryServiceLoader.class, "com.ibm.xsp.Library");
            libraries.stream().filter(lib -> lib instanceof XspLibrary).map(XspLibrary.class::cast).map(lib -> new LibraryWrapper(lib.getLibraryId(), lib)).map(wrapper -> {
                SimpleRegistryProvider provider = new SimpleRegistryProvider();
                provider.init(wrapper);
                return provider;
            }).map(XspRegistryProvider::getRegistry).forEach(facesRegistry::addDepend);
            facesRegistry.refreshReferences();
            componentInfo = new JsonJavaObject();
            JsonArray defs = new JsonJavaArray();
            facesRegistry.findComponentDefs().stream().filter(FacesComponentDefinition::isTag).map(def -> {
                try {
                    JsonObject defObj = new JsonJavaObject();
                    // $NON-NLS-1$
                    defObj.putJsonProperty("namespaceUri", def.getNamespaceUri());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("tagName", def.getTagName());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("class", def.getJavaClass().getName());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("since", def.getSince());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("defaultPrefix", def.getFirstDefaultPrefix());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("componentFamily", def.getComponentFamily());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("componentType", def.getComponentType());
                    // $NON-NLS-1$
                    defObj.putJsonProperty("id", def.getId());
                    JsonArray facetNames = new JsonJavaArray();
                    for (String facetName : def.getFacetNames()) {
                        facetNames.add(facetName);
                    }
                    // $NON-NLS-1$
                    defObj.putJsonProperty("facetNames", facetNames);
                    FacesProperty defaultProp = def.getDefaultFacesProperty();
                    if (defaultProp != null) {
                        JsonObject defaultPropObj = new JsonJavaObject();
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("name", defaultProp.getName());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("since", defaultProp.getSince());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("class", defaultProp.getJavaClass().getName());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("required", defaultProp.isRequired());
                        // $NON-NLS-1$
                        defaultPropObj.putJsonProperty("attribute", defaultProp.isAttribute());
                    }
                    JsonArray properties = new JsonJavaArray();
                    for (String propName : def.getPropertyNames()) {
                        FacesProperty prop = def.getProperty(propName);
                        JsonObject propObj = new JsonJavaObject();
                        // $NON-NLS-1$
                        propObj.putJsonProperty("name", propName);
                        // $NON-NLS-1$
                        propObj.putJsonProperty("class", prop.getJavaClass().getName());
                        // $NON-NLS-1$
                        propObj.putJsonProperty("since", prop.getSince());
                        // $NON-NLS-1$
                        propObj.putJsonProperty("required", prop.isRequired());
                        // $NON-NLS-1$
                        propObj.putJsonProperty("attribute", prop.isAttribute());
                        properties.add(propObj);
                    }
                    // $NON-NLS-1$
                    defObj.putJsonProperty("properties", properties);
                    return defObj;
                } catch (JsonException e) {
                    throw new RuntimeException(e);
                }
            }).forEach(defObj -> {
                try {
                    defs.add(defObj);
                } catch (JsonException e) {
                    throw new RuntimeException(e);
                }
            });
            // $NON-NLS-1$
            componentInfo.putJsonProperty("components", defs);
        }
        os.print(JsonGenerator.toJson(JsonJavaFactory.instance, componentInfo, false));
    } catch (Throwable e) {
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintWriter out = new PrintWriter(baos);
        e.printStackTrace(out);
        out.flush();
        os.println(baos.toString());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletException(javax.servlet.ServletException) ExtensionManager(com.ibm.commons.extension.ExtensionManager) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) JsonGenerator(com.ibm.commons.util.io.json.JsonGenerator) XspLibrary(com.ibm.xsp.library.XspLibrary) HttpServletRequest(javax.servlet.http.HttpServletRequest) JsonJavaArray(com.ibm.commons.util.io.json.JsonJavaArray) FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) JsonJavaFactory(com.ibm.commons.util.io.json.JsonJavaFactory) ServletOutputStream(javax.servlet.ServletOutputStream) JsonArray(com.ibm.commons.util.io.json.JsonArray) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) PrintWriter(java.io.PrintWriter) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) HttpServlet(javax.servlet.http.HttpServlet) JsonObject(com.ibm.commons.util.io.json.JsonObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) FacesProperty(com.ibm.xsp.registry.FacesProperty) WebServlet(javax.servlet.annotation.WebServlet) LibraryServiceLoader(com.ibm.xsp.library.LibraryServiceLoader) List(java.util.List) JsonException(com.ibm.commons.util.io.json.JsonException) XspRegistryProvider(com.ibm.xsp.registry.config.XspRegistryProvider) JsonException(com.ibm.commons.util.io.json.JsonException) JsonJavaArray(com.ibm.commons.util.io.json.JsonJavaArray) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) ServletOutputStream(javax.servlet.ServletOutputStream) XspLibrary(com.ibm.xsp.library.XspLibrary) JsonObject(com.ibm.commons.util.io.json.JsonObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonArray(com.ibm.commons.util.io.json.JsonArray) FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) JsonJavaObject(com.ibm.commons.util.io.json.JsonJavaObject) JsonObject(com.ibm.commons.util.io.json.JsonObject) FacesProperty(com.ibm.xsp.registry.FacesProperty) PrintWriter(java.io.PrintWriter)

Example 4 with FacesComponentDefinition

use of com.ibm.xsp.registry.FacesComponentDefinition 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

FacesComponentDefinition (com.ibm.xsp.registry.FacesComponentDefinition)4 ExtensionManager (com.ibm.commons.extension.ExtensionManager)2 JsonArray (com.ibm.commons.util.io.json.JsonArray)2 JsonException (com.ibm.commons.util.io.json.JsonException)2 JsonJavaArray (com.ibm.commons.util.io.json.JsonJavaArray)2 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)2 JsonObject (com.ibm.commons.util.io.json.JsonObject)2 XMLException (com.ibm.commons.xml.XMLException)2 LibraryServiceLoader (com.ibm.xsp.library.LibraryServiceLoader)2 LibraryWrapper (com.ibm.xsp.library.LibraryWrapper)2 XspLibrary (com.ibm.xsp.library.XspLibrary)2 FacesComplexDefinition (com.ibm.xsp.registry.FacesComplexDefinition)2 FacesProperty (com.ibm.xsp.registry.FacesProperty)2 SharableRegistryImpl (com.ibm.xsp.registry.SharableRegistryImpl)2 SimpleRegistryProvider (com.ibm.xsp.registry.config.SimpleRegistryProvider)2 XspRegistryProvider (com.ibm.xsp.registry.config.XspRegistryProvider)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 List (java.util.List)2