Package org.apache.velocity.exception

Examples of org.apache.velocity.exception.VelocityException


        catch( Exception e )
        {
            String msg = "ASTMethod.execute() : exception invoking method '"
                         + methodName + "' in " + o.getClass();
            log.error(msg, e);
            throw new VelocityException(msg, e);
        }
    }
View Full Code Here


            }
            catch(Exception e)
            {
                String msg = "Exception while looking for get('" + property + "') method";
                log.error(msg, e);
                throw new VelocityException(msg, e);
            }
        }
    }
View Full Code Here

            }
            catch(Exception e)
            {
                String msg = "Exception while looking for put('" + property + "') method";
                log.error(msg, e);
                throw new VelocityException(msg, e);
            }
        }
    }
View Full Code Here

    {
        if (macroBody == null)
        {
            // happens only if someone uses this class without the Macro directive
            // and provides a null value as an argument
            throw new VelocityException("Null AST for "+vmName+" in "+namespace);
        }

        MacroEntry me = new MacroEntry(vmName, macroBody, argArray, namespace, rsvc);

        me.setFromLibrary(registerFromLib);
View Full Code Here

                    /**
                     * At this point we know that an attempt is about to be made
                     * to call a method or property on a null value.
                     */
                    String name = jjtGetChild(i).getFirstToken().image;
                    throw new VelocityException("Attempted to access '" 
                        + name + "' on a null value at "
                        + Log.formatFileString(uberInfo.getTemplateName(),
                        + jjtGetChild(i).getLine(), jjtGetChild(i).getColumn()));                 
                }
                previousResult = result;
View Full Code Here

                {
                  log.error("Prepend the reference with '$!' e.g., $!" + literal().substring(1)
                      + " if you want Velocity to ignore the reference when it evaluates to null");
                  if (value == null)
                  {
                    throw new VelocityException("Reference " + literal()
                        + " evaluated to null when attempting to render at "
                        + Log.formatFileString(this));
                  }
                  else  // toString == null
                  {
                    // This will probably rarely happen, but when it does we want to
                    // inform the user that toString == null so they don't pull there
                    // hair out wondering why Velocity thinks the value is null.                   
                    throw new VelocityException("Reference " + literal()
                        + " evaluated to object " + value.getClass().getName()
                        + " whose toString() method returned null at "
                        + Log.formatFileString(this));
                  }
                }             
View Full Code Here

            {
                return value.toString() != null;
            }
            catch(Exception e)
            {
                throw new VelocityException("Reference evaluation threw an exception at "
                    + Log.formatFileString(this), e);
            }
        }
        else
        {
View Full Code Here

            if (method == null)
            {
                // couldn't find set or put method, so bail
                if (strictRef)
                {
                    throw new VelocityException(
                        "Found neither a 'set' or 'put' method with param types '("
                        + printClass(paramClasses[0]) + "," + printClass(paramClasses[1])
                        + ")' on class '" + result.getClass().getName()
                        + "' at " + Log.formatFileString(astIndex));
                }
                return false;
            }
         
            try
            {
                method.invoke(result, params);
            }
            catch(RuntimeException e)
            {
                // Kludge since invoke throws Exception, pass up Runtimes
                throw e;
            }
            catch(Exception e)
            {
                throw new MethodInvocationException(
                  "Exception calling method '"
                  + methodName + "("
                  + printClass(paramClasses[0]) + "," + printClass(paramClasses[1])
                  + ")' in  " + result.getClass(),
                  e.getCause(), identifier, astIndex.getTemplateName(), astIndex.getLine(),
                    astIndex.getColumn());
            }
           
            return true;
        }
       
       
        /*
         *  We support two ways of setting the value in a #set($ref.foo = $value ) :
         *  1) ref.setFoo( value )
         *  2) ref,put("foo", value ) to parallel the get() map introspection
         */

        try
        {
            VelPropertySet vs =
                    rsvc.getUberspect().getPropertySet(result, identifier,
                            value, uberInfo);

            if (vs == null)
            {
                if (strictRef)
                {
                    throw new MethodInvocationException("Object '" + result.getClass().getName() +
                       "' does not contain property '" + identifier + "'", null, identifier,
                       uberInfo.getTemplateName(), uberInfo.getLine(), uberInfo.getColumn());
                }
                else
                {
                  return false;
                }
            }

            vs.invoke(result, value);
        }
        catch(InvocationTargetException ite)
        {
            /*
             *  this is possible
             */

            throw  new MethodInvocationException(
                "ASTReference : Invocation of method '"
                + identifier + "' in  " + result.getClass()
                + " threw exception "
                + ite.getTargetException().toString(),
               ite.getTargetException(), identifier, getTemplateName(), this.getLine(), this.getColumn());
        }
        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            throw e;
        }
        catch(Exception e)
        {
            /*
             *  maybe a security exception?
             */
            String msg = "ASTReference setValue() : exception : " + e
                          + " template at " + Log.formatFileString(uberInfo);
            log.error(msg, e);
            throw new VelocityException(msg, e);
         }

        return true;
    }
View Full Code Here

        /*
         *  did we get an argument?
         */
        if ( node.jjtGetNumChildren() == 0 )
        {
            throw new VelocityException("#parse(): argument missing at " +
                                        Log.formatFileString(this));
        }

        /*
         *  does it have a value?  If you have a null reference, then no.
         */
        Object value =  node.jjtGetChild(0).value( context );
        if (value == null && rsvc.getLog().isDebugEnabled())
        {
            rsvc.getLog().debug("#parse(): null argument at " +
                                Log.formatFileString(this));
        }

        /*
         *  get the path
         */
        String sourcearg = value == null ? null : value.toString();

        /*
         *  check to see if the argument will be changed by the event cartridge
         */
        String arg = EventHandlerUtil.includeEvent( rsvc, context, sourcearg, context.getCurrentTemplateName(), getName());

        /*
         *   a null return value from the event cartridge indicates we should not
         *   input a resource.
         */
        if (arg == null)
        {
            // abort early, but still consider it a successful rendering
            return true;
        }


        if (maxDepth > 0)
        {
            /*
             * see if we have exceeded the configured depth.
             */
            Object[] templateStack = context.getTemplateNameStack();
            if (templateStack.length >= maxDepth)
            {
                StringBuffer path = new StringBuffer();
                for( int i = 0; i < templateStack.length; ++i)
                {
                    path.append( " > " + templateStack[i] );
                }
                rsvc.getLog().error("Max recursion depth reached (" +
                                    templateStack.length + ')' + " File stack:" +
                                    path);
                return false;
            }
        }

        /*
         *  now use the Runtime resource loader to get the template
         */

        Template t = null;

        try
        {
            t = rsvc.getTemplate( arg, getInputEncoding(context) );
        }
        catch ( ResourceNotFoundException rnfe )
        {
            /*
             * the arg wasn't found.  Note it and throw
             */
            rsvc.getLog().error("#parse(): cannot find template '" + arg +
                                "', called at " + Log.formatFileString(this));
            throw rnfe;
        }
        catch ( ParseErrorException pee )
        {
            /*
             * the arg was found, but didn't parse - syntax error
             *  note it and throw
             */
            rsvc.getLog().error("#parse(): syntax error in #parse()-ed template '"
                                + arg + "', called at " + Log.formatFileString(this));
            throw pee;
        }
        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            rsvc.getLog().error("Exception rendering #parse(" + arg + ") at " +
                                Log.formatFileString(this));
            throw e;
        }
        catch ( Exception e)
        {
            String msg = "Exception rendering #parse(" + arg + ") at " +
                         Log.formatFileString(this);
            rsvc.getLog().error(msg, e);
            throw new VelocityException(msg, e);
        }

        /**
         * Add the template name to the macro libraries list
         */
        List macroLibraries = context.getMacroLibraries();

        /**
         * if macroLibraries are not set create a new one
         */
        if (macroLibraries == null)
        {
            macroLibraries = new ArrayList();
        }

        context.setMacroLibraries(macroLibraries);

        macroLibraries.add(arg);

        /*
         *  and render it
         */
        try
        {
            preRender(context);
            context.pushCurrentTemplateName(arg);

            ((SimpleNode) t.getData()).render(context, writer);
        }
        catch( StopCommand stop )
        {
            if (!stop.isFor(this))
            {
                throw stop;
            }
        }
        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            /**
             * Log #parse errors so the user can track which file called which.
             */
            rsvc.getLog().error("Exception rendering #parse(" + arg + ") at " +
                                Log.formatFileString(this));
            throw e;
        }
        catch ( Exception e )
        {
            String msg = "Exception rendering #parse(" + arg + ") at " +
                         Log.formatFileString(this);
            rsvc.getLog().error(msg, e);
            throw new VelocityException(msg, e);
        }
        finally
        {
            context.popCurrentTemplateName();
            postRender(context);
View Full Code Here

        super.init(rs, context, node);

        // the first child is the block name (key), the second child is the block AST body
        if ( node.jjtGetNumChildren() != 2 )
        {
            throw new VelocityException("parameter missing: block name at "
                 + Log.formatFileString(this));
        }
       
        /*
         * first token is the name of the block. We don't even check the format,
View Full Code Here

TOP

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

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.