commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@yahoo.com>
Subject RE: [jxpath] Using JXPATH for dates
Date Tue, 15 Jan 2008 20:49:43 GMT
Way to jump to the front of a 600-email queue.  I
actually intended for any prodding to take place on
the mail list.  And two might have been a little
extreme, for your education in dealing with volunteer
fora in the future.  That notwithstanding...

Quite simply, you are making an unfounded assumption: 
that JXPath has some intrinsic knowledge of how to
handle dates.  It doesn't.  None whatever.  In my
opinion the easiest way to use JXPath to compare
java.util.Date objects would be to compare their
"time" properties, i.e. invoking getTime() behind the
scenes, which as a long CAN be compared by JXPath.

-Matt

--- "Desai, Jasmina" <jdesai@qualcomm.com> wrote:

> Hi Matt,
> 
> Basically I have hundreds of java objects in memory
> and I need to filter
> out those objects using JXPATH.
> 
> One of the objects has "private Date
> enteredMarketDate;"
> (java.util.Date).
> 
> When I have an xpath sentence like
> /wirelessDevices[marketData/enteredMarketDate >=
> xs:date:("2008-01-01")
> and marketData/enteredMarketDate <=
> xs:date:("2008-01-14") ]
> 
> Or
> 
> /wirelessDevices[marketData/enteredMarketDate >=
> "2008-01-01" and
> marketData/enteredMarketDate <= "2008-01-14" ]
> 
> I get an Invalid xpath error.
> 
> It basically cannot convert string to date and then
> filter the objects.
> How do I convert the string to java.util.date to
> make the actual jxpath
> query?
> 
> 
> 
> Thanks
> Regards,
> Jasmina
>  
> Programmer Analyst, Sr
> Direct: (858) 651-1132
> Ext:     11132
> 
> -----Original Message-----
> From: Desai, Jasmina 
> Sent: Monday, January 14, 2008 2:57 PM
> To: 'Matt Benson'
> Subject: RE: [jxpath] Using JXPATH for dates
> 
> Hi Matt,
> 
> Thanks for the reply.
> 
> Basically my code generates a xpath sentence as
> follows (forget about
> how it generates)
> 
> /wirelessDevices[marketData/enteredMarketDate >=
> xs:date:("2008-01-01")
> and marketData/enteredMarketDate <=
> xs:date:("2008-01-14") ]
> 
> Here "wirelessDevices" is the main object which has
> an instance of
> "marketData" object which in turn has a property
> "Date
> enteredMarketDate".
> 
> Basically this date comes form the client side where
> the user selects a
> date range from the calendar (just like any other
> web application).
> 
> So what I do is, get these dates and generate an
> xpath sentence and
> execute it to get the results back from the
> database.
> 
> In all other cases like String, Boolean, Numbers
> etc, a similar kind of
> xpath sentence works perfectly fine.
> 
> For e.g.: The sentence below works and gets me the
> appropriate results
> back:
> 
>
/wirelessDevices[marketData/operators/address/countryType/regionType/id=
> '10']
> 
> Here the id (10) is a number and hence the sentence
> gets executed
> easily. But when I try to use a date it throws an
> Invalid XPATH error.
> 
> I hope this explains you my problem. 
> 
> Thanks
> Regards,
> Jasmina
> 
> Thanks
> Regards,
> Jasmina
>  
> Programmer Analyst, Sr
> Direct: (858) 651-1132
> Ext:     11132
> 
> -----Original Message-----
> From: Matt Benson [mailto:gudnabrsam@yahoo.com] 
> Sent: Monday, January 14, 2008 2:43 PM
> To: Jakarta Commons Users List
> Subject: Re: [jxpath] Using JXPATH for dates
> 
> Hi,
>   To be quite honest I'm not sure where the "xs:"
> portions of your example, and question, are coming
> from.  Maybe if you provide a little more basic
> detail
> to describe how you got to the point you're at with
> JXPath, the list could be of more help.
> 
> -Matt
> 
> --- "Desai, Jasmina" <jdesai@qualcomm.com> wrote:
> 
> > I am using JXPATH to build a java expression which
> > can be used to get
> > records from a table if its columns fall between a
> > specific date range.
> > 
> > Basically I have a client application which asks
> the
> > end user to enter a
> > date range.
> > 
> > The application needs to get the results which
> fall
> > between the
> > specified date range.
> > 
> >  
> > 
> > I have something like this for the lower value of
> > the date range:
> > 
> >  
> > 
> > if (criterion.getValue() instanceof Date) {
> > 
> >                   SimpleDateFormat dateFormat =
> new
> > SimpleDateFormat("yyyy-MM-dd"); // TODO
> 01-DEC-2007
> > i.e. dd-MM-yyyy
> > 
> >                   valueAsJXPath = "xs:date:('" +
> > dateFormat.format(((Date) criterion.getValue())) +
> > ")'";  //DOES NOT
> > WORK
> > 
> >             }
> > 
> >  
> > 
> > Here the "Date" is of type java.util.Date.
> > 
> >  
> > 
> > Then I have the following for the upper value:
> > 
> >  
> > 
> > if (criterion.getUpperValue() instanceof Date) {
> > 
> >                         SimpleDateFormat
> dateFormat
> > = new
> > SimpleDateFormat("yyyy-MM-dd");
> > 
> >                         upperValueAsJXPath =
> > "xs:date:('" +
> > dateFormat.format(((Date)
> > criterion.getUpperValue())) + ")'"; 
> > 
> >                   }
> > 
> >  
> > 
> >  
> > 
> > The xpath sentence that gets created is something
> > like 
> > 
> >  
> > 
> > marketData/enteredMarketDate >=
> > xs:date:('2008-01-01)' and
> > marketData/enteredMarketDate <=
> > xs:date:('2008-01-15)'
> > 
> >  
> > 
> > But I get an error which says:
> > 
> >  
> > 
> > An Exception has occured:
> > org.apache.commons.jxpath.JXPathException:
> > Invalid XPath:
> > '/wirelessDevices[marketData/enteredMarketDate >=
> > xs:date:(\'2008-01-01)\' and
> > marketData/enteredMarketDate <=
> > xs:date:(\'2008-01-15)\' ]'. Syntax error after:
> > '/wirelessDevices[marketData/enteredMarketDate >=
> > xs:d' at
> >
>
org.apache.commons.jxpath.ri.Parser.parseExpression(Parser.java:60)
> > at
> >
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.compileExpressio
> > n(JXPathContextReferenceImpl.java:218) at
> >
>
org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.iterate(JXPathCo
> > ntextReferenceImpl.java:384)
> > 
> >  
> > 
> >  
> > 
> > I am a first time user of JXPATH. Kindly help me
> > with this error.
> > 
> >  
> > 
> > Also, I need to use the date as 01-DEC-2007 i.e.
> > dd-MM-yyyy instead of
> > yyyy-MM-dd.
> > 
> > Will the xs:date accept the date in dd-MM-yyyy
> > format?
> > 
> >  
> > 
> > Thanks
> > 
> > Regards,
> > Jasmina
> > 
> >  
> > 
> > Programmer Analyst, Sr
> > 
> > Direct: (858) 651-1132
> > 
> > Ext:     11132
> > 
> >  
> > 
> > 
> 
> 
> 
>  
>
________________________________________________________________________
> ____________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now.
>
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@commons.apache.org
> For additional commands, e-mail:
> user-help@commons.apache.org
> 
> 



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

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


Mime
View raw message