Examples of RuntimeServices


Examples of org.apache.velocity.runtime.RuntimeServices

        /*
         * the normal processing
         *
         * if we have an event cartridge, get a new value object
         */
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        value = EventHandlerUtil.referenceInsert(rsvc, context, literal, value);

        String toString = null;
        if (value != null)
        {         
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

         2) ref,put("foo", value ) to parallel the get() map introspection
         */

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

            if (vs == null)
            {
                if (strictRef)
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

        Object right = jjtGetChild(1).value( context );

        /*
         *  if either is null, lets log and bail
         */
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        if (left == null || right == null)
        {
            String msg = (left == null ? "Left" : "Right")
                           + " side ("
                           + jjtGetChild( (left == null? 0 : 1) ).literal()
                           + ") of '>=' operation has null value at "
                           + VelocityException.formatFileString(this);
           
            if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false))
            {
              throw new VelocityException(msg);
            }
           
            Logger.error(this,msg);
            return false;
        }


        /*
         *  convert to Number if applicable
         */
        if (left instanceof TemplateNumber)
        {
           left = ( (TemplateNumber) left).getAsNumber();
        }
        if (right instanceof TemplateNumber)
        {
           right = ( (TemplateNumber) right).getAsNumber();
        }

        /*
         *  Only compare Numbers
         */

        if ( !( left instanceof Number || !( right instanceof Number ))
        {
            String msg = (!(left instanceof Number) ? "Left" : "Right")
                           + " side of '>=' operation is not a Number at "
                           + VelocityException.formatFileString(this);

            if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false))
            {
              throw new VelocityException(msg);
            }

            Logger.error(this,msg);
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

        /** method is synchronized to avoid concurrent directive initialization **/
       
        if (!isInitialized)
        {
            super.init( context, data );
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            /*
             *  only do things that are not context dependent
             */
   
            if (rsvc.getDirective(directiveName) !=null )
            {
                isDirective = true;
   
                try
                {
                    directive = (Directive) rsvc.getDirective(directiveName)
                        .getClass().newInstance();
                }
                catch (InstantiationException e)
                {
                    throw ExceptionUtils.createRuntimeException("Couldn't initialize " +
                            "directive of class " +
                            rsvc.getDirective(directiveName).getClass().getName(),
                            e);
                }
                catch (IllegalAccessException e)
                {
                    throw ExceptionUtils.createRuntimeException("Couldn't initialize " +
                            "directive of class " +
                            rsvc.getDirective(directiveName).getClass().getName(),
                            e);
                }
                       
                directive.setLocation(getLine(), getColumn(), getTemplateName());
                directive.init(rsvc, context,this);
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

 
    public Object init(InternalContextAdapter context, Object data)
        throws TemplateInitException
    {
        super.init(context, data);
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
        return data;
   
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

         * simple habit... we prollie don't have an AST beneath us
         */

        super.init(context, data);
       
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        /*
         * the stringlit is set at template parse time, so we can do this here
         * for now. if things change and we can somehow create stringlits at
         * runtime, this must move to the runtime execution path
         *
         * so, only if interpolation is turned on AND it starts with a " AND it
         * has a directive or reference, then we can interpolate. Otherwise,
         * don't bother.
         */
        Token ff=tokens.get(0);
        interpolate = rsvc.getBoolean(
                RuntimeConstants.INTERPOLATE_STRINGLITERALS, true)
                && ff.image.startsWith("\"")
                && ((ff.image.indexOf('$') != -1) || (ff.image
                        .indexOf('#') != -1));

        /*
         * get the contents of the string, minus the '/" at each end
         */
        String img = ff.image;
       
        image = img.substring(1, img.length() - 1);
       
        if (img.startsWith("\""))
        {
            image = unescape(image);
        }
        if (img.charAt(0) == '"' || img.charAt(0) == '\'' )
        {
            // replace double-double quotes like "" with a single double quote "
            // replace double single quotes '' with a single quote '
            image = replaceQuotes(image, img.charAt(0));
        }

        /**
         * note. A kludge on a kludge. The first part, Geir calls this the
         * dreaded <MORE> kludge. Basically, the use of the <MORE> token eats
         * the last character of an interpolated string. EXCEPT when a line
         * comment (##) is in the string this isn't an issue.
         *
         * So, to solve this we look for a line comment. If it isn't found we
         * add a space here and remove it later.
         */

        /**
         * Note - this should really use a regexp to look for [^\]## but
         * apparently escaping of line comments isn't working right now anyway.
         */
        containsLineComment = (image.indexOf("##") != -1);

        /*
         * if appropriate, tack a space on the end (dreaded <MORE> kludge)
         */
        String interpolateimage=null;
       
        if (!containsLineComment)
        {
            interpolateimage = image + " ";
        }
        else
        {
            interpolateimage = image;
        }

        if (interpolate)
        {
            /*
             * now parse and init the nodeTree
             */
            StringReader br = new StringReader(interpolateimage);

            /*
             * it's possible to not have an initialization context - or we don't
             * want to trust the caller - so have a fallback value if so
             *
             * Also, do *not* dump the VM namespace for this template
             */

            String templateName =
                (context != null) ? context.getCurrentTemplateName() : "StringLiteral";
            try
            {
                nodeTree = rsvc.parse(br, templateName, false);
            }
            catch (ParseException e)
            {
                String msg = "Failed to parse String literal at "+
                        VelocityException.formatFileString(templateName, getLine(), getColumn());
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

        super.init(context, data);

        identifier = tokens.get(0).image.intern();

        uberInfo = new Info(getTemplateName(), getLine(), getColumn());
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
       
        return data;
    }
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

            {
                /*
                 *  otherwise, do the introspection, and cache it.  Use the
                 *  uberspector
                 */
                RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
                vg = rsvc.getUberspect().getPropertyGet(o,identifier, uberInfo);

                if (vg != null && vg.isCacheable() && (o != null))
                {
                    icd = new IntrospectionCacheData();
                    icd.contextData = o.getClass();
                    icd.thingy = vg;
                    context.icachePut(this,icd);
                }
            }
        }

        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            throw e;
        }
        catch(Exception e)
        {
            String msg = "ASTIdentifier.execute() : identifier = "+identifier;
            Logger.error(this,msg, e);
            throw new VelocityException(msg, e);
        }

        /*
         *  we have no getter... punt...
         */

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

        /*
         *  now try and execute.  If we get a MIE, throw that
         *  as the app wants to get these.  If not, log and punt.
         */
        try
        {
            return vg.invoke(o);
        }
        catch(InvocationTargetException ite)
        {
            /*
             *  if we have an event cartridge, see if it wants to veto
             *  also, let non-Exception Throwables go...
             */

            Throwable t = ite.getTargetException();
            if (t instanceof Exception)
            {
                try
                {
                    RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
                    return EventHandlerUtil.methodException(rsvc, context, o.getClass(), vg.getMethodName(),
                            (Exception) t);
                }

                /**
 
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

        Object right = jjtGetChild(1).value( context );

        /*
         *  if either is null, lets log and bail
         */
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        if (left == null || right == null)
        {
            String msg = (left == null ? "Left" : "Right")
                           + " side ("
                           + jjtGetChild( (left == null? 0 : 1) ).literal()
                           + ") of '<=' operation has null value at "
                           + VelocityException.formatFileString(this);
           
            if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false))
            {
              throw new VelocityException(msg);
            }
           
            Logger.error(this,msg);
            return false;
        }

        /*
         *  convert to Number if applicable
         */
        if (left instanceof TemplateNumber)
        {
           left = ( (TemplateNumber) left).getAsNumber();
        }
        if (right instanceof TemplateNumber)
        {
           right = ( (TemplateNumber) right).getAsNumber();
        }

        /*
         *  Only compare Numbers
         */
        if ( !( left instanceof Number || !( right instanceof Number ))
        {
            String msg = (!(left instanceof Number) ? "Left" : "Right")
                           + " side of '>=' operation is not a Number at "
                           + VelocityException.formatFileString(this);
           
            if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false))
            {
              throw new VelocityException(msg);
            }

            Logger.error(this,msg);
View Full Code Here

Examples of org.apache.velocity.runtime.RuntimeServices

            String msg = (left == null ? "Left" : "Right")
                           + " side ("
                           + jjtGetChild( (left == null? 0 : 1) ).literal()
                           + ") of '>' operation has null value at "
                           + VelocityException.formatFileString(this);
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false))
            {
              throw new VelocityException(msg);
            }

            Logger.error(this,msg);
            return false;
        }

        /*
         *  convert to Number if applicable
         */
        if (left instanceof TemplateNumber)
        {
           left = ( (TemplateNumber) left).getAsNumber();
        }
        if (right instanceof TemplateNumber)
        {
           right = ( (TemplateNumber) right).getAsNumber();
        }

        /*
         *  Only compare Numbers
         */

        if ( !( left instanceof Number || !( right instanceof Number ))
        {
            String msg = (!(left instanceof Number) ? "Left" : "Right")
                           + " side of '>=' operation is not a Number at "
                           + VelocityException.formatFileString(this);
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            if (rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false))
            {
              throw new VelocityException(msg);
            }
           
            Logger.error(this,msg);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.