01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.om.Item;
05: import net.sf.saxon.trans.XPathException;
06: import net.sf.saxon.value.AtomicValue;
07: import net.sf.saxon.value.StringValue;
08:
09: /**
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()
31: .toUpperCase());
32: case LOWERCASE:
33: return StringValue.makeStringValue(sv.getStringValue()
34: .toLowerCase());
35: default:
36: throw new UnsupportedOperationException("Unknown function");
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: //
|