Thanks to Artem and Toby..
Just solved implementing
org.apache.velocity.runtime.resource.loader.ResourceLoader interfaces.
And for security in appengine-web-wml i've added

<resource-files>
        <include path="/**.vm" />
    </resource-files>

Ciao
Vincenzo

package com.vincenzoamoruso.velocity;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.apache.velocity.runtime.resource.Resource;
import org.apache.velocity.runtime.resource.loader.ResourceLoader;

public class velocityResourceLoader extends ResourceLoader {
        @Override
        public long getLastModified(Resource arg0) {
        return arg0.getLastModified();
        }

        @Override
        public InputStream getResourceStream(String arg0)
                        throws ResourceNotFoundException {
                InputStream is=null;
                try {
                        is = new FileInputStream(arg0);
                } catch (FileNotFoundException e) {
                        throw new ResourceNotFoundException(arg0);
                }
                // TODO Auto-generated method stub
                return is;
        }

        @Override
        public void init(ExtendedProperties arg0) {
                // TODO Auto-generated method stub

        }

        @Override
        public boolean isSourceModified(Resource arg0) {
                // TODO Auto-generated method stub
                return false;
        }

}


On 20 Nov, 12:21, ArtemGr <artem...@gmail.com> wrote:
> Google App Engine does not provide a usual file systemaccess.
> You should implement certain Velocity interfaces to load the files via
> classloader.
> I have it working.
>
> On 19 ноя, 22:26, vincwe <vincenzo.amor...@gmail.com> wrote:
>
>
>
> > Hi to all,
> > i'm try to use Apache velocity template for mailing,
> > using the following code
>
> > <code>
> >         VelocityEngine ve = new VelocityEngine();
> >         try {
> >             ve.setProperty("resource.loader", "file");
> >             ve.setProperty
> > ("file.resource.loader.class","org.apache.velocity.runtime.resource.loader.­FileResourceLoader");
> >                 
> > ve.setProperty("file.resource.loader.path","/template/email/");
> >                 ve.setProperty( 
> > RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
> >               "org.apache.velocity.runtime.log.Log4JLogChute" );
>
> >                  ve.setProperty("runtime.log.logsystem.log4j.logger",
> >                  log.getName());
> >                 // ve.setApplicationAttribute
> > ("javax.servlet.ServletContext",this.servlet.getServletContext());
> >                         ve.init();
> >                 } catch (Exception e1) {
> >                         // TODO Auto-generated catch block
> >                     log.warning("EI:"+e1.getMessage());
> >                 }
>
> >                 VelocityContext context = new VelocityContext();
> >         Template template =  null;
>
> >                 try
> >         {
> >                 template = ve.getTemplate("mail1.vm");
>
> >         }
> >        .....
>
> > </code>
>
> > But at runtime gives this exception :
>
> > 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>:
> > [error] ResourceManager.getResource() load exception
> > W 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>:
> >accessdenied(java.io.FilePermission/template/email/mail1.vm read)
> > W 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>:
> > java.security.AccessControlException:accessdenied
> > (java.io.FilePermission/template/email/mail1.vm
> > W 11-19 10:44AM 33.316 [wincheck123/4.337839622240022599].<stderr>: at
> > java.security.AccessControlContext.checkPermission
> > (AccessControlContext.java:355)
> > ..
>
> > Are there some security configuration to set for reading files on
> >appengine? such as security policy or others
>
> > Thank in advance
> > Regards
> > Vincenzo- Nascondi testo citato
>
> - Mostra testo citato -

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=.


Reply via email to