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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations