subsys/groovy/src/main/java/org/commonjava/indy/subsys/template/TemplatingEngine.java
private Template getTemplate( final String acceptHeader, final String templateKey )
        throws IndyGroovyException
    {
        final String accept = ( acceptHeader == null ? "" : acceptHeader.replace( '/', '_' ) + "/" );
        try
        {
            final String filename = accept + templateKey + ".groovy";
            final DataFile templateFile = manager.getDataFile( TEMPLATES, filename );
            logger.info( "Looking for template: {} for ACCEPT header: {} in: {}", templateKey, acceptHeader,
                         templateFile );

            Template template;
            if ( templateFile.exists() && !templateFile.isDirectory() )
            {
                template = engine.createTemplate( templateFile.readString() );
            }
            else
            {
                final String urlpath = TEMPLATES + "/" + accept + templateKey + ".groovy";
                logger.info( "Looking for template: {} for ACCEPT header: {} in: {}", templateKey, acceptHeader,
                             urlpath );

                final URL u = Thread.currentThread()
                                    .getContextClassLoader()
                                    .getResource( urlpath );

                template = u == null ? null : engine.createTemplate( u );
            }

            if ( template == null )
            {
                throw new IndyGroovyException( "Failed to locate template: %s (with ACCEPT header: %s)", templateKey,
                                                acceptHeader );
            }

            return template;
        }
        catch ( final CompilationFailedException e )
        {
            throw new IndyGroovyException( "Failed to compile template: %s. Reason: %s", e, templateKey, e.getMessage() );
        }
        catch ( final ClassNotFoundException e )
        {
            throw new IndyGroovyException( "Failed to compile template: %s. Reason: %s", e, templateKey, e.getMessage() );
        }
        catch ( final IOException e )
        {
            throw new IndyGroovyException( "Failed to read template: %s. Reason: %s", e, templateKey, e.getMessage() );
        }
    }
private Template getTemplate( final String acceptHeader, final String templateKey )
        throws IndyGroovyException
    {
        final String accept = ( acceptHeader == null ? "" : acceptHeader.replace( '/', '_' ) + "/" );
        try
        {
            final String filename = accept + templateKey + ".groovy";
            final DataFile templateFile = manager.getDataFile( TEMPLATES, filename );
            logger.info( "Looking for template: {} for ACCEPT header: {} in: {}", templateKey, acceptHeader,
                         templateFile );

            Template template;
            if ( templateFile.exists() && !templateFile.isDirectory() )
            {
                template = engine.createTemplate( templateFile.readString() );
            }
            else
            {
                final String urlpath = TEMPLATES + "/" + accept + templateKey + ".groovy";
                logger.info( "Looking for template: {} for ACCEPT header: {} in: {}", templateKey, acceptHeader,
                             urlpath );

                final URL u = Thread.currentThread()
                                    .getContextClassLoader()
                                    .getResource( urlpath );

                template = u == null ? null : engine.createTemplate( u );
            }

            if ( template == null )
            {
                throw new IndyGroovyException( "Failed to locate template: %s (with ACCEPT header: %s)", templateKey,
                                                acceptHeader );
            }

            return template;
        }
        catch ( final CompilationFailedException e )
        {
            throw new IndyGroovyException( "Failed to compile template: %s. Reason: %s", e, templateKey, e.getMessage() );
        }
        catch ( final ClassNotFoundException e )
        {
            throw new IndyGroovyException( "Failed to compile template: %s. Reason: %s", e, templateKey, e.getMessage() );
        }
        catch ( final IOException e )
        {
            throw new IndyGroovyException( "Failed to read template: %s. Reason: %s", e, templateKey, e.getMessage() );
        }
    }
TODO Cache these...though this will hurt hot-reloading. Perhaps a debug mode configuration?