View Javadoc

1   /*
2    * This file is part of Pease Plate Template Engine.
3    * 
4    * Pease Plate Template Engine is free software: you can redistribute
5    * it and/or modify it under the terms of the GNU Lesser General 
6    * Public License as published by the Free Software Foundation, 
7    * either version 3 of the License, or any later version.
8    * 
9    * Pease Plate Template Engine is distributed in the hope that it 
10   * will be useful, but WITHOUT ANY WARRANTY; without even the implied
11   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12   * See the GNU Lesser General Public License for more details.
13   * 
14   * You should have received a copy of the GNU Lesser General Public 
15   * License along with Pease Plate Template Engine. If not, see 
16   * <http://www.gnu.org/licenses/>.
17   * 
18   * Copyright (c) 2008 Manfred HANTSCHEL
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   * A chunk is a piece of a compiled template.
32   * 
33   * @author Manfred HANTSCHEL
34   */
35  public interface Chunk {
36  
37  	/**
38  	 * Returns the template locator of the template this chunk belongs to
39  	 * @return the template locator
40  	 */
41  	public TemplateLocator getLocator();
42  	
43  	/**
44  	 * Returns the line where this chunk is located in the source of the template.
45  	 * @return the line
46  	 */
47  	public int getLine();
48  	
49  	/**
50  	 * Returns the column where this chunk is located in the source of the template.
51  	 * @return the column
52  	 */
53  	public int getColumn();
54  	
55  	/**
56  	 * Returns true if the chunk is visible, false otherwise.
57  	 * A content chunk with only white spaces in it, is by definition
58  	 * not visible and not essential. It only gets essential
59  	 * if it's the only thing in the line.
60  	 * 
61  	 * @return true if visible, false otherwise 
62  	 */
63  	public boolean isVisible();
64  
65  	/**
66  	 * Returns true if the chunk is essential, false otherwise.
67  	 * A code chunk is by default essential, a content chunk not
68  	 * if it contains just spaces.
69  	 * 
70  	 * @return true if essential, false otherwise
71  	 */
72  	public boolean isEssential();
73  	
74  	/**
75  	 * Renders the chunk to the specified writer using the specified template context.
76  	 * @param context the context
77  	 * @param writer the writer
78  	 * @throws TemplateException on occasion
79  	 * @throws IOException on occasion
80  	 */
81  	public void render(BuildContext context, Writer writer) throws TemplateException, IOException;
82  	
83  	/**
84  	 * Returns a meaningful representation of this chunk
85  	 * @return a meaningful representation of this chunk
86  	 */
87  	public String toString();
88  	
89  }