velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "joe" <jose.arraz...@cgi.com>
Subject Re: Bug in nested #parse()
Date Mon, 23 Aug 2004 17:29:32 GMT
Just trying to understand this further for my benefit...In my testing I
found the ResourceNotFoundException is thrown because while parsing out of
the resource properties file some how it searches for blank keys.  I
modified the method getString(String bundleName, Locale locale, String key)
to get rid of the ResourceNotFoundException.  This however, doesn't seem the
right way of handling this since I guess a blank key could be a valid key???
On the other hand, if the parser ignores the rest of the keys after the
ResourceNotFoundException but these are still processed and
populated/display the .vm page then how does this affect the intake service
validating against keys which may not exist (when submitted)...Does this
patch address this? Or am I way off on this one?

Thanks
Below is what I did in order to handle the ResourceNotFoundException in my
app.

public class TurbineLocalizationService
    extends TurbineBaseService
    implements LocalizationService
...
 public String getString(String bundleName, Locale locale, String key)
    {
      // My modification...in order to silently swallow parsing exceptions
when (for some reason) a null is searched for
      // out of the Resource.properties resources file.
      if (key == null || key == "")
      {
        return null;
      }
        String value = null;

        if (locale == null)
        {
            locale = getLocale((String) null);
        }

        // Look for text in requested bundle.
        ResourceBundle rb = getBundle(bundleName, locale);
        value = getStringOrNull(rb, key);
    // rest of code omitted
   ...
"Will Glass-Husain" <wglass@forio.com> wrote in message
news:006601c4815b$414e8b10$6500a8c0@Apollo...
> There's a patch in Bugzilla that might help, if you are up for recompiling
> Velocity.
>
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=28388
>
> This defines a new type of event handler "IncludeEventHandler".  This
allows
> you, the developer, to define a class (implementing IncludeEventHandler)
> which will be called every time a #parse or #include is evaluated.  The
> purpose of your event handler would be to check if the template exists and
> set an error flag for the calling code if not.
>
> WILL
>
>
> ----- Original Message ----- 
> From: "Ford, Peter" <Peter.Ford@travelocity.com>
> To: "Velocity Users List" <velocity-user@jakarta.apache.org>
> Sent: Friday, August 13, 2004 5:53 AM
> Subject: RE: Bug in nested #parse()
>
>
> Yes, I saw that the log captures the error - but that doesn't fix the
> problem. With the exception not reaching the calling code, it assumes
> everything is ok when it isn't; as a result, the partially-processed
output
> is used as if everything was good.
>
> --Pete
>
> > -----Original Message-----
> > From: Kishore Senji [mailto:ksenji@gmail.com]
> > Sent: Thursday, August 12, 2004 4:02 PM
> > To: Velocity Users List
> > Subject: Re: Bug in nested #parse()
> >
> >
> > On Thu, 12 Aug 2004 10:41:32 -0500, Ford, Peter
> > <peter.ford@travelocity.com> wrote:
> > > There seems to be a problem in Velocity in which exceptions
> > thrown during processing of nested #parse() calls do not get
> > passed to the calling code. It is very simple to reproduce -
> > just compile the following and set up a couple of test files.
> > >
> > > Test program source:
> > >
> > > public class Test
> > > {
> > >    public static void main(String[] args)
> > >    {
> > >        try
> > >        {
> > >            String resource = args[0];
> > >            VelocityContext context = new
> > VelocityContext(new Properties());
> > >            context.put("firstName", "Pete");
> > >            VelocityEngine ve = new VelocityEngine();
> > >            Properties velCfg = new Properties();
> > >            ve.init(velCfg);
> > >            Writer w = new StringWriter();
> > >            ve.mergeTemplate(resource, context, w);
> > >            System.out.println(w.toString());
> > >        }
> > >        catch (Exception e)
> > >        {
> > >            e.printStackTrace();
> > >        }
> > >    }
> > > }
> > >
> > > test file 1 ("basic.txt"):
> > >
> > > #parse( "no-such-file.txt" )
> > >
> > > test file 2 ("wrapper.txt"):
> > >
> > > #parse( "basic.txt" )
> > >
> > > Now run the program using "basic.txt" as the argument;
> > you'll see an exception thrown because the engine can't find
> > "no-such-file.txt". So far so good.
> > >
> > > Run it again using "wrapper.txt" as the argument; this time
> > no exception is thrown. The mergeTemplate() call returns to
> > the caller as if nothing is wrong.
> > >
> >
> > If you look in to the Velocity.log, it does throw an
> > ResourceNotFoundException and ignores what ever comes in the template
> > after that exception.
> >
> > Thanks,
> > Kishore Senji
> >
> > > This is causing me serious headaches and I have to find a
> > solution or workround. Is this a known bug? Does anyone know of a fix?
> > >
> > > I'm running on RedHat 9. Velocity 1.3.1 and 1.4 both behave
> > the same way.
> > >
> > > --Pete
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > velocity-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message