Package org.apache.velocity.runtime.resource

Examples of org.apache.velocity.runtime.resource.Resource


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

    Resource resource = null;

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

      rsvc.error("#include(): cannot find resource '" + arg
          + "', called from template "
          + context.getCurrentTemplateName() + " at (" + getLine()
          + ", " + getColumn() + ")");
      throw rnfe;
    }

    catch (Exception e) {
      rsvc.error("#include(): arg = '" + arg + "', called from template "
          + context.getCurrentTemplateName() + " at (" + getLine()
          + ", " + getColumn() + ") : " + e);
    }

    if (resource == null)
      return false;

    writer.write((String) resource.getData());
    return true;
  }
View Full Code Here


         */
        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
             */
            rsvc.getLog().error("#include(): cannot find resource '" + arg +
                                "', called at " + Log.formatFileString(this));
            throw rnfe;
        }

        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            rsvc.getLog().error("#include(): arg = '" + arg +
                                "', called at " + Log.formatFileString(this));
            throw e;
        }
        catch (Exception e)
        {
            String msg = "#include(): arg = '" + arg +
                        "', called at " + Log.formatFileString(this);
            rsvc.getLog().error(msg, e);
            throw new VelocityException(msg, e);
        }


        /*
         *    note - a blocked input is still a successful operation as this is
         *    expected behavior.
         */

        if ( blockinput )
            return true;

        else if ( resource == null )
            return false;

        writer.write((String)resource.getData());
        return true;
    }
View Full Code Here

         */
        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
             */
            rsvc.getLog().error("#include(): cannot find resource '" + arg +
                                "', called from template " +
                                context.getCurrentTemplateName() + " at (" +
                                getLine() + ", " + getColumn() + ")" );
            throw rnfe;
        }

        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            throw e;
        }
        catch (Exception e)
        {
            String msg = "#include(): arg = '" + arg +
                        "', called from template " +
                        context.getCurrentTemplateName() + " at (" +
                        getLine() + ", " + getColumn() + ')';
            rsvc.getLog().error(msg, e);
            throw new VelocityException(msg, e);
        }


        /*
         *    note - a blocked input is still a successful operation as this is
         *    expected behavior.
         */

        if ( blockinput )
            return true;

        else if ( resource == null )
            return false;

        writer.write((String)resource.getData());
        return true;
    }
View Full Code Here

     * from.
     * @return The encoding to use when processing this directive.    
     */
    protected String getInputEncoding(InternalContextAdapter context)
    {
        Resource current = context.getCurrentResource();
        if (current != null)
        {
            return current.getEncoding();
        }
        else
        {
            return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
        }
View Full Code Here

         */
        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
             */
            Logger.error(this,"#include(): cannot find resource '" + arg +
                                "', called at " + VelocityException.formatFileString(this));
            throw rnfe;
        }

        /**
         * pass through application level runtime exceptions
         */
        catch( RuntimeException e )
        {
            Logger.error(this,"#include(): arg = '" + arg +
                                "', called at " + VelocityException.formatFileString(this));
            throw e;
        }
        catch (Exception e)
        {
            String msg = "#include(): arg = '" + arg +
                        "', called at " + VelocityException.formatFileString(this);
            Logger.error(this,msg, e);
            throw new VelocityException(msg, e);
        }


        /*
         *    note - a blocked input is still a successful operation as this is
         *    expected behavior.
         */

        if ( blockinput )
            return true;

        else if ( resource == null )
            return false;

        writer.write((String)resource.getData());
        return true;
    }
View Full Code Here

     * from.
     * @return The encoding to use when processing this directive.
     */
    protected String getInputEncoding(InternalContextAdapter context)
    {
        Resource current = context.getCurrentResource();
        if (current != null)
        {
            return current.getEncoding();
        }
        else
        {
            RuntimeServices rsvc=VelocityUtil.getEngine().getRuntimeServices();
            return (String) rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
View Full Code Here

    @Override
    protected Resource loadResource(String resourceName, int resourceType, String encoding)
        throws ResourceNotFoundException, ParseErrorException, Exception
    {
        // create a blank new resource
        Resource resource = ResourceFactory.getResource(resourceName, resourceType);
        resource.setRuntimeServices(rsvc);
        resource.setName(resourceName);
        resource.setEncoding(encoding);

        resource.setResourceLoader(_contextLoader);
        resource.process();
        resource.setLastModified(_contextLoader.getLastModified(resource));
        resource.setModificationCheckInterval(_contextLoader.getModificationCheckInterval());
        resource.touch();

        return resource;
    }
View Full Code Here

        throws ResourceNotFoundException, ParseErrorException, Exception
    {
        SiteKey skey = new SiteKey(resourceName);

        // create a blank new resource
        Resource resource = ResourceFactory.getResource(skey.path, resourceType);
        resource.setRuntimeServices(rsvc);
        resource.setEncoding(encoding);

        // first try loading it via the site-specific resource loader
        try {
            resource.setName(resourceName);
            resolveResource(resource, _siteLoader);
        } catch (ResourceNotFoundException rnfe) {
            // nothing to worry about here
        }

        // then try the servlet context loader if we didn't find a site-specific resource
        if (resource.getData() == null) {
            resource.setName(skey.path);
            resolveResource(resource, _contextLoader);
        }

        return resource;
    }
View Full Code Here

        }

        // inherit the current encoding if there is a current template,
        // otherwise use the configured encoding
        String encoding = null;
        Resource current = context.getCurrentResource();
        if (current != null) {
            encoding = current.getEncoding();
        } else {
            encoding = (String)
                rsvc.getProperty(RuntimeConstants.INPUT_ENCODING);
        }
View Full Code Here

TOP

Related Classes of org.apache.velocity.runtime.resource.Resource

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.