use of org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet in project jaffa-framework by jaffa-projects.
the class JaffaI18nFactorySet method createDefaultFactory.
protected DefinitionsFactory createDefaultFactory(ServletContext servletContext) throws DefinitionsFactoryException, FileNotFoundException {
XmlDefinitionsSet rootXmlConfig = this.parseXmlFiles(servletContext, "", (XmlDefinitionsSet) null);
if (rootXmlConfig == null) {
throw new FileNotFoundException();
} else {
rootXmlConfig.resolveInheritances();
if (log.isDebugEnabled()) {
log.debug(rootXmlConfig);
}
DefinitionsFactory factory = new DefinitionsFactory(rootXmlConfig);
if (log.isDebugEnabled()) {
log.debug("factory loaded : " + factory);
}
return factory;
}
}
use of org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet in project jaffa-framework by jaffa-projects.
the class JaffaI18nFactorySet method parseXmlFile.
/**
* Parse specified xml file and find definitions from with in classpath by searching all jars
* and add definition to specified definitions set.
* This method is used to load several description files in one instances list.
* If filename exists and definition set is <code>null</code>, create a new set. Otherwise, return
* passed definition set (can be <code>null</code>).
* @param servletContext Current servlet context. Used to open file.
* @param xmlDefinitions Definitions set to which definitions will be added. If null, a definitions
* set is created on request.
* @return XmlDefinitionsSet The definitions set created or passed as parameter.
* @throws DefinitionsFactoryException On errors parsing file.
*/
protected XmlDefinitionsSet parseXmlFile(ServletContext servletContext, XmlDefinitionsSet xmlDefinitions) throws DefinitionsFactoryException {
if (log.isDebugEnabled()) {
log.debug("Parsing tiles definition files from classpath");
}
try {
List<Resource> resourceList = new ArrayList<>();
for (String filename : filenames) {
PathMatchingResourcePatternResolver resolver = OrderedPathMatchingResourcePatternResolver.getInstance();
resourceList.addAll(Arrays.asList(resolver.getResources(filename)));
}
// if( xmlParser == null )
if (true) {
xmlParser = new XmlParser();
xmlParser.setValidating(isValidatingParser);
}
// Check if definition set already exist.
if (xmlDefinitions == null) {
xmlDefinitions = new XmlDefinitionsSet();
}
if (resourceList != null && resourceList.size() > 0) {
for (Resource resource : resourceList) {
if (log.isDebugEnabled()) {
log.debug("Parsing tiles definition: " + resource.getFilename());
}
xmlParser.parse(resource.getInputStream(), xmlDefinitions);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Can't open files '" + filenames + "'");
}
return xmlDefinitions;
}
} catch (SAXException | IOException ex) {
if (log.isDebugEnabled()) {
log.debug("Error while parsing files '" + filenames + "'.");
ex.printStackTrace();
}
throw new DefinitionsFactoryException("Error while parsing files '" + filenames + "'. " + ex.getMessage(), ex);
}
return xmlDefinitions;
}
use of org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet in project jaffa-framework by jaffa-projects.
the class JaffaI18nFactorySetTest method testXmlDefinitionsLoading.
/**
* tests the xml definitions are correctly read and loaded, when passed with
* the tiles-defs.xml or any other file name
* @throws Exception
*/
@Test
public void testXmlDefinitionsLoading() throws Exception {
try {
// initialize
String tilesDefsFileName = "tiles-defs.xml";
// test
target.initFactory(null, tilesDefsFileName);
XmlDefinitionsSet xmlDefinitionsSet = target.parseXmlFile(null, null);
// verify
assertNotNull(xmlDefinitionsSet.getDefinitions());
assertNotNull(xmlDefinitionsSet.getDefinition("jaffa.FinderXmlLayout"));
assertNotNull(xmlDefinitionsSet.getDefinition("jaffa.MaintenanceLayout"));
assertNotNull(xmlDefinitionsSet.getDefinition("httpunittest.desktop"));
} catch (Exception ee) {
fail("Exception occurred while initializing Factory");
}
}
Aggregations