1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.peaseplate.chunk;
21
22 import java.io.IOException;
23 import java.io.Writer;
24
25 import org.peaseplate.TemplateException;
26 import org.peaseplate.internal.BuildContext;
27 import org.peaseplate.locator.TemplateLocator;
28
29
30
31
32
33
34 public abstract class AbstractBlock extends AbstractChunk implements BlockHead {
35
36 private Chunk[] block = null;
37
38 public AbstractBlock(TemplateLocator locator, int line, int column) {
39 super(locator, line, column);
40 }
41
42
43
44
45 public Chunk[] getBlock() {
46 return block;
47 }
48
49
50
51
52 public void setBlock(Chunk[] block) throws IllegalStateException {
53 if ((this.block != null) && (block != null) && (this.block != block))
54 throw new IllegalStateException("Block has already block");
55
56 this.block = block;
57 }
58
59
60
61
62 public void renderBlock(BuildContext context, Writer writer) throws TemplateException, IOException {
63 for (Chunk chunk : getBlock())
64 chunk.render(context, writer);
65 }
66
67
68
69
70 @Override
71 public String toString() {
72 StringBuilder builder = new StringBuilder("{\n");
73
74 if (getBlock() != null)
75 for (Chunk chunk : getBlock())
76 builder.append("\t").append(
77 chunk.toString().replace("\n", "\n\t")
78 ).append("\n");
79
80 builder.append("}");
81
82 return builder.toString();
83 }
84
85 }