Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.ResourceNotFoundException


                /*
                 * Return null if we can't find a resource.
                 */
                if (resource.getData() == null)
                {
                    throw new ResourceNotFoundException(
                        "Unable to find resource '" + resourceName + "'");
                }                       

                resource.setLastModified( howOldItWas );
                
View Full Code Here


      assertTrue(ex.getMessage().indexOf("url") != -1);
    }
  }

  public void testCannotResolveTemplateNameResourceNotFoundException() throws Exception {
    testCannotResolveTemplateName(new ResourceNotFoundException(""));
  }
View Full Code Here

        /*
         * Return null if we can't find a resource.
         */
        if (resource.getData() == null)
        {
            throw new ResourceNotFoundException("Unable to find resource '" + resourceName + "'");
        }

        /*
         *  some final cleanup
         */
 
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 = "File resource error : argument " + template +
                " contains .. and may be trying to access " +
                "content outside of template root.  Rejected.";

            log.error("FileResourceLoader : " + msg);

            throw new ResourceNotFoundException ( msg );
        }

        int size = paths.size();
        for (int i = 0; i < size; i++)
        {
            String path = (String) paths.get(i);
            InputStream inputStream = null;

            try
            {
                inputStream = findTemplate(path, template);
            }
            catch (IOException ioe)
            {
                log.error("While loading Template " + template + ": ", ioe);
            }

            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.
         */
         throw new ResourceNotFoundException("FileResourceLoader : cannot find " + template);
    }
View Full Code Here

        {
            /*
             *  is == null, therefore we have some kind of file issue
             */

            errorCondition = new ResourceNotFoundException("Unknown resource error for resource " + name );
            throw errorCondition;
        }
    }
View Full Code Here

    {
        InputStream results = null;

        if ( source == null || source.length() == 0)
        {
            throw new ResourceNotFoundException("Need to have a resource!");
        }
       
        String normalizedPath = StringUtils.normalizePath( source );
       
        if ( normalizedPath == null || normalizedPath.length() == 0 )
        {
            String msg = "JAR resource error : argument " + normalizedPath +
                " contains .. and may be trying to access " +
                "content outside of template root.  Rejected.";
           
            log.error( "JarResourceLoader : " + msg );
           
            throw new ResourceNotFoundException ( msg );
        }
       
        /*
         *  if a / leads off, then just nip that :)
         */
        if ( normalizedPath.startsWith("/") )
        {
            normalizedPath = normalizedPath.substring(1);
        }
   
        if ( entryDirectory.containsKey( normalizedPath ) )
        {
            String jarurl  = (String)entryDirectory.get( normalizedPath );
           
            if ( jarfiles.containsKey( jarurl ) )
            {
                JarHolder holder = (JarHolder)jarfiles.get( jarurl );
                results =  holder.getResource( normalizedPath );
                return results;
            }
        }
       
        throw new ResourceNotFoundException( "JarResourceLoader Error: cannot find resource " +
          source );

    }
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 = "File resource error : argument " + template +
                " contains .. and may be trying to access " +
                "content outside of template root.  Rejected.";

            log.error("FileResourceLoader : " + msg);
     
            throw new ResourceNotFoundException ( msg );
        }

        int size = paths.size();
        for (int i = 0; i < size; i++)
        {
            String path = (String) paths.get(i);
            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.
         */
         throw new ResourceNotFoundException("FileResourceLoader : cannot find " + template);
    }
View Full Code Here

            }
        }
        catch( Exception fnfe )
        {
            log.error("JarHolder: getResource() error", fnfe);
            throw new ResourceNotFoundException( fnfe.getMessage() );
        }
       
        return data;
    }
View Full Code Here

    {
        InputStream result = null;

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

        /**
         * look for resource in thread classloader first (e.g. WEB-INF\lib in
         * a servlet container) then fall back to the system classloader.
         */

        try
        {
            result = ClassUtils.getResourceAsStream( getClass(), name );
        }
        catch( Exception fnfe )
        {
            throw (ResourceNotFoundException) ExceptionUtils.createWithCause(ResourceNotFoundException.class, "problem with template: " + name, fnfe );
        }

        if (result == null)
        {
             String msg = "ClasspathResourceLoader Error: cannot find resource " +
              name;

             throw new ResourceNotFoundException( msg );
        }

        return result;
    }
View Full Code Here

     public synchronized InputStream getResourceStream(String name)
         throws ResourceNotFoundException
     {
         if (name == null || name.length() == 0)
         {
             throw new ResourceNotFoundException ("Need to specify a template name!");
         }

         try
         {
             Connection conn = openDbConnection();

             try
             {
                 ResultSet rs = readData(conn, templateColumn, name);

                 try
                 {
                     if (rs.next())
                     {
                         InputStream ascStream = rs.getAsciiStream(templateColumn);
                         if (ascStream != null)
                         {
                             return new BufferedInputStream(ascStream);
                         }
                         else
                         {
                             String msg = "DataSourceResourceLoader : cannot find resource "
                                 + name;
                             log.error(msg);

                             throw new ResourceNotFoundException(msg);
                        }
                     }
                     else
                     {
                         String msg = "DataSourceResourceLoader : cannot find resource "
                             + name;
                         log.error(msg);

                         throw new ResourceNotFoundException(msg);
                     }
                 }
                 finally
                 {
                     rs.close();
                 }
             }
             finally
             {
                 closeDbConnection(conn);
             }
         }
         // IOException, SQLException
         catch(Exception e)
         {
             String msg = "DataSourceResourceLoader : database problem trying to load resource "
                          + name;
             log.error(msg, e);

             throw new ResourceNotFoundException(msg);
         }
     }
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.