KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.Item;
4 import net.sf.saxon.trans.XPathException;
5 import net.sf.saxon.value.AtomicValue;
6 import net.sf.saxon.value.StringValue;
7
8
9 /**
10 * This class implements the upper-case() and lower-case() functions
11 */

12
13 public class ForceCase extends SystemFunction {
14
15     public static final int UPPERCASE = 0;
16     public static final int LOWERCASE = 1;
17
18     /**
19     * Evaluate in a general context
20     */

21
22     public Item evaluateItem(XPathContext c) throws XPathException {
23         AtomicValue sv = (AtomicValue)argument[0].evaluateItem(c);
24         if (sv==null) {
25             return StringValue.EMPTY_STRING;
26         }
27
28         switch(operation) {
29             case UPPERCASE:
30                 return StringValue.makeStringValue(sv.getStringValue().toUpperCase());
31             case LOWERCASE:
32                 return StringValue.makeStringValue(sv.getStringValue().toLowerCase());
33             default:
34                 throw new UnsupportedOperationException JavaDoc("Unknown function");
35         }
36     }
37
38 }
39
40
41
42 //
43
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
44
// you may not use this file except in compliance with the License. You may obtain a copy of the
45
// License at http://www.mozilla.org/MPL/
46
//
47
// Software distributed under the License is distributed on an "AS IS" basis,
48
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
49
// See the License for the specific language governing rights and limitations under the License.
50
//
51
// The Original Code is: all this file.
52
//
53
// The Initial Developer of the Original Code is Michael H. Kay.
54
//
55
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
56
//
57
// Contributor(s): none.
58
//
59
Popular Tags