KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > xml > MakeCDATA


1 // Copyright (c) 2004 Per M.A. Bothner
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.xml;
5 import gnu.mapping.*;
6 import gnu.lists.*;
7 import gnu.xml.TextUtils;
8
9 public class MakeCDATA extends MethodProc // NodeConstructor
10
{
11   public static final MakeCDATA makeCDATA
12     = new MakeCDATA();
13
14   public void apply (CallContext ctx)
15   {
16     Consumer saved = ctx.consumer;
17     XConsumer out = NodeConstructor.pushNodeContext(ctx);
18     try
19       {
20     StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
21     Object JavaDoc endMarker = Location.UNBOUND;
22     for (;;)
23       {
24         Object JavaDoc arg = ctx.getNextArg(endMarker);
25         if (arg == endMarker)
26           break;
27         TextUtils.stringValue(arg, sbuf);
28       }
29     int n = sbuf.length();
30     char[] chars = new char[n];
31     sbuf.getChars(0, n, chars, 0);
32     out.writeCDATA(chars, 0, n);
33       }
34     finally
35       {
36     NodeConstructor.popNodeContext(saved, ctx);
37       }
38   }
39
40   /*
41   public void compileToNode (ApplyExp exp, Compilation comp,
42                       ConsumerTarget target)
43   {
44     Variable consumer = target.getConsumerVariable();
45     Expression[] args = exp.getArgs();
46     int nargs = args.length;
47     CodeAttr code = comp.getCode();
48     for (int i = 0; i < nargs; i++)
49       // FIXME needs to coerce to string value.
50       compileChild(args[i], comp, target);
51   }
52   */

53 }
54
Popular Tags