Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.ResourceNotFoundException


    public static FactoryConfiguration load(String path)
    {
        FactoryConfiguration config = find(path);
        if (config == null)
        {
            throw new ResourceNotFoundException("Could not find configuration at "+path);
        }
        return config;
    }
View Full Code Here


     */
    public InputStream getResourceStream(String name)
            throws ResourceNotFoundException {
       
        if (name == null || name.length() == 0) {
            throw new ResourceNotFoundException("Need to specify a template name!");
        }
       
        try {
            WeblogTemplate page =
                    WebloggerFactory.getWeblogger().getUserManager().getPage(name);
           
            if (page == null) {
                throw new ResourceNotFoundException(
                        "RollerResourceLoader: page \"" +
                        name + "\" not found");
            }
            return new ByteArrayInputStream( page.getContents().getBytes("UTF-8") );
        } catch (UnsupportedEncodingException uex) {
            // This should never actually happen.  We expect UTF-8 in all JRE installation.
            // This rethrows as a Runtime exception after logging.
            mLogger.error(uex);
            throw new RuntimeException(uex);
        } catch (WebloggerException re) {
            String msg = "RollerResourceLoader Error: " +
                    "database problem trying to load resource " + name;
            mLogger.error( msg, re );
            throw new ResourceNotFoundException(msg);
        }
    }
View Full Code Here

        expect(generator.getDirectoryName(directory, packageName, suite, parameters)).andReturn("mydir");
        File mydir = new File(directory, "mydir");
        expect(generator.getFilename(mydir , packageName, suite, parameters)).andReturn("myfile.txt");
        String sampleVmPath = "/sample.vm";
        expect(generator.getTemplatePath(mydir, packageName, suite, parameters)).andReturn(sampleVmPath);
        expect(velocityEngine.getTemplate("/sample.vm")).andThrow(new ResourceNotFoundException("hello"));

        replay(velocityEngine, generator, suite, template, parameters);
        generator.generate(directory, packageName, suite, parameters);
        verify(velocityEngine, generator, suite, template, parameters);
    }
View Full Code Here

        expect(generator.getDirectoryName(directory, packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn("mydir");
        File mydir = new File(directory, "mydir");
        expect(generator.getFilename(mydir , packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn("myfile.txt");
        String sampleVmPath = "/sample.vm";
        expect(generator.getTemplatePath(mydir, packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn(sampleVmPath);
        expect(velocityEngine.getTemplate("/sample.vm")).andThrow(new ResourceNotFoundException("hello"));

        replay(velocityEngine, generator, suite, clazz, template, parameters);
        generator.generate(directory, packageName, suite, clazz, parameters, runtimeClass, requestClass);
        verify(velocityEngine, generator, suite, clazz, template, parameters);
    }
View Full Code Here

     */
    public synchronized InputStream getResourceStream( String name )
        throws ResourceNotFoundException {

        if (name == null || name.length() == 0) {
            throw new ResourceNotFoundException ("No template name provided");
        }
       
        try {
            if (!name.startsWith("/")) {
                name = "/" + name;
            }

            return servletContext.getResourceAsStream(name);
        }
        catch(Exception fnfe){

            /*
             *  log and convert to a general Velocity ResourceNotFoundException
             */
           
            throw new ResourceNotFoundException(fnfe.getMessage());
        }
    }
View Full Code Here

   * @param fn
   * @return the velocity template
   * @throws Exception
   */
  private Template getTemplate(String[] path, String fn) throws Exception {
    ResourceNotFoundException rnfe = null;

    for (String p : path) {
      if (p == null)
        continue;

      // System.out.println( "trying to load template "+(p+fn) );
      try {
        if (Velocity.resourceExists(p + fn))
          return Velocity.getTemplate(p + fn);
      } catch (ResourceNotFoundException e) {
        rnfe = e;
      } catch (Exception e) {
        System.out.println("ignoring " + e);
      }
    }

    if (rnfe != null)
      throw rnfe;

    throw new ResourceNotFoundException("could not find resource: " + fn);
  }
View Full Code Here

*/
public class StrutsResourceLoader extends ClasspathResourceLoader {

    public synchronized InputStream getResourceStream(String name) throws ResourceNotFoundException {
        if ((name == null) || (name.length() == 0)) {
            throw new ResourceNotFoundException("No template name provided");
        }

        if (name.startsWith("/")) {
            name = name.substring(1);
        }

        try {
            return ClassLoaderUtil.getResourceAsStream(name, StrutsResourceLoader.class);
        } catch (Exception e) {
            throw new ResourceNotFoundException(e.getMessage());
        }
    }
View Full Code Here

    public InputStream getResourceStream(String template) throws ResourceNotFoundException {
        try {
            return pt.opensoft.io.ResourceLoader.getResourceStream(template);
        } catch (pt.opensoft.io.ResourceNotFoundException e) {
            throw new ResourceNotFoundException(e.getMessage());
        }
    }
View Full Code Here

            /*
             * If we don't get a properly formed templateName then
             * there's not much we can do. So we'll forget about
             * trying to search any more paths for the template.
             */
            throw new ResourceNotFoundException( "Need to specify a file name or file path!" );
        }

        String template = StringUtils.normalizePath( templateName );
        if ( template == null || template.length() == 0 )
        {
            String msg = "Project Resource loader error : argument " + template
                + " contains .. and may be trying to access " + "content outside of template root.  Rejected.";

            rsvc.getLog().error( "ProjectResourceLoader : " + msg );

            throw new ResourceNotFoundException( msg );
        }

        /*
         *  if a / leads off, then just nip that :)
         */
        if ( template.startsWith( "/" ) )
        {
            template = template.substring( 1 );
        }
       
        // MCHANGES-118 adding the basedir path
        paths.add( (String) rsvc.getApplicationAttribute( "baseDirectory" ) );

        for ( String path : paths )
        {
            InputStream inputStream = findTemplate( path, template );

            if ( inputStream != null )
            {
                /*
                 * Store the path that this template came
                 * from so that we can check its modification
                 * time.
                 */

                templatePaths.put( templateName, path );
                return inputStream;
            }
        }

        /*
         * We have now searched all the paths for
         * templates and we didn't find anything so
         * throw an exception.
         */
        String msg = "ProjectResourceLoader Error: cannot find resource " + template;

        throw new ResourceNotFoundException( msg );
    }
View Full Code Here

            getLog().info( "Created template " + f );
        }

        catch ( ResourceNotFoundException rnfe )
        {
            throw new ResourceNotFoundException( "Template not found. ( " + templateDirectory + "/" + template + " )" );
        }
        catch ( VelocityException ve )
        {
            throw new VelocityException( ve.toString() );
        }
View Full Code Here

TOP

Related Classes of org.apache.velocity.exception.ResourceNotFoundException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.