Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using xalan extensions to get the current date and time.

Similar presentations


Presentation on theme: "Using xalan extensions to get the current date and time."— Presentation transcript:

1 Using xalan extensions to get the current date and time.

2 We use this area for alerts like server maintenance.

3 This is an example of an alert message. I want the alert message to no longer show after a given expiration date.

4 I want to compare the expiration date in to the current date. This is an example of the XML used for the alert message. defines whether or not to show the message (a manual on/off switch) is the date and time after which the message should no longer show.

5 Source: http://www.w3schools.com/xpath/xpath_functions.asp XSLT and XPATH Versions 2.0 With XSLT 2.0 and XPATH 2.0, this is how to get the current date and time. WebVoyage uses XSLT 1.0.

6 header.xsl 1.Define the java.util.GregorianCalendar namespace. 2.Import alert.xml and get the expiration date from. 3.Get the current date. 4.Compare the dates. 5.Display alert messages based on the result of the comparison. To get the current date and time, I used xalan extensions. Xalan extensions are installed on your WebVoyage server. 1 2 3 4

7 header.xsl If $display is true and $isExpired is false, display the stylesheet for the alert. $display is based on the tag in the imported XML. $isExpired is true or false depending on whether the current date is greater than or less than the expiration date in the imported XML. A different stylesheet is used based on the id (headerRow or headerRowAlert)

8 header.xsl Again, if $display is true and $isExpired is false, display the alert.

9 header.xsl The part where the xalan extensions comes in is in the getCurrentDate template.

10 header.xsl We define the ‘cal’ namespace to be a xalan extension using the java.util.GregorianCalendar class from the Java API.

11 In the template, create a new cal object

12 java.util.GregorianCalendar[time=1264440457772,areFieldsSet=true,areAllFieldsSet=true,lenient=true, zone=sun.util.calendar.ZoneInfo[id="US/Central",offset=-21600000,dstSavings=3600000,useDaylight=true, transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Central,offset=-21600000,dstSavings=3600000, useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000, startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]], firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2010,MONTH=0,WEEK_OF_YEAR=5,WEEK_OF_MONTH=5, DAY_OF_MONTH=25,DAY_OF_YEAR=25,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=4,AM_PM=0,HOUR=11, HOUR_OF_DAY=11,MINUTE=27,SECOND=37,MILLISECOND=772,ZONE_OFFSET=-21600000,DST_OFFSET=0] public static final int YEAR 1 public static final int MONTH 2 public static final int DAY_OF_MONTH 5 public static final int HOUR 11 public static final int MINUTE 12 public static final int SECOND 13 http://java.sun.com/j2se/1.5.0/docs/api/constant-values.html#java.util.Calendar If we print the new object, we get a long string of information. We’re interested in the current year, month, day, hour, minute, second. But the constants didn’t work in XSLT. So I had to look up the constant values.

13 CONSTANT field values Defined in java.util.CALENDAR CONSTANT field values Defined in java.util.CALENDAR Using the constant values, I defined variables for the current year, month, day, hour, minute, and second.

14 The template returns date/time formatted as 2010-01-25 11:27:37 With my variables, I created a string to represent the date. I formatted the string so the template could be re-used.

15 header.xsl 1.Get the current date using the xalan extension and getCurrentDate template. 2.Get the expiration date from the imported XML. 3.Remove punctuation from both variables with translate(). 4.Turn them into numbers with number(). 5.Compare the numbers (20100201153112 > 20100125112737). 6.The result of the comparison (true/false) is put in the $isExpired variable. 2 1 3 4 5

16 The Apache Xalan Project http://xalan.apache.org/index.html Xalan Java Extensions http://xml.apache.org/xalan-j/extensions.html Extensions Library http://xml.apache.org/xalan-j/extensionslib.html Java 2 Platform API http://java.sun.com/j2se/1.5.0/docs/api/


Download ppt "Using xalan extensions to get the current date and time."

Similar presentations


Ads by Google