use of org.apache.openejb.jee.FacesConfig in project tomee by apache.
the class DeploymentLoader method addFacesConfigs.
/**
* Finds all faces configuration files and stores them in the WebModule
*
* @param webModule WebModule
* @throws OpenEJBException
*/
private void addFacesConfigs(final WebModule webModule) throws OpenEJBException {
//*************************IMPORTANT*******************************************
// TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
// look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
final Set<URL> facesConfigLocations = new HashSet<URL>();
// web.xml contains faces config locations in the context parameter javax.faces.CONFIG_FILES
final File warFile = new File(webModule.getJarLocation());
final WebApp webApp = webModule.getWebApp();
if (webApp != null) {
final String foundContextParam = webApp.contextParamsAsMap().get("javax.faces.CONFIG_FILES");
if (foundContextParam != null) {
// the value is a comma separated list of config files
final String commaDelimitedListOfFiles = foundContextParam.trim();
final String[] configFiles = commaDelimitedListOfFiles.split(",");
// trim any extra spaces in each file
final String[] trimmedConfigFiles = new String[configFiles.length];
for (int i = 0; i < configFiles.length; i++) {
trimmedConfigFiles[i] = configFiles[i].trim();
}
// convert each file to a URL and add it to facesConfigLocations
for (final String location : trimmedConfigFiles) {
if (!location.startsWith("/")) {
logger.error("A faces configuration file should be context relative when specified in web.xml. Please fix the value of context parameter javax.faces.CONFIG_FILES for the file " + location);
}
try {
final File file = new File(warFile, location).getCanonicalFile().getAbsoluteFile();
final URL url = file.toURI().toURL();
facesConfigLocations.add(url);
} catch (final IOException e) {
logger.error("Faces configuration file location bad: " + location, e);
}
}
} else {
logger.debug("faces config file is null");
}
}
// Search for WEB-INF/faces-config.xml
final File webInf = new File(warFile, "WEB-INF");
if (webInf.isDirectory()) {
File facesConfigFile = new File(webInf, "faces-config.xml");
if (facesConfigFile.exists()) {
try {
facesConfigFile = facesConfigFile.getCanonicalFile().getAbsoluteFile();
final URL url = facesConfigFile.toURI().toURL();
facesConfigLocations.add(url);
} catch (final IOException e) {
// TODO: kmalhi:: Remove the printStackTrace after testing
e.printStackTrace();
}
}
}
// flag an error and not allow the application to be deployed.
for (final URL location : facesConfigLocations) {
final FacesConfig facesConfig = ReadDescriptors.readFacesConfig(location);
webModule.getFacesConfigs().add(facesConfig);
if ("file".equals(location.getProtocol())) {
webModule.getWatchedResources().add(URLs.toFilePath(location));
}
}
}
use of org.apache.openejb.jee.FacesConfig in project tomee by apache.
the class ReadDescriptors method readFacesConfig.
public static FacesConfig readFacesConfig(final URL url) throws OpenEJBException {
try {
final Source src = getSource(url);
if (src == null) {
return new FacesConfig();
}
final String content = IO.slurp(src.get());
if (isEmpty(new ByteArrayInputStream(content.getBytes()), "faces-config")) {
return new FacesConfig();
}
return FacesConfigXml.unmarshal(new ByteArrayInputStream(content.getBytes()));
} catch (final SAXException e) {
throw new OpenEJBException("Cannot parse the faces configuration file: " + url.toExternalForm(), e);
} catch (final JAXBException e) {
throw new OpenEJBException("Cannot unmarshall the faces configuration file: " + url.toExternalForm(), e);
} catch (final IOException e) {
throw new OpenEJBException("Cannot read the faces configuration file: " + url.toExternalForm(), e);
} catch (final Exception e) {
throw new OpenEJBException("Encountered unknown error parsing the faces configuration file: " + url.toExternalForm(), e);
}
}
use of org.apache.openejb.jee.FacesConfig in project tomee by apache.
the class JsfTest method testFacesConfig.
/**
* This test requires that there are three managed beans in faces-config.xml. It will ask JaxbJavaee to load faces-config.xml
* and then assert if it found the three managed beans and checks if the class names are correct
*
* @throws Exception
*/
public void testFacesConfig() throws Exception {
final List<String> managedBeanClasses = new ArrayList<String>();
managedBeanClasses.add("org.apache.openejb.faces.EmployeeBean");
managedBeanClasses.add("org.apache.openejb.faces.OneBean");
managedBeanClasses.add("org.apache.openejb.faces.TwoBean");
final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("jsf/faces-config.xml");
final FacesConfig facesConfig = (FacesConfig) JaxbJavaee.unmarshalJavaee(FacesConfig.class, inputStream);
final List<FacesManagedBean> managedBean = facesConfig.getManagedBean();
for (final FacesManagedBean bean : managedBean) {
assertTrue(managedBeanClasses.contains(bean.getManagedBeanClass().trim()));
}
assertEquals(3, managedBean.size());
marshalAndUnmarshal(FacesConfig.class, "jsf/faces-config.xml", null);
}
use of org.apache.openejb.jee.FacesConfig in project tomee by apache.
the class JsfTest method test11.
public void test11() throws Exception {
marshalAndUnmarshal(FacesConfig.class, "jsf/1_1_dtd/faces-config-simple-src.xml", "jsf/1_0_dtd/faces-config-simple-expected.xml");
marshalAndUnmarshal(FacesConfig.class, "jsf/1_1_dtd/faces-config-moderate-src.xml", "jsf/1_0_dtd/faces-config-moderate-expected.xml");
marshalAndUnmarshal(FacesConfig.class, "jsf/1_1_dtd/faces-config-complex-src.xml", "jsf/1_0_dtd/faces-config-complex-expected.xml");
marshalAndUnmarshal(FacesConfig.class, "jsf/1_1_dtd/faces-config-empty-src.xml", "jsf/1_0_dtd/faces-config-empty-expected.xml");
final FacesConfig f = marshalAndUnmarshal(FacesConfig.class, "jsf/1_1_dtd/faces-config.xml", null);
}
use of org.apache.openejb.jee.FacesConfig in project tomee by apache.
the class FacesConfig22Test method unmarshallFacesConfig22.
@Test
public void unmarshallFacesConfig22() throws Exception {
final URL url = getClass().getClassLoader().getResource("a-faces-config-22.xml");
final FacesConfig facesConfig = FacesConfigXml.unmarshal(url);
assertNotNull(facesConfig);
}
Aggregations