Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.ResourceNotFoundException


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

        InputStream inputStream = null;
        Exception exception = null;
        for(int i=0; i < roots.length; i++)
        {
            try
            {
                URL u = new URL(roots[i] + name);
                inputStream = u.openStream();

                if (inputStream != null)
                {
                    if (log.isDebugEnabled()) log.debug("URLResourceLoader: Found '"+name+"' at '"+roots[i]+"'");

                    // save this root for later re-use
                    templateRoots.put(name, roots[i]);
                    break;
                }
            }
            catch(IOException ioe)
            {
                if (log.isDebugEnabled()) log.debug("URLResourceLoader: Exception when looking for '"+name+"' at '"+roots[i]+"'", ioe);

                // only save the first one for later throwing
                if (exception == null)
                {
                    exception = ioe;
                }
            }
        }

        // if we never found the template
        if (inputStream == null)
        {
            String msg;
            if (exception == null)
            {
                msg = "URLResourceLoader : Resource '" + name + "' not found.";
            }
            else
            {
                msg = exception.getMessage();
            }
            // convert to a general Velocity ResourceNotFoundException
            throw new ResourceNotFoundException(msg);
        }

        return inputStream;
    }
View Full Code Here


        stream = loadFromThisClassLoader(name);
        if (stream != null) {
            return stream;
        }

        throw new ResourceNotFoundException("Couldn't find resource '"
                + name
                + "'. Searched filesystem path and classpath");
    }
View Full Code Here

            getLog().debug( "File " + outputFilename + " created..." );
        }

        catch ( ResourceNotFoundException e )
        {
            throw new ResourceNotFoundException( "Template not found: " + templateDirectory + "/" + template, e );
        }
        catch ( VelocityException e )
        {
            throw e; // to get past generic catch for Exception.
        }
View Full Code Here

    {
        InputStream result = null;
       
        if (name == null || name.length() == 0)
        {
            throw new ResourceNotFoundException ("No template name provided");
        }
       
        String value = null;
        HashMap<String, String> resources = resourcesTL.get();
        if( resources!=null ) {
          value = resources.get(name);
        }
       
      if( value == null ) {
        result = this.fileResourceLoader.getResourceStream(name);
      } else {
            try
            {
              result = new ByteArrayInputStream(value.getBytes());
            }
            catch( Exception e )
            {
                throw new ResourceNotFoundException( e.getMessage() );
            }
      }
        return result;
    }
View Full Code Here

        stream = loadFromThisClassLoader(name);
        if (stream != null) {
            return stream;
        }

        throw new ResourceNotFoundException("Couldn't find resource '"
                + name
                + "'. Searched filesystem path and classpath");
    }
View Full Code Here

                return (file.canRead()) ? new BufferedInputStream(new FileInputStream(
                        file.getAbsolutePath())) : null;

            }
            catch (FileNotFoundException fnfe) {
                throw new ResourceNotFoundException(
                        "AbsFileResourceLoader Error: cannot find resource " + name);
            }
        }
    }
View Full Code Here

        if ( template == null )
        {
            String msg = "VelocityEngine.mergeTemplate() was unable to load template '"
                           + templateName + "'";
            getLog().error(msg);
            throw new ResourceNotFoundException(msg);
        }
        else
        {
            template.merge(context, writer);
            return true;
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)
            {
                String msg = "Exception while loading Template " + template;
                log.error(msg, ioe);
                throw new VelocityException(msg, 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

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

        StringResource resource = this.repository.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;
        PreparedStatement ps = null;
        try
        {
            conn = openDbConnection();
            ps = getStatement(conn, templateColumn, name);
            rs = ps.executeQuery();

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

                return new BufferedInputStream(stream);
            }
            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);
            closeStatement(ps);
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.