Search in sources :

Example 11 with ConfigurationException

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

the class ParseConfigResourceToDOMTask method call.

// ----------------------------------------------- Methods from Callable
/**
 * @return the result of the parse operation (a DOM)
 * @throws Exception if an error occurs during the parsing process
 */
@Override
public DocumentInfo call() throws Exception {
    try {
        Timer timer = Timer.getInstance();
        if (timer != null) {
            timer.startTiming();
        }
        Document document = getDocument();
        if (timer != null) {
            timer.stopTiming();
            timer.logResult("Parse " + documentURI.toURL().toExternalForm());
        }
        return new DocumentInfo(document, documentURI);
    } catch (Exception e) {
        throw new ConfigurationException(format("Unable to parse document ''{0}'': {1}", documentURI.toURL().toExternalForm(), e.getMessage()), e);
    }
}
Also used : Timer(com.sun.faces.util.Timer) ConfigurationException(com.sun.faces.config.ConfigurationException) Document(org.w3c.dom.Document) ConfigurationException(com.sun.faces.config.ConfigurationException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 12 with ConfigurationException

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

the class ApplicationConfigProcessor method addSystemEventListener.

private void addSystemEventListener(ServletContext servletContext, FacesContext facesContext, Application application, Node systemEventListener) {
    NodeList children = systemEventListener.getChildNodes();
    String listenerClass = null;
    String eventClass = null;
    String sourceClass = null;
    for (int j = 0, len = children.getLength(); j < len; j++) {
        Node n = children.item(j);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            switch(n.getLocalName()) {
                case SYSTEM_EVENT_LISTENER_CLASS:
                    listenerClass = getNodeText(n);
                    break;
                case SYSTEM_EVENT_CLASS:
                    eventClass = getNodeText(n);
                    break;
                case SOURCE_CLASS:
                    sourceClass = getNodeText(n);
                    break;
            }
        }
    }
    if (listenerClass != null) {
        SystemEventListener systemEventListenerInstance = (SystemEventListener) createInstance(servletContext, facesContext, listenerClass, SystemEventListener.class, null, systemEventListener);
        if (systemEventListenerInstance != null) {
            systemEventListeners.add(systemEventListenerInstance);
            try {
                // If there is an eventClass, use it, otherwise use
                // SystemEvent.class
                // noinspection unchecked
                Class<? extends SystemEvent> eventClazz;
                if (eventClass != null) {
                    eventClazz = (Class<? extends SystemEvent>) loadClass(servletContext, facesContext, eventClass, this, null);
                } else {
                    eventClazz = SystemEvent.class;
                }
                // If there is a sourceClass, use it, otherwise use null
                Class<?> sourceClazz = sourceClass != null && sourceClass.length() != 0 ? Util.loadClass(sourceClass, this.getClass()) : null;
                application.subscribeToEvent(eventClazz, sourceClazz, systemEventListenerInstance);
                if (LOGGER.isLoggable(Level.FINE)) {
                    LOGGER.log(Level.FINE, "Subscribing for event {0} and source {1} using listener {2}", new Object[] { eventClazz.getName(), sourceClazz != null ? sourceClazz.getName() : "ANY", systemEventListenerInstance.getClass().getName() });
                }
            } catch (ClassNotFoundException cnfe) {
                throw new ConfigurationException(cnfe);
            }
        }
    }
}
Also used : SystemEventListener(jakarta.faces.event.SystemEventListener) ConfigurationException(com.sun.faces.config.ConfigurationException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Util.getLocaleFromString(com.sun.faces.util.Util.getLocaleFromString)

Example 13 with ConfigurationException

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

the class ConverterConfigProcessor method addConverters.

// --------------------------------------------------------- Private Methods
private void addConverters(NodeList converters, String namespace) {
    Application application = getApplication();
    Verifier verifier = Verifier.getCurrentInstance();
    for (int i = 0, size = converters.getLength(); i < size; i++) {
        Node converter = converters.item(i);
        NodeList children = ((Element) converter).getElementsByTagNameNS(namespace, "*");
        String converterId = null;
        String converterClass = null;
        String converterForClass = null;
        for (int c = 0, csize = children.getLength(); c < csize; c++) {
            Node n = children.item(c);
            switch(n.getLocalName()) {
                case CONVERTER_ID:
                    converterId = getNodeText(n);
                    break;
                case CONVERTER_CLASS:
                    converterClass = getNodeText(n);
                    break;
                case CONVERTER_FOR_CLASS:
                    converterForClass = getNodeText(n);
                    break;
            }
        }
        if (converterId != null && converterClass != null) {
            if (LOGGER.isLoggable(FINE)) {
                LOGGER.log(FINE, format("[Converter by ID] Calling Application.addConverter({0}, {1}", converterId, converterClass));
            }
            if (verifier != null) {
                verifier.validateObject(Verifier.ObjectType.CONVERTER, converterClass, Converter.class);
            }
            application.addConverter(converterId, converterClass);
        } else if (converterClass != null && converterForClass != null) {
            try {
                Class<?> cfcClass = Util.loadClass(converterForClass, this.getClass());
                if (LOGGER.isLoggable(FINE)) {
                    LOGGER.log(FINE, format("[Converter for Class] Calling Application.addConverter({0}, {1}", converterForClass, converterClass));
                }
                if (verifier != null) {
                    verifier.validateObject(Verifier.ObjectType.CONVERTER, converterClass, Converter.class);
                }
                application.addConverter(cfcClass, converterClass);
            } catch (ClassNotFoundException cnfe) {
                throw new ConfigurationException(cnfe);
            }
        }
    }
}
Also used : ConfigurationException(com.sun.faces.config.ConfigurationException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) FacesConverter(jakarta.faces.convert.FacesConverter) Converter(jakarta.faces.convert.Converter) Verifier(com.sun.faces.config.Verifier) Application(jakarta.faces.application.Application)

Example 14 with ConfigurationException

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

the class Documents method getXMLDocuments.

/**
 * <p>
 * Obtains an array of <code>Document</code>s to be processed
 * </p>
 *
 * @param servletContext the <code>ServletContext</code> for the application to be processed
 * @param providers <code>List</code> of <code>ConfigurationResourceProvider</code> instances that provide the URL of
 * the documents to parse.
 * @param executor the <code>ExecutorService</code> used to dispatch parse request to
 * @param validating flag indicating whether or not the documents should be validated
 * @return an array of <code>DocumentInfo</code>s
 */
public static DocumentInfo[] getXMLDocuments(ServletContext servletContext, List<ConfigurationResourceProvider> providers, ExecutorService executor, boolean validating) {
    // Query all configuration providers to give us a URL to the configuration they are providing
    List<FutureTask<Collection<URI>>> uriTasks = new ArrayList<>(providers.size());
    for (ConfigurationResourceProvider provider : providers) {
        FutureTask<Collection<URI>> uriTask = new FutureTask<>(new FindConfigResourceURIsTask(provider, servletContext));
        uriTasks.add(uriTask);
        if (executor != null) {
            executor.execute(uriTask);
        } else {
            uriTask.run();
        }
    }
    // Load and XML parse all documents to which the URLs that we collected above point to
    List<FutureTask<DocumentInfo>> docTasks = new ArrayList<>(providers.size() << 1);
    for (FutureTask<Collection<URI>> uriTask : uriTasks) {
        try {
            for (URI uri : uriTask.get()) {
                FutureTask<DocumentInfo> docTask = new FutureTask<>(new ParseConfigResourceToDOMTask(servletContext, validating, uri));
                docTasks.add(docTask);
                if (executor != null) {
                    executor.execute(docTask);
                } else {
                    docTask.run();
                }
            }
        } catch (InterruptedException ignored) {
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
    }
    // Collect the results of the documents we parsed above
    List<DocumentInfo> docs = new ArrayList<>(docTasks.size());
    for (FutureTask<DocumentInfo> docTask : docTasks) {
        try {
            docs.add(docTask.get());
        } catch (ExecutionException e) {
            throw new ConfigurationException(e);
        } catch (InterruptedException ignored) {
        }
    }
    return docs.toArray(new DocumentInfo[docs.size()]);
}
Also used : ParseConfigResourceToDOMTask(com.sun.faces.config.manager.tasks.ParseConfigResourceToDOMTask) ConfigurationResourceProvider(com.sun.faces.spi.ConfigurationResourceProvider) ArrayList(java.util.ArrayList) URI(java.net.URI) ConfigurationException(com.sun.faces.config.ConfigurationException) ExecutionException(java.util.concurrent.ExecutionException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FutureTask(java.util.concurrent.FutureTask) ConfigurationException(com.sun.faces.config.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Collection(java.util.Collection) FindConfigResourceURIsTask(com.sun.faces.config.manager.tasks.FindConfigResourceURIsTask) ExecutionException(java.util.concurrent.ExecutionException) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 15 with ConfigurationException

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

the class ValidatorConfigProcessor method processDefaultValidatorIds.

// --------------------------------------------------------- Private Methods
private void processDefaultValidatorIds() {
    Application app = getApplication();
    Map<String, String> defaultValidatorInfo = app.getDefaultValidatorInfo();
    for (Map.Entry<String, String> info : defaultValidatorInfo.entrySet()) {
        String defaultValidatorId = info.getKey();
        boolean found = false;
        for (Iterator<String> registered = app.getValidatorIds(); registered.hasNext(); ) {
            if (defaultValidatorId.equals(registered.next())) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new ConfigurationException(format("Default validator ''{0}'' does not reference a registered validator.", defaultValidatorId));
        }
    }
}
Also used : ConfigurationException(com.sun.faces.config.ConfigurationException) Application(jakarta.faces.application.Application) Map(java.util.Map)

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