KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > Adjust


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.expr.Expression;
4 import net.sf.saxon.expr.StaticContext;
5 import net.sf.saxon.om.Item;
6 import net.sf.saxon.trans.XPathException;
7 import net.sf.saxon.value.AtomicValue;
8 import net.sf.saxon.value.CalendarValue;
9 import net.sf.saxon.value.SecondsDurationValue;
10
11 /**
12 * This class implements the XPath 2.0 functions
13  * adjust-date-to-timezone(), adjust-time-timezone(), and adjust-dateTime-timezone().
14 */

15
16
17 public class Adjust extends SystemFunction {
18
19     int implicitTimezone;
20
21     /**
22     * Simplify and validate.
23     */

24
25     public Expression simplify(StaticContext env) throws XPathException {
26         implicitTimezone = env.getConfiguration().getImplicitTimezone();
27         return super.simplify(env);
28     }
29
30     /**
31     * Evaluate in a general context
32     */

33
34     public Item evaluateItem(XPathContext context) throws XPathException {
35         AtomicValue av1 = (AtomicValue)argument[0].evaluateItem(context);
36         if (av1==null) {
37             return null;
38         }
39         CalendarValue in = (CalendarValue)av1.getPrimitiveValue();
40
41         int nargs = argument.length;
42         SecondsDurationValue tz;
43         if (nargs==1) {
44             // use the implicit timezone
45
tz = SecondsDurationValue.fromMilliseconds(implicitTimezone * 60000);
46             return in.setTimezone(tz);
47         } else {
48             AtomicValue av2 = (AtomicValue)argument[1].evaluateItem(context);
49             if (av2==null) {
50                 return in.removeTimezone();
51             }
52             tz = (SecondsDurationValue)av2.getPrimitiveValue();
53             return in.setTimezone(tz);
54         }
55     }
56
57 }
58
59
60
61
62 //
63
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
64
// you may not use this file except in compliance with the License. You may obtain a copy of the
65
// License at http://www.mozilla.org/MPL/
66
//
67
// Software distributed under the License is distributed on an "AS IS" basis,
68
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
69
// See the License for the specific language governing rights and limitations under the License.
70
//
71
// The Original Code is: all this file.
72
//
73
// The Initial Developer of the Original Code is Michael H. Kay.
74
//
75
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
76
//
77
// Contributor(s): none.
78
//
79
Popular Tags