01: // Copyright (c) 2004 Per M.A. Bothner
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.xml;
05:
06: import gnu.mapping.*;
07: import gnu.lists.*;
08: import gnu.xml.TextUtils;
09:
10: public class MakeCDATA extends MethodProc // NodeConstructor
11: {
12: public static final MakeCDATA makeCDATA = new MakeCDATA();
13:
14: public void apply(CallContext ctx) {
15: Consumer saved = ctx.consumer;
16: XConsumer out = NodeConstructor.pushNodeContext(ctx);
17: try {
18: StringBuffer sbuf = new StringBuffer();
19: Object endMarker = Location.UNBOUND;
20: for (;;) {
21: Object arg = ctx.getNextArg(endMarker);
22: if (arg == endMarker)
23: break;
24: TextUtils.stringValue(arg, sbuf);
25: }
26: int n = sbuf.length();
27: char[] chars = new char[n];
28: sbuf.getChars(0, n, chars, 0);
29: out.writeCDATA(chars, 0, n);
30: } finally {
31: NodeConstructor.popNodeContext(saved, ctx);
32: }
33: }
34:
35: /*
36: public void compileToNode (ApplyExp exp, Compilation comp,
37: ConsumerTarget target)
38: {
39: Variable consumer = target.getConsumerVariable();
40: Expression[] args = exp.getArgs();
41: int nargs = args.length;
42: CodeAttr code = comp.getCode();
43: for (int i = 0; i < nargs; i++)
44: // FIXME needs to coerce to string value.
45: compileChild(args[i], comp, target);
46: }
47: */
48: }
|