Search in sources :

Example 1 with FacesDefinition

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

the class AbstractSchemaServlet method findDefinitionElement.

/**
 * Finds the XML element for the given property in its original .xsp-config file.
 *
 * @param def the containing {@link FacesDefinition} for the property
 * @param prop the {@link FacesProperty} to search for
 * @return an {@link Element} describing the definition, or {@code null} if it cannot be found
 */
private Element findDefinitionElement(FacesDefinition def, FacesProperty prop) {
    try {
        Element parent = findDefinitionElement(def);
        if (parent != null) {
            // Check for the property directly
            Element propElement = Stream.of(DOMUtil.nodes(parent, "property/property-name[normalize-space(text())='" + prop.getName() + "']")).filter(Element.class::isInstance).map(Element.class::cast).map(el -> el.getParentNode()).map(Element.class::cast).findFirst().orElse(null);
            if (propElement != null) {
                // Great!
                return propElement;
            }
            // Check its parent
            if (def.getParent() != null) {
                propElement = findDefinitionElement(def.getParent(), prop);
                if (propElement != null) {
                    return propElement;
                }
            }
            Collection<String> groups = def.getGroupTypeRefs();
            if (groups != null && !groups.isEmpty()) {
                String propFile = prop.getFile().getFilePath();
                Document propDoc = getXspConfig(propFile);
                if (propDoc != null) {
                    return findInGroups(prop, propDoc, groups);
                }
            }
        }
        return null;
    } catch (XMLException e) {
        throw new RuntimeException(e);
    }
}
Also used : FacesListener(javax.faces.event.FacesListener) FacesSimpleProperty(com.ibm.xsp.registry.FacesSimpleProperty) ServletException(javax.servlet.ServletException) Date(java.util.Date) ExtensionManager(com.ibm.commons.extension.ExtensionManager) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) HashMap(java.util.HashMap) XspLibrary(com.ibm.xsp.library.XspLibrary) TemporalAccessor(java.time.temporal.TemporalAccessor) FacesComplexDefinition(com.ibm.xsp.registry.FacesComplexDefinition) HttpServletRequest(javax.servlet.http.HttpServletRequest) FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) Document(org.w3c.dom.Document) ActionGroup(com.ibm.xsp.actions.ActionGroup) Map(java.util.Map) Node(org.w3c.dom.Node) LocalTime(java.time.LocalTime) AbstractContainerProperty(com.ibm.xsp.registry.AbstractContainerProperty) MethodBinding(javax.faces.el.MethodBinding) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) PrintWriter(java.io.PrintWriter) PathUtil(com.ibm.commons.util.PathUtil) DOMUtil(com.ibm.commons.xml.DOMUtil) FacesValidatorDefinition(com.ibm.xsp.registry.FacesValidatorDefinition) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) Properties(java.util.Properties) HttpServlet(javax.servlet.http.HttpServlet) FacesContainerProperty(com.ibm.xsp.registry.FacesContainerProperty) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) FacesDefinition(com.ibm.xsp.registry.FacesDefinition) Collectors(java.util.stream.Collectors) ValueBinding(javax.faces.el.ValueBinding) FacesProperty(com.ibm.xsp.registry.FacesProperty) UIComponent(javax.faces.component.UIComponent) LibraryServiceLoader(com.ibm.xsp.library.LibraryServiceLoader) List(java.util.List) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) XspRegistryProvider(com.ibm.xsp.registry.config.XspRegistryProvider) Format(com.ibm.commons.xml.Format) XMLException(com.ibm.commons.xml.XMLException) InputStream(java.io.InputStream) ComplexContainerTreeNode(com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode) XMLException(com.ibm.commons.xml.XMLException) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 2 with FacesDefinition

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

the class AbstractSchemaServlet method outProperty.

private void outProperty(FacesDefinition def, FacesProperty prop, Element element, SharableRegistryImpl registry) {
    // TODO check run/load binding from FacesSimpleProperty
    Class<?> clazz = prop.getJavaClass();
    if (prop instanceof AbstractContainerProperty) {
        clazz = ((AbstractContainerProperty) prop).getItemProperty().getJavaClass();
    }
    if (isBindingType(prop)) {
        outAttribute(def, prop, element, extMap.get(this.namespace) + ":attrBinding", false);
    } else if (byte.class.equals(clazz) || short.class.equals(clazz) || int.class.equals(clazz) || long.class.equals(clazz) || Byte.class.equals(clazz) || Short.class.equals(clazz) || Integer.class.equals(clazz) || Long.class.equals(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrInteger", false);
    } else if (boolean.class.equals(clazz) || Boolean.class.equals(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrBoolean", false);
    } else if (float.class.equals(clazz) || double.class.equals(clazz) || Number.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrDecimal", false);
    } else if (LocalTime.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrTime", false);
    } else if (Date.class.equals(clazz) || TemporalAccessor.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, extMap.get(namespace) + ":attrDate", false);
    } else if ("id".equals(prop.getName())) {
        outAttribute(def, prop, element, "xs:ID", false);
    } else if (CharSequence.class.isAssignableFrom(clazz)) {
        outAttribute(def, prop, element, "xs:string", false);
    } else if (Object.class.equals(clazz) || FacesListener.class.isAssignableFrom(clazz)) {
        // FacesListeners lead to an xp: prefix below if left unhandled
        outAttribute(def, prop, element, "xs:string", false);
    } else {
        // Figure out if it's complex or not
        Class<?> finalClazz = clazz;
        FacesDefinition propDef = registry.findDefs().stream().filter(def2 -> def2.getJavaClass().equals(finalClazz)).findFirst().orElse(null);
        if (propDef != null) {
            outAttribute(def, prop, element, extMap.get(propDef.getNamespaceUri()) + ':' + toElementName(propDef, false), true);
        } else {
            outAttribute(def, prop, element, "xs:string", false);
        }
    }
}
Also used : FacesDefinition(com.ibm.xsp.registry.FacesDefinition) FacesListener(javax.faces.event.FacesListener) AbstractContainerProperty(com.ibm.xsp.registry.AbstractContainerProperty)

Example 3 with FacesDefinition

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

the class AbstractSchemaServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
        Document doc = DOMUtil.createDocument(namespace, "xs:schema");
        doc.setXmlStandalone(true);
        Element schema = doc.getDocumentElement();
        schema.setAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
        schema.setAttribute("xmlns:" + extMap.get(namespace), namespace);
        schema.setAttribute("targetNamespace", namespace);
        schema.setAttribute("elementFormDefault", "qualified");
        for (String importUri : this.imports) {
            schema.setAttribute("xmlns:" + extMap.get(importUri), importUri);
            Element importEl = DOMUtil.createElement(doc, schema, "xs:import");
            importEl.setAttribute("namespace", importUri);
            // importEl.setAttribute("schemaLocation", URI.create(req.getRequestURL().toString()).resolve(extMap.get(importUri) + ".xsd").toString());
            importEl.setAttribute("schemaLocation", extMap.get(importUri) + ".xsd");
        }
        outSimpleTypes(schema);
        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();
        @SuppressWarnings("unchecked") List<FacesDefinition> defs = (List<FacesDefinition>) (List<?>) facesRegistry.findDefs();
        defs.stream().filter(FacesDefinition::isTag).filter(def -> StringUtil.equals(namespace, def.getNamespaceUri())).forEach(def -> outComponentDefinition(def, schema, facesRegistry, false));
        resp.setContentType("text/xml");
        DOMUtil.serialize(resp.getOutputStream(), doc, new Format(2, true, "UTF-8"));
    } catch (Throwable e) {
        e.printStackTrace();
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage());
        resp.setContentType("text/plain");
        e.printStackTrace(new PrintWriter(resp.getOutputStream()));
        resp.getOutputStream().flush();
        e.printStackTrace();
    }
}
Also used : FacesListener(javax.faces.event.FacesListener) FacesSimpleProperty(com.ibm.xsp.registry.FacesSimpleProperty) ServletException(javax.servlet.ServletException) Date(java.util.Date) ExtensionManager(com.ibm.commons.extension.ExtensionManager) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) HashMap(java.util.HashMap) XspLibrary(com.ibm.xsp.library.XspLibrary) TemporalAccessor(java.time.temporal.TemporalAccessor) FacesComplexDefinition(com.ibm.xsp.registry.FacesComplexDefinition) HttpServletRequest(javax.servlet.http.HttpServletRequest) FacesComponentDefinition(com.ibm.xsp.registry.FacesComponentDefinition) Document(org.w3c.dom.Document) ActionGroup(com.ibm.xsp.actions.ActionGroup) Map(java.util.Map) Node(org.w3c.dom.Node) LocalTime(java.time.LocalTime) AbstractContainerProperty(com.ibm.xsp.registry.AbstractContainerProperty) MethodBinding(javax.faces.el.MethodBinding) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) PrintWriter(java.io.PrintWriter) PathUtil(com.ibm.commons.util.PathUtil) DOMUtil(com.ibm.commons.xml.DOMUtil) FacesValidatorDefinition(com.ibm.xsp.registry.FacesValidatorDefinition) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) Properties(java.util.Properties) HttpServlet(javax.servlet.http.HttpServlet) FacesContainerProperty(com.ibm.xsp.registry.FacesContainerProperty) Collection(java.util.Collection) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) FacesDefinition(com.ibm.xsp.registry.FacesDefinition) Collectors(java.util.stream.Collectors) ValueBinding(javax.faces.el.ValueBinding) FacesProperty(com.ibm.xsp.registry.FacesProperty) UIComponent(javax.faces.component.UIComponent) LibraryServiceLoader(com.ibm.xsp.library.LibraryServiceLoader) List(java.util.List) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) StringUtil(com.ibm.commons.util.StringUtil) XspRegistryProvider(com.ibm.xsp.registry.config.XspRegistryProvider) Format(com.ibm.commons.xml.Format) XMLException(com.ibm.commons.xml.XMLException) InputStream(java.io.InputStream) ComplexContainerTreeNode(com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode) LibraryWrapper(com.ibm.xsp.library.LibraryWrapper) Element(org.w3c.dom.Element) XspLibrary(com.ibm.xsp.library.XspLibrary) FacesDefinition(com.ibm.xsp.registry.FacesDefinition) Document(org.w3c.dom.Document) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) Format(com.ibm.commons.xml.Format) SimpleRegistryProvider(com.ibm.xsp.registry.config.SimpleRegistryProvider) List(java.util.List) PrintWriter(java.io.PrintWriter)

Aggregations

AbstractContainerProperty (com.ibm.xsp.registry.AbstractContainerProperty)3 FacesDefinition (com.ibm.xsp.registry.FacesDefinition)3 FacesListener (javax.faces.event.FacesListener)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 XMLException (com.ibm.commons.xml.XMLException)2 ActionGroup (com.ibm.xsp.actions.ActionGroup)2 ComplexContainerTreeNode (com.ibm.xsp.extlib.tree.complex.ComplexContainerTreeNode)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 FacesComponentDefinition (com.ibm.xsp.registry.FacesComponentDefinition)2 FacesContainerProperty (com.ibm.xsp.registry.FacesContainerProperty)2 FacesProperty (com.ibm.xsp.registry.FacesProperty)2 FacesSimpleProperty (com.ibm.xsp.registry.FacesSimpleProperty)2 FacesValidatorDefinition (com.ibm.xsp.registry.FacesValidatorDefinition)2