Search in sources :

Example 6 with DefinitionsFactoryException

use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.

the class InitDefinitionsTag method doStartTag.

/**
 * Do start tag.
 */
public int doStartTag() throws JspException {
    DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(pageContext.getRequest(), pageContext.getServletContext());
    if (factory != null)
        return SKIP_BODY;
    DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
    factoryConfig.setFactoryClassname(classname);
    factoryConfig.setDefinitionConfigFiles(filename);
    try {
        factory = TilesUtil.createDefinitionsFactory(pageContext.getServletContext(), factoryConfig);
    } catch (DefinitionsFactoryException ex) {
        ex.printStackTrace();
        throw new JspException(ex);
    }
    return SKIP_BODY;
}
Also used : JspException(javax.servlet.jsp.JspException) DefinitionsFactoryConfig(org.apache.struts.tiles.DefinitionsFactoryConfig) DefinitionsFactoryException(org.apache.struts.tiles.DefinitionsFactoryException) DefinitionsFactory(org.apache.struts.tiles.DefinitionsFactory)

Example 7 with DefinitionsFactoryException

use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.

the class RedeployableActionServlet method getRequestProcessor.

protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config) throws ServletException {
    if (tileProcessor != null) {
        TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
        return processor;
    }
    // reset the request processor
    String requestProcessorKey = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();
    getServletContext().removeAttribute(requestProcessorKey);
    // create a new request processor instance
    TilesRequestProcessor processor = (TilesRequestProcessor) super.getRequestProcessor(config);
    tileProcessor = processor;
    try {
        // reload Tiles defs
        DefinitionsFactory factory = processor.getDefinitionsFactory();
        factory.init(factory.getConfig(), getServletContext());
    // System.out.println("reloaded tiles-definitions");
    } catch (DefinitionsFactoryException e) {
        e.printStackTrace();
    }
    return processor;
}
Also used : TilesRequestProcessor(org.apache.struts.tiles.TilesRequestProcessor) DefinitionsFactoryException(org.apache.struts.tiles.DefinitionsFactoryException) DefinitionsFactory(org.apache.struts.tiles.DefinitionsFactory)

Example 8 with DefinitionsFactoryException

use of org.apache.struts.tiles.DefinitionsFactoryException 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)

Aggregations

DefinitionsFactoryException (org.apache.struts.tiles.DefinitionsFactoryException)8 IOException (java.io.IOException)3 DefinitionsFactory (org.apache.struts.tiles.DefinitionsFactory)3 ComponentDefinitionsFactory (org.apache.struts.tiles.ComponentDefinitionsFactory)2 FactoryNotFoundException (org.apache.struts.tiles.FactoryNotFoundException)2 SAXException (org.xml.sax.SAXException)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 ServletContext (javax.servlet.ServletContext)1 JspException (javax.servlet.jsp.JspException)1 ComponentDefinition (org.apache.struts.tiles.ComponentDefinition)1 DefinitionsFactoryConfig (org.apache.struts.tiles.DefinitionsFactoryConfig)1 NoSuchDefinitionException (org.apache.struts.tiles.NoSuchDefinitionException)1 TilesRequestProcessor (org.apache.struts.tiles.TilesRequestProcessor)1 XmlDefinitionsSet (org.apache.struts.tiles.xmlDefinition.XmlDefinitionsSet)1 XmlParser (org.apache.struts.tiles.xmlDefinition.XmlParser)1 OrderedPathMatchingResourcePatternResolver (org.jaffa.util.OrderedPathMatchingResourcePatternResolver)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1