1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
package org.webmacro.directive; |
24 | |
|
25 | |
import org.webmacro.Context; |
26 | |
import org.webmacro.FastWriter; |
27 | |
import org.webmacro.PropertyException; |
28 | |
import org.webmacro.TemplateVisitor; |
29 | |
import org.webmacro.engine.BuildContext; |
30 | |
import org.webmacro.engine.BuildException; |
31 | |
import org.webmacro.engine.MacroDefinition; |
32 | |
|
33 | |
import java.io.IOException; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public class MacroDirective extends Directive |
42 | |
{ |
43 | |
|
44 | |
private static final int MACRO_NAME = 1; |
45 | |
private static final int MACRO_ARGS = 2; |
46 | |
private static final int MACRO_BODY = 3; |
47 | |
|
48 | |
private static final ArgDescriptor[] |
49 | 2 | myArgs = new ArgDescriptor[]{ |
50 | |
new NameArg(MACRO_NAME), |
51 | |
new FormalArgListArg(MACRO_ARGS), |
52 | |
new BlockArg(MACRO_BODY) |
53 | |
}; |
54 | |
|
55 | |
private static final DirectiveDescriptor |
56 | 2 | myDescr = new DirectiveDescriptor(null, null, myArgs, null); |
57 | |
|
58 | |
public static DirectiveDescriptor getDescriptor () |
59 | |
{ |
60 | 6 | return myDescr; |
61 | |
} |
62 | |
|
63 | |
public MacroDirective () |
64 | 0 | { |
65 | 0 | } |
66 | |
|
67 | |
public Object build (DirectiveBuilder builder, |
68 | |
BuildContext bc) |
69 | |
throws BuildException |
70 | |
{ |
71 | 0 | String name = (String) builder.getArg(MACRO_NAME, bc); |
72 | 0 | Object[] args = (Object[]) builder.getArg(MACRO_ARGS, bc); |
73 | 0 | String[] argNames = new String[args.length]; |
74 | 0 | for (int i = 0; i < args.length; i++) |
75 | 0 | argNames[i] = (String) args[i]; |
76 | 0 | Object body = builder.getArg(MACRO_BODY); |
77 | 0 | MacroDefinition macro = new MacroDefinition(name, argNames, body); |
78 | 0 | bc.putMacro(name, macro); |
79 | 0 | return null; |
80 | |
} |
81 | |
|
82 | |
public void write (FastWriter out, Context context) |
83 | |
throws PropertyException, IOException |
84 | |
{ |
85 | 0 | } |
86 | |
|
87 | |
public void accept (TemplateVisitor v) |
88 | |
{ |
89 | 0 | } |
90 | |
|
91 | |
} |