KickJava   Java API By Example, From Geeks To Geeks.

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


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.om.FastStringBuffer;
5 import net.sf.saxon.trans.XPathException;
6 import net.sf.saxon.value.AtomicValue;
7 import net.sf.saxon.value.SequenceType;
8 import net.sf.saxon.value.StringValue;
9
10
11 public class Concat extends SystemFunction {
12
13     /**
14     * Get the required type of the nth argument
15     */

16
17     protected SequenceType getRequiredType(int arg) {
18         return getDetails().argumentTypes[0];
19         // concat() is a special case
20
}
21
22     /**
23     * Evaluate the function in a string context
24     */

25
26     public String JavaDoc evaluateAsString(XPathContext c) throws XPathException {
27         return evaluateItem(c).getStringValue();
28     }
29
30     /**
31     * Evaluate in a general context
32     */

33
34     public Item evaluateItem(XPathContext c) throws XPathException {
35         int numArgs = argument.length;
36         FastStringBuffer sb = new FastStringBuffer(1024);
37         for (int i=0; i<numArgs; i++) {
38             AtomicValue val = (AtomicValue)argument[i].evaluateItem(c);
39             if (val!=null) {
40                 sb.append(val.getStringValueCS());
41             }
42         }
43         return StringValue.makeStringValue(sb.condense());
44     }
45
46 }
47
48
49
50 //
51
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
52
// you may not use this file except in compliance with the License. You may obtain a copy of the
53
// License at http://www.mozilla.org/MPL/
54
//
55
// Software distributed under the License is distributed on an "AS IS" basis,
56
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
57
// See the License for the specific language governing rights and limitations under the License.
58
//
59
// The Original Code is: all this file.
60
//
61
// The Initial Developer of the Original Code is Michael H. Kay.
62
//
63
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
64
//
65
// Contributor(s): none.
66
//
67
Popular Tags