Search in sources :

Example 1 with DocumentInfo

use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.

the class Documents method sortDocuments.

/**
 * <p>
 * Sort the <code>faces-config</code> documents found on the classpath and those specified by the
 * <code>jakarta.faces.CONFIG_FILES</code> context init parameter.
 * </p>
 *
 * @param facesDocuments an array of <em>all</em> <code>faces-config</code> documents
 * @param webInfFacesConfig FacesConfigInfo representing the WEB-INF/faces-config.xml for this app
 *
 * @return the sorted documents
 */
public static DocumentInfo[] sortDocuments(DocumentInfo[] facesDocuments, FacesConfigInfo webInfFacesConfig) {
    int len = webInfFacesConfig.isWebInfFacesConfig() ? facesDocuments.length - 1 : facesDocuments.length;
    List<String> absoluteOrdering = webInfFacesConfig.getAbsoluteOrdering();
    if (len > 1) {
        List<DocumentOrderingWrapper> list = new ArrayList<>();
        for (int i = 1; i < len; i++) {
            list.add(new DocumentOrderingWrapper(facesDocuments[i]));
        }
        DocumentOrderingWrapper[] ordering = list.toArray(new DocumentOrderingWrapper[list.size()]);
        if (absoluteOrdering == null) {
            DocumentOrderingWrapper.sort(ordering);
            // the original array with the sorted documentation.
            for (int i = 1; i < len; i++) {
                facesDocuments[i] = ordering[i - 1].getDocument();
            }
            return facesDocuments;
        } else {
            DocumentOrderingWrapper[] result = DocumentOrderingWrapper.sort(ordering, absoluteOrdering);
            DocumentInfo[] ret = new DocumentInfo[webInfFacesConfig.isWebInfFacesConfig() ? result.length + 2 : result.length + 1];
            for (int i = 1; i < len; i++) {
                ret[i] = result[i - 1].getDocument();
            }
            // Add the impl specific config file
            ret[0] = facesDocuments[0];
            // Add the WEB-INF if necessary
            if (webInfFacesConfig.isWebInfFacesConfig()) {
                ret[ret.length - 1] = facesDocuments[facesDocuments.length - 1];
            }
            return ret;
        }
    }
    return facesDocuments;
}
Also used : ArrayList(java.util.ArrayList) DocumentOrderingWrapper(com.sun.faces.config.manager.documents.DocumentOrderingWrapper) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 2 with DocumentInfo

use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.

the class Documents method getProgrammaticDocuments.

public static List<DocumentInfo> getProgrammaticDocuments(List<ApplicationConfigurationPopulator> configPopulators) throws ParserConfigurationException {
    List<DocumentInfo> programmaticDocuments = new ArrayList<>();
    DOMImplementation domImpl = createDOMImplementation();
    for (ApplicationConfigurationPopulator populator : configPopulators) {
        Document facesConfigDoc = createEmptyFacesConfigDocument(domImpl);
        try {
            populator.populateApplicationConfiguration(facesConfigDoc);
            programmaticDocuments.add(new DocumentInfo(facesConfigDoc, null));
        } catch (Throwable e) {
            if (LOGGER.isLoggable(INFO)) {
                LOGGER.log(INFO, "{0} thrown when invoking {1}.populateApplicationConfigurationResources: {2}", new String[] { e.getClass().getName(), populator.getClass().getName(), e.getMessage() });
            }
        }
    }
    return programmaticDocuments;
}
Also used : ApplicationConfigurationPopulator(jakarta.faces.application.ApplicationConfigurationPopulator) ArrayList(java.util.ArrayList) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 3 with DocumentInfo

use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.

the class FacesConfigOrderingTestCase method testNoOrderingStartWithCab.

// ------------------------------------------------- Individual Test Methods
/**
 * <p>
 * verify that the overrides specified in the faces-config.xml in the user's
 * webapp take precedence.
 * </p>
 *
 * @throws java.lang.Exception
 */
public void testNoOrderingStartWithCab() throws Exception {
    DocumentInfo docC = createDocument("C", null, null);
    DocumentInfo doca = createDocument("a", null, null);
    DocumentInfo docb = createDocument(null, null, null);
    List<DocumentOrderingWrapper> documents = new ArrayList<DocumentOrderingWrapper>();
    // J-
    Collections.addAll(documents, new DocumentOrderingWrapper(docC), new DocumentOrderingWrapper(doca), new DocumentOrderingWrapper(docb));
    // J+
    DocumentOrderingWrapper[] wrappers = documents.toArray(new DocumentOrderingWrapper[documents.size()]);
    String[] originalOrder = extractNames(wrappers);
    DocumentOrderingWrapper.sort(wrappers);
    String[] orderedNames = extractNames(wrappers);
    // a solution:
    // ['C', 'a', '']
    List<String> original = Arrays.asList(originalOrder);
    List<String> actually = Arrays.asList(orderedNames);
    List<String> possibility1 = Arrays.asList("C", "a", "");
    boolean assertion = (actually.equals(possibility1));
    String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n";
    assertTrue(message, assertion);
    System.out.println("testNoOrderingStartWithCab: Passed" + message);
}
Also used : ArrayList(java.util.ArrayList) DocumentOrderingWrapper(com.sun.faces.config.manager.documents.DocumentOrderingWrapper) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 4 with DocumentInfo

use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.

the class FacesConfigOrderingTestCase method testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithABCD.

public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithABCD() throws Exception {
    List<String> docAAfterIds = new ArrayList<String>();
    Collections.addAll(docAAfterIds, "D");
    // C should before B, hence B needs to be after C
    List<String> docBAfterIds = new ArrayList<String>();
    Collections.addAll(docBAfterIds, "C");
    List<String> docBBeforeIds = new ArrayList<String>();
    Collections.addAll(docBBeforeIds, "@others");
    List<String> docCAfterIds = new ArrayList<String>();
    Collections.addAll(docCAfterIds, "D");
    List<String> docCBeforeIds = new ArrayList<String>();
    Collections.addAll(docCBeforeIds, "B");
    DocumentInfo docA = createDocument("A", null, docAAfterIds);
    DocumentInfo docB = createDocument("B", docBBeforeIds, docBAfterIds);
    DocumentInfo docC = createDocument("C", docCBeforeIds, docCAfterIds);
    DocumentInfo docD = createDocument("D", null, null);
    List<DocumentOrderingWrapper> documents = new ArrayList<DocumentOrderingWrapper>();
    // J-
    Collections.addAll(documents, new DocumentOrderingWrapper(docA), new DocumentOrderingWrapper(docB), new DocumentOrderingWrapper(docC), new DocumentOrderingWrapper(docD));
    // J+
    DocumentOrderingWrapper[] wrappers = documents.toArray(new DocumentOrderingWrapper[documents.size()]);
    String[] originalOrder = extractNames(wrappers);
    DocumentOrderingWrapper.sort(wrappers);
    String[] orderedNames = extractNames(wrappers);
    // a solution:
    // ['D', 'C', 'B', 'A']
    List<String> original = Arrays.asList(originalOrder);
    List<String> actually = Arrays.asList(orderedNames);
    List<String> possibility1 = Arrays.asList("D", "C", "B", "A");
    boolean assertion = (actually.equals(possibility1));
    String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n";
    assertTrue(message, assertion);
    System.out.println("testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithABCD: Passed" + message);
}
Also used : ArrayList(java.util.ArrayList) DocumentOrderingWrapper(com.sun.faces.config.manager.documents.DocumentOrderingWrapper) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Example 5 with DocumentInfo

use of com.sun.faces.config.manager.documents.DocumentInfo in project mojarra by eclipse-ee4j.

the class FacesConfigOrderingTestCase method testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithADBC.

public void testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithADBC() throws Exception {
    List<String> docAAfterIds = new ArrayList<String>();
    Collections.addAll(docAAfterIds, "D");
    // C should before B, hence B needs to be after C
    List<String> docBAfterIds = new ArrayList<String>();
    Collections.addAll(docBAfterIds, "C");
    List<String> docBBeforeIds = new ArrayList<String>();
    Collections.addAll(docBBeforeIds, "@others");
    List<String> docCAfterIds = new ArrayList<String>();
    Collections.addAll(docCAfterIds, "D");
    List<String> docCBeforeIds = new ArrayList<String>();
    Collections.addAll(docCBeforeIds, "B");
    DocumentInfo docA = createDocument("A", null, docAAfterIds);
    DocumentInfo docB = createDocument("B", docBBeforeIds, docBAfterIds);
    DocumentInfo docC = createDocument("C", docCBeforeIds, docCAfterIds);
    DocumentInfo docD = createDocument("D", null, null);
    List<DocumentOrderingWrapper> documents = new ArrayList<DocumentOrderingWrapper>();
    // J-
    Collections.addAll(documents, new DocumentOrderingWrapper(docA), new DocumentOrderingWrapper(docD), new DocumentOrderingWrapper(docB), new DocumentOrderingWrapper(docC));
    // J+
    DocumentOrderingWrapper[] wrappers = documents.toArray(new DocumentOrderingWrapper[documents.size()]);
    String[] originalOrder = extractNames(wrappers);
    DocumentOrderingWrapper.sort(wrappers);
    String[] orderedNames = extractNames(wrappers);
    // a solution:
    // ['D', 'C', 'B', 'A']
    List<String> original = Arrays.asList(originalOrder);
    List<String> actually = Arrays.asList(orderedNames);
    List<String> possibility1 = Arrays.asList("D", "C", "B", "A");
    boolean assertion = (actually.equals(possibility1));
    String message = "\n original: " + original + "\n expected: " + possibility1 + "\n actually: " + actually + "\n";
    assertTrue(message, assertion);
    System.out.println("testAafterD_BafterCbeforeOthers_CafterDbeforeB_startWithADBC: Passed" + message);
}
Also used : ArrayList(java.util.ArrayList) DocumentOrderingWrapper(com.sun.faces.config.manager.documents.DocumentOrderingWrapper) DocumentInfo(com.sun.faces.config.manager.documents.DocumentInfo)

Aggregations

DocumentInfo (com.sun.faces.config.manager.documents.DocumentInfo)13 ArrayList (java.util.ArrayList)9 DocumentOrderingWrapper (com.sun.faces.config.manager.documents.DocumentOrderingWrapper)6 Document (org.w3c.dom.Document)4 ConfigurationException (com.sun.faces.config.ConfigurationException)2 FacesConfigInfo (com.sun.faces.config.manager.FacesConfigInfo)2 URI (java.net.URI)2 ExecutionException (java.util.concurrent.ExecutionException)2 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 HighAvailabilityEnabler (com.sun.faces.spi.HighAvailabilityEnabler)1 InjectionProvider (com.sun.faces.spi.InjectionProvider)1 ThreadContext (com.sun.faces.spi.ThreadContext)1 Timer (com.sun.faces.util.Timer)1 FacesException (jakarta.faces.FacesException)1 ApplicationConfigurationPopulator (jakarta.faces.application.ApplicationConfigurationPopulator)1 ConfigurableNavigationHandler (jakarta.faces.application.ConfigurableNavigationHandler)1 NavigationHandler (jakarta.faces.application.NavigationHandler)1 IOException (java.io.IOException)1