org.apache.sling.servlets.post.impl.helper
Class DateParser

java.lang.Object
  extended by org.apache.sling.servlets.post.impl.helper.DateParser

public class DateParser
extends Object

Takes a string representation of a time-date string and tries for parse it using different formats.


Constructor Summary
DateParser()
           
 
Method Summary
 Calendar parse(String source)
          Parses the given source string and returns the respective calendar instance.
 Calendar[] parse(String[] sources)
          Parses the given source strings and returns the respective calendar instances.
 javax.jcr.Value[] parse(String[] sources, javax.jcr.ValueFactory factory)
          Parses the given source strings and returns the respective jcr date value instances.
 void register(String format)
          Registers a format string to the list of internally checked ones.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateParser

public DateParser()
Method Detail

register

public void register(String format)
Registers a format string to the list of internally checked ones. Uses the SimpleDateFormat.

Parameters:
format - format as in SimpleDateFormat
Throws:
IllegalArgumentException - if the format is not valid.

parse

public Calendar parse(String source)
Parses the given source string and returns the respective calendar instance. If no format matches returns null.

Note: method is synchronized because SimpleDateFormat is not.

Parameters:
source - date time source string
Returns:
calendar representation of the source or null

parse

public Calendar[] parse(String[] sources)
Parses the given source strings and returns the respective calendar instances. If no format matches for any of the sources returns null.

Note: method is synchronized because SimpleDateFormat is not.

Parameters:
sources - date time source strings
Returns:
calendar representations of the source or null

parse

public javax.jcr.Value[] parse(String[] sources,
                               javax.jcr.ValueFactory factory)
Parses the given source strings and returns the respective jcr date value instances. If no format matches for any of the sources returns null.

Note: method is synchronized because SimpleDateFormat is not.

Parameters:
sources - date time source strings
factory - the value factory
Returns:
jcr date value representations of the source or null


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.