com.echomine.jabber
Class JabberUtil

java.lang.Object
  extended by com.echomine.jabber.JabberUtil

public class JabberUtil
extends java.lang.Object

This class contains convenience methods to work with the Jabber protocol. These may involve features such as parsing date and time according to JEP-0082 (Date and Time Profile).


Constructor Summary
JabberUtil()
           
 
Method Summary
static java.lang.String formatDateTime(java.util.Calendar cal)
          This formats the date to a string that is compliant with the Jabber dateTime format.
static java.util.Calendar parseDate(java.lang.String date)
          parses the a date string according to JEP-0082.
static java.util.Calendar parseDateTime(java.lang.String dateTime)
          This method parses the date and the time out of the string.
static java.util.Calendar parseTime(java.lang.String time)
          parses the time string according to JEP-0082.
static java.util.TimeZone parseTimeZone(java.lang.String tz)
          Parses the timezone from a given string.
static Element parseXmlStringToDOM(java.lang.String xmlStr)
          parses the XML string into a JDOM dom element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JabberUtil

public JabberUtil()
Method Detail

parseDate

public static java.util.Calendar parseDate(java.lang.String date)
                                    throws ParseException
parses the a date string according to JEP-0082. The date must be in the format of yyyy-MM-dd. The parser should be multi-thread safe since the matcher is instantiated per call. However, the pattern is already compiled so there should be little delay when doing the regex matching. Also, the time should not be considered in the returned date as this method deals specifically with date, not time. Timezone should not matter in this case.

Parameters:
date - the date in the format specified by the JEP.
Returns:
the calendar-based date
Throws:
ParseException - when parsing problems occur

parseTime

public static java.util.Calendar parseTime(java.lang.String time)
                                    throws ParseException
parses the time string according to JEP-0082. The time must be in the format of hh:mm:ss[.sss][TZD]. The fractional seconds are optional and is ignored by the parsing. The timezone can either be the letter Z to denote UTC or can be an offset from UTC (ie. +-08:00). The returned date should not use the date value of the object. Only the time should be used. The timezone is optional and thus if it does not exist, then the current system timezone is assumed.

Parameters:
time - the time string
Returns:
the parsed time
Throws:
ParseException

parseDateTime

public static java.util.Calendar parseDateTime(java.lang.String dateTime)
                                        throws ParseException
This method parses the date and the time out of the string. The format is in the form of yyyy-MM-ddThh:mm:ss[.sss]TZD. This is essentially the combination of the date and time parsing with the exception that the timezone is a required element rather than optional (as in the time parsing).

Parameters:
dateTime - the datetime string to be parsed
Returns:
the calendar object with the date and time set and timezone set
Throws:
ParseException - when parsing problems occur

formatDateTime

public static java.lang.String formatDateTime(java.util.Calendar cal)
This formats the date to a string that is compliant with the Jabber dateTime format. The timezone used by the date formatter is the timezone specified in the calendar instance.

Parameters:
cal - the calendar instance to convert into a string
Returns:
the datetime string representation

parseTimeZone

public static java.util.TimeZone parseTimeZone(java.lang.String tz)
Parses the timezone from a given string. The timezone can be null, in which case the UTC timezone is assumed. The timezone can be the string "Z", in which case the UTC timezone will be returned. Any other timezones should be in the format +-hh:mm. If the timezone cannot be recognized, UTC will be returned.

Parameters:
tz - the timezone string, or can be null
Returns:
the timezone instance, or current timezone if null is passed in

parseXmlStringToDOM

public static Element parseXmlStringToDOM(java.lang.String xmlStr)
                                   throws java.io.IOException,
                                          JDOMException
parses the XML string into a JDOM dom element. This dom element is reuseable and can be inserted into another dom tree.

Throws:
java.io.IOException
JDOMException


Copyright © 2001-2005 Echomine. All Rights Reserved.