Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.ResourceNotFoundException


     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())
                     {
                         return new
                             BufferedInputStream(rs.getAsciiStream(templateColumn));
                     }
                     else
                     {
                         String msg = "DataSourceResourceLoader Error: cannot find resource "
                             + name;
                         Runtime.error(msg );

                         throw new ResourceNotFoundException (msg);
                     }
                 }
                 finally
                 {
                     rs.close();
                 }
             }
             finally
             {
                 closeDbConnection(conn);
             }
         }
         catch(Exception e)
         {
             String msg =  "DataSourceResourceLoader Error: database problem trying to load resource "
                 + name + ": " + e.toString();

             Runtime.error( msg );

             throw new ResourceNotFoundException (msg);

         }

     }
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

        /*
         * 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

    {
        InputStream results = null;

        if (org.apache.commons.lang.StringUtils.isEmpty(source))
        {
            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);
        }

        return data;
    }
View Full Code Here

    public InputStream getResourceStream(final String name)
            throws ResourceNotFoundException
    {
        if (StringUtils.isEmpty(name))
        {
            throw new ResourceNotFoundException("No template name provided");
        }

        StringResource resource = getRepository().getStringResource(name);
       
        if(resource == null)
        {
            throw new ResourceNotFoundException("Could not locate resource '" + name + "'");
        }
       
        byte [] byteArray = null;
     
        try
View Full Code Here

     public synchronized InputStream getResourceStream(final String name)
         throws ResourceNotFoundException
     {
   if (org.apache.commons.lang.StringUtils.isEmpty(name))
         {
             throw new ResourceNotFoundException ("DataSourceResourceLoader: "
                 + "Template name was empty or null");
         }

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

             if (rs.next())
             {
           InputStream ascStream = rs.getAsciiStream(templateColumn);
           if (ascStream == null)
           {
               throw new ResourceNotFoundException("DataSourceResourceLoader: "
                 + "template column for '" + name + "' is null");
           }

           return new BufferedInputStream(ascStream);
             }
             else
             {
           throw new ResourceNotFoundException("DataSourceResourceLoader: "
         + "could not find resource '" + name + "'");

             }
         }
         catch(SQLException sqle)
         {
             String msg = "DataSourceResourceLoader: database problem while getting resource '"
                     + name + "': ";

       log.error(msg, sqle);
             throw new ResourceNotFoundException(msg);
         }
         catch(NamingException ne)
         {
             String msg = "DataSourceResourceLoader: database problem while getting resource '"
                     + name + "': ";

       log.error(msg, ne);
             throw new ResourceNotFoundException(msg);
         }
         finally
         {
             closeResultSet(rs);
             closeDbConnection(conn);
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

        {
            /*
             *  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

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.