Search in sources :

Example 1 with XmlDefinitionsSet

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;
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) DefinitionsFactory(org.apache.struts.tiles.xmlDefinition.DefinitionsFactory) XmlDefinitionsSet(org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet)

Example 2 with XmlDefinitionsSet

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;
}
Also used : XmlParser(org.apache.struts.tiles.xmlDefinition.XmlParser) DefinitionsFactoryException(org.apache.struts.tiles.DefinitionsFactoryException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) OrderedPathMatchingResourcePatternResolver(org.jaffa.util.OrderedPathMatchingResourcePatternResolver) XmlDefinitionsSet(org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet) SAXException(org.xml.sax.SAXException)

Example 3 with XmlDefinitionsSet

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");
    }
}
Also used : XmlDefinitionsSet(org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet) Test(org.junit.Test)

Aggregations

XmlDefinitionsSet (org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 DefinitionsFactoryException (org.apache.struts.tiles.DefinitionsFactoryException)1 DefinitionsFactory (org.apache.struts.tiles.xmlDefinition.DefinitionsFactory)1 XmlParser (org.apache.struts.tiles.xmlDefinition.XmlParser)1 OrderedPathMatchingResourcePatternResolver (org.jaffa.util.OrderedPathMatchingResourcePatternResolver)1 Test (org.junit.Test)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 SAXException (org.xml.sax.SAXException)1