Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.ResourceNotFoundException


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


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

            throws ResourceNotFoundException {
       
        log.debug("Looking up resource named ... "+name);
       
        if (name == null || name.length() == 0) {
            throw new ResourceNotFoundException("No template name provided");
        }
       
        InputStream result = null;
       
        try {
            if(!name.startsWith("/"))
                name = "/WEB-INF/velocity/" + name;
           
            result = this.mContext.getResourceAsStream(name);
           
        } catch(Exception e) {
            throw new ResourceNotFoundException(e.getMessage());
        }
       
        if(result == null) {
            throw new ResourceNotFoundException("Couldn't find "+name);
        }
       
        return result;
    }
View Full Code Here

            throws ResourceNotFoundException {
       
        log.debug("Looking up resource named ... "+name);
       
        if (name == null || name.length() == 0) {
            throw new ResourceNotFoundException("No template name provided");
        }
       
        InputStream result = null;
       
        try {
            if(!name.startsWith("/"))
                name = templateDir + "/" + name;
            else {
                name = templateDir + name;
            }
           
            result = new FileInputStream(name);
           
        } catch(Exception e) {
            throw new ResourceNotFoundException(e.getMessage());
        }
       
        if(result == null) {
            throw new ResourceNotFoundException("Couldn't find "+name);
        }
       
        return result;
    }
View Full Code Here

            throws ResourceNotFoundException {
       
        log.debug("Looking up resource named ... "+name);
       
        if (name == null || name.length() == 0) {
            throw new ResourceNotFoundException("No template name provided");
        }
       
        InputStream result = null;
       
        try {
            if(!name.startsWith("/"))
                name = "/WEB-INF/velocity/" + name;
           
            result = this.mContext.getResourceAsStream(name);
           
        } catch(Exception e) {
            throw new ResourceNotFoundException(e.getMessage());
        }
       
        if(result == null) {
            throw new ResourceNotFoundException("Couldn't find "+name);
        }
       
        return result;
    }
View Full Code Here

        throws ResourceNotFoundException {
       
        mLogger.debug("Looking up resource named ... "+name);
       
        if (name == null || name.length() < 1) {
            throw new ResourceNotFoundException("Need to specify a template name!");
        }
       
        try {
            // parse the name ... theme templates name are <theme>:<template>
            String[] split = name.split(":", 2);
            if(split.length < 2)
                throw new ResourceNotFoundException("Invalid ThemeRL key "+name);
           
            // lookup the template from the proper theme
            ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
            Theme theme = themeMgr.getTheme(split[0]);
            ThemeTemplate template = theme.getTemplateByName(split[1]);
           
            if(template == null)
                throw new ResourceNotFoundException("Template ["+split[1]+
                        "] doesn't seem to be part of theme ["+split[0]+"]");
           
            mLogger.debug("Resource found!");
           
            // return the input stream
            return new ByteArrayInputStream(template.getContents().getBytes("UTF-8"));
           
        } catch (UnsupportedEncodingException uex) {
            // We expect UTF-8 in all JRE installation.
            // This rethrows as a Runtime exception after logging.
            mLogger.error(uex);
            throw new RuntimeException(uex);
          
        } catch (ThemeNotFoundException tnfe) {
            String msg = "ThemeResourceLoader Error: " + tnfe.getMessage();
            mLogger.error(msg, tnfe);
            throw new ResourceNotFoundException(msg);
           
        } catch (WebloggerException re) {
            String msg = "RollerResourceLoader Error: " + re.getMessage();
            mLogger.error( msg, re );
            throw new ResourceNotFoundException(msg);
        }
    }
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().getWeblogManager().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

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

        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 ( template == null )
        {
            String msg = "Velocity.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

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.