Package org.apache.velocity.runtime

Examples of org.apache.velocity.runtime.RuntimeServices


               ResourceNotFoundException
    {
        /*
         *  get our arguments and check them
         */
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        int argCount = node.jjtGetNumChildren();

        for( int i = 0; i < argCount; i++)
        {
            /*
 
View Full Code Here


    private boolean renderOutput( Node node, InternalContextAdapter context,
                                  Writer writer )
        throws IOException, MethodInvocationException,
               ResourceNotFoundException
    {
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        if ( node == null )
        {
            Logger.error(this,"#include() null argument");
            return false;
        }

        /*
         *  does it have a value?  If you have a null reference, then no.
         */
        Object value = node.value( context );
        if ( value == null)
        {
            Logger.error(this,"#include() null argument");
            return false;
        }

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

        /*
         *  check to see if the argument will be changed by the event handler
         */

        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.
         */
        boolean blockinput = false;
        if (arg == null)
            blockinput = true;

        Resource resource = null;

        try
        {
            if (!blockinput)
                resource = rsvc.getContent(arg, getInputEncoding(context));
        }
        catch ( ResourceNotFoundException rnfe )
        {
            /*
             * the arg wasn't found.  Note it and throw
View Full Code Here

         */
        List<Token> tokens=node.getTokens();
        Token t = tokens.get(tokens.size()-1);
        if (t.image.startsWith(")") || t.image.startsWith("#end"))
        {
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
        }
               
        // Validate that none of the arguments are plain words, (VELOCITY-614)
        // they should be string literals, references, inline maps, or inline lists
        for (int n=0; n < node.jjtGetNumChildren(); n++)
View Full Code Here

        String renderingTemplate = context.getCurrentTemplateName();
       
        /**
         * first look in the source template
         */
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        Object o = rsvc.getVelocimacro(macroName, getTemplateName(), renderingTemplate);

        if( o != null )
        {
            // getVelocimacro can only return a VelocimacroProxy so we don't need the
            // costly instanceof check
            vmProxy = (VelocimacroProxy)o;
        }

        /**
         * if not found, look in the macro libraries.
         */
        if (vmProxy == null)
        {
            List macroLibraries = context.getMacroLibraries();
            if (macroLibraries != null)
            {
                for (int i = macroLibraries.size() - 1; i >= 0; i--)
                {
                    o = rsvc.getVelocimacro(macroName,
                            (String)macroLibraries.get(i), renderingTemplate);

                    // get the first matching macro
                    if (o != null)
                    {
View Full Code Here

     */
    public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
        throws TemplateInitException
    {
        super.init(rs, context, node);
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        // get name of the reference that refers to AST block passed to block macro call
        key = rsvc.getString(RuntimeConstants.VM_BODY_REFERENCE, "bodyContent");

        // use the macro max depth for bodyContent max depth as well
        maxDepth = rs.getInt(RuntimeConstants.VM_MAX_DEPTH);

        macro = new RuntimeMacro(name);
View Full Code Here

    public boolean render(InternalContextAdapter context, Writer writer,
                          Node node, Renderable body)
            throws IOException, MethodInvocationException, MacroOverflowException
    {
        // wrap the current context and add the macro arguments
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        // the creation of this context is a major bottleneck (incl 2x HashMap)
        final ProxyVMContext vmc = new ProxyVMContext(context, rsvc, localContextScope);

        int callArguments = node.jjtGetNumChildren();
View Full Code Here

    /**
     * Initialize members of VelocimacroProxy.  called from MacroEntry
     */
    public void init(RuntimeServices rs)
    {
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        // this is a very expensive call (ExtendedProperties is very slow)
        strictArguments = rs.getConfiguration().getBoolean(
            RuntimeConstants.VM_ARGUMENTS_STRICT, false);

        // support for local context scope feature, where all references are local
        // we do not have to check this at every invocation of ProxyVMContext
        localContextScope = rsvc.getBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, false);
        if (localContextScope && Logger.isWarnEnabled(this.getClass()))
        {
            // only warn once per runtime, so this isn't obnoxious
            String key = "velocimacro.context.localscope.warning";
            Boolean alreadyWarned = (Boolean)rsvc.getApplicationAttribute(key);
            if (alreadyWarned == null)
            {
                rsvc.setApplicationAttribute(key, Boolean.TRUE);
                Logger
                .warn(this,"The "+RuntimeConstants.VM_CONTEXT_LOCALSCOPE+
                      " feature is deprecated and will be removed in Velocity 2.0."+
                      " Instead, please use the $macro scope to store references"+
                      " that must be local to your macros (e.g. "+
                      "#set( $macro.foo = 'bar' ) and $macro.foo).  This $macro"+
                      " namespace is automatically created and destroyed for you at"+
                      " the beginning and end of the macro rendering.");
            }
        }

        // get the macro call depth limit
        maxCallDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);

        // get name of the reference that refers to AST block passed to block macro call
        bodyReference = rsvc.getString(RuntimeConstants.VM_BODY_REFERENCE, "bodyContent");
    }
View Full Code Here

     */
    public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
        throws TemplateInitException
    {
        super.init(rs, context, node);
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();

        this.maxDepth = rsvc.getInt(RuntimeConstants.PARSE_DIRECTIVE_MAXDEPTH, 10);
    }
View Full Code Here

        /*
         *  does it have a value?  If you have a null reference, then no.
         */
        Object value =  node.jjtGetChild(0).value( context );
        RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
        if (value == null && Logger.isDebugEnabled(this.getClass()))
        {
            Logger.debug(this,"#parse(): null argument at " +
                    VelocityException.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] );
                }
                Logger.error(this,"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
View Full Code Here

        {
            return current.getEncoding();
        }
        else
        {
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.velocity.runtime.RuntimeServices

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.