Search in sources :

Example 1 with ConfigurationException

use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.

the class FaceletTaglibConfigProcessor method processHandlerClass.

private void processHandlerClass(ServletContext sc, FacesContext facesContext, Node handlerClass, TagLibraryImpl taglibrary, String name) {
    String className = getNodeText(handlerClass);
    if (className == null) {
        throw new ConfigurationException("The tag named " + name + " from namespace " + taglibrary.getNamespace() + " has a null handler-class defined");
    }
    try {
        Class<?> clazz;
        try {
            clazz = loadClass(sc, facesContext, className, this, null);
            taglibrary.putTagHandler(name, clazz);
        } catch (NoClassDefFoundError defNotFound) {
            String message = defNotFound.toString();
            if (message.contains("com/sun/facelets/") || message.contains("com.sun.facelets.")) {
                if (LOGGER.isLoggable(WARNING)) {
                    LOGGER.log(WARNING, "faces.config.legacy.facelet.warning", new Object[] { handlerClass });
                }
            } else {
                throw defNotFound;
            }
        }
    } catch (ClassNotFoundException cnfe) {
        throw new ConfigurationException(cnfe);
    }
}
Also used : ConfigurationException(com.sun.faces.config.ConfigurationException)

Example 2 with ConfigurationException

use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.

the class FaceletTaglibConfigProcessor method processFunctions.

private void processFunctions(ServletContext sc, FacesContext facesContext, NodeList functions, TagLibraryImpl taglibrary) {
    if (functions != null && functions.getLength() > 0) {
        for (int i = 0, ilen = functions.getLength(); i < ilen; i++) {
            NodeList children = functions.item(i).getChildNodes();
            String functionName = null;
            String functionClass = null;
            String functionSignature = null;
            for (int j = 0, jlen = children.getLength(); j < jlen; j++) {
                Node n = children.item(j);
                if (n.getLocalName() != null) {
                    switch(n.getLocalName()) {
                        case FUNCTION_NAME:
                            functionName = getNodeText(n);
                            break;
                        case FUNCTION_CLASS:
                            functionClass = getNodeText(n);
                            break;
                        case FUNCTION_SIGNATURE:
                            functionSignature = getNodeText(n);
                            break;
                    }
                }
            }
            try {
                Class<?> clazz = loadClass(sc, facesContext, functionClass, this, null);
                Method m = createMethod(clazz, functionSignature);
                taglibrary.putFunction(functionName, m);
            } catch (Exception e) {
                throw new ConfigurationException(e);
            }
        }
    }
}
Also used : ConfigurationException(com.sun.faces.config.ConfigurationException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Method(java.lang.reflect.Method) ConfigurationException(com.sun.faces.config.ConfigurationException) MalformedURLException(java.net.MalformedURLException) FacesException(jakarta.faces.FacesException)

Example 3 with ConfigurationException

use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.

the class RenderKitConfigProcessor method process.

// -------------------------------------------- Methods from ConfigProcessor
@Override
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
    Map<String, Map<Document, List<Node>>> renderers = new LinkedHashMap<>();
    Map<String, Map<Document, List<Node>>> behaviorRenderers = new LinkedHashMap<>();
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    for (int i = 0; i < documentInfos.length; i++) {
        if (LOGGER.isLoggable(FINE)) {
            LOGGER.log(FINE, format("Processing render-kit elements for document: ''{0}''", documentInfos[i].getSourceURI()));
        }
        Document document = documentInfos[i].getDocument();
        String namespace = document.getDocumentElement().getNamespaceURI();
        NodeList renderkits = document.getDocumentElement().getElementsByTagNameNS(namespace, RENDERKIT);
        if (renderkits != null && renderkits.getLength() > 0) {
            addRenderKits(servletContext, facesContext, renderkits, document, renderers, behaviorRenderers, renderKitFactory);
        }
    }
    // Process annotated Renderers, ClientBehaviorRenderers first as Renderers configured
    // via config files take precedence
    processAnnotations(facesContext, FacesRenderer.class);
    processAnnotations(facesContext, FacesBehaviorRenderer.class);
    // Now add the accumulated renderers to the RenderKits
    for (Map.Entry<String, Map<Document, List<Node>>> entry : renderers.entrySet()) {
        RenderKit renderKit = renderKitFactory.getRenderKit(null, entry.getKey());
        if (renderKit == null) {
            throw new ConfigurationException(getExceptionMessageString(RENDERER_CANNOT_BE_REGISTERED_ID, entry.getKey()));
        }
        for (Map.Entry<Document, List<Node>> renderEntry : entry.getValue().entrySet()) {
            addRenderers(servletContext, facesContext, renderKit, renderEntry.getKey(), renderEntry.getValue());
        }
    }
    // Now add the accumulated behavior renderers to the RenderKits
    for (Map.Entry<String, Map<Document, List<Node>>> entry : behaviorRenderers.entrySet()) {
        RenderKit renderKit = renderKitFactory.getRenderKit(null, entry.getKey());
        if (renderKit == null) {
            throw new ConfigurationException(getExceptionMessageString(RENDERER_CANNOT_BE_REGISTERED_ID, entry.getKey()));
        }
        for (Map.Entry<Document, List<Node>> renderEntry : entry.getValue().entrySet()) {
            addClientBehaviorRenderers(servletContext, facesContext, renderKit, renderEntry.getKey(), renderEntry.getValue());
        }
    }
}
Also used : Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) MessageUtils.getExceptionMessageString(com.sun.faces.util.MessageUtils.getExceptionMessageString) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) ConfigurationException(com.sun.faces.config.ConfigurationException) RenderKit(jakarta.faces.render.RenderKit) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Example 4 with ConfigurationException

use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.

the class AbstractConfigProcessor method createInstance.

protected Object createInstance(ServletContext sc, FacesContext facesContext, String className, Class<?> rootType, Object root, Node source, boolean performInjection, boolean[] didPerformInjection) {
    Class<?> clazz;
    Object returnObject = null;
    if (className != null) {
        try {
            clazz = loadClass(sc, facesContext, className, returnObject, null);
            if (clazz != null) {
                if (returnObject == null) {
                    // an object to adapt
                    if (rootType != null && root != null) {
                        Constructor<?> construct = lookupConstructor(clazz, rootType);
                        if (construct != null) {
                            returnObject = construct.newInstance(root);
                        }
                    }
                }
                if (clazz != null && returnObject == null) {
                    returnObject = clazz.newInstance();
                }
                ApplicationInstanceFactoryMetadataMap<String, Object> classMetadataMap = getClassMetadataMap(sc);
                if (classMetadataMap.hasAnnotations(className) && performInjection) {
                    InjectionProvider injectionProvider = (InjectionProvider) facesContext.getAttributes().get(INJECTION_PROVIDER_KEY);
                    try {
                        injectionProvider.inject(returnObject);
                    } catch (InjectionProviderException ex) {
                        LOGGER.log(SEVERE, "Unable to inject instance" + className, ex);
                        throw new FacesException(ex);
                    }
                    try {
                        injectionProvider.invokePostConstruct(returnObject);
                    } catch (InjectionProviderException ex) {
                        LOGGER.log(SEVERE, "Unable to invoke @PostConstruct annotated method on instance " + className, ex);
                        throw new FacesException(ex);
                    }
                    didPerformInjection[0] = true;
                }
            }
        } catch (ClassNotFoundException cnfe) {
            throw new ConfigurationException(buildMessage(format("Unable to find class ''{0}''", className), source), cnfe);
        } catch (NoClassDefFoundError ncdfe) {
            throw new ConfigurationException(buildMessage(format("Class ''{0}'' is missing a runtime dependency: {1}", className, ncdfe.toString()), source), ncdfe);
        } catch (ClassCastException cce) {
            throw new ConfigurationException(buildMessage(format("Class ''{0}'' is not an instance of ''{1}''", className, rootType), source), cce);
        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | FacesException e) {
            throw new ConfigurationException(buildMessage(format("Unable to create a new instance of ''{0}'': {1}", className, e.toString()), source), e);
        }
    }
    return returnObject;
}
Also used : InjectionProviderException(com.sun.faces.spi.InjectionProviderException) InjectionProvider(com.sun.faces.spi.InjectionProvider) FacesException(jakarta.faces.FacesException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfigurationException(com.sun.faces.config.ConfigurationException)

Example 5 with ConfigurationException

use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.

the class FaceletTaglibConfigProcessor method processValidator.

private void processValidator(ServletContext sc, FacesContext facesContext, NodeList validator, TagLibraryImpl taglibrary, String name) {
    if (validator != null && validator.getLength() > 0) {
        String validatorId = null;
        String handlerClass = null;
        for (int i = 0, ilen = validator.getLength(); i < ilen; i++) {
            Node n = validator.item(i);
            if (n.getLocalName() != null) {
                switch(n.getLocalName()) {
                    case VALIDATOR_ID:
                        validatorId = getNodeText(n);
                        break;
                    case HANDLER_CLASS:
                        handlerClass = getNodeText(n);
                        break;
                }
            }
        }
        if (handlerClass != null) {
            try {
                Class<?> clazz = loadClass(sc, facesContext, handlerClass, this, null);
                taglibrary.putValidator(name, validatorId, clazz);
            } catch (NoClassDefFoundError defNotFound) {
                String message = defNotFound.toString();
                if (message.contains("com/sun/facelets/") || message.contains("com.sun.facelets.")) {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        LOGGER.log(Level.WARNING, "faces.config.legacy.facelet.warning", new Object[] { handlerClass });
                    }
                } else {
                    throw defNotFound;
                }
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException(e);
            }
        } else {
            taglibrary.putValidator(name, validatorId);
        }
    }
}
Also used : ConfigurationException(com.sun.faces.config.ConfigurationException) Node(org.w3c.dom.Node)

Aggregations

ConfigurationException (com.sun.faces.config.ConfigurationException)15 Node (org.w3c.dom.Node)8 NodeList (org.w3c.dom.NodeList)4 DocumentInfo (com.sun.faces.config.manager.documents.DocumentInfo)2 Timer (com.sun.faces.util.Timer)2 FacesException (jakarta.faces.FacesException)2 Application (jakarta.faces.application.Application)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Document (org.w3c.dom.Document)2 Verifier (com.sun.faces.config.Verifier)1 FindConfigResourceURIsTask (com.sun.faces.config.manager.tasks.FindConfigResourceURIsTask)1 ParseConfigResourceToDOMTask (com.sun.faces.config.manager.tasks.ParseConfigResourceToDOMTask)1 ConfigurationResourceProvider (com.sun.faces.spi.ConfigurationResourceProvider)1 InjectionProvider (com.sun.faces.spi.InjectionProvider)1 InjectionProviderException (com.sun.faces.spi.InjectionProviderException)1 MessageUtils.getExceptionMessageString (com.sun.faces.util.MessageUtils.getExceptionMessageString)1 Util.getLocaleFromString (com.sun.faces.util.Util.getLocaleFromString)1 Converter (jakarta.faces.convert.Converter)1