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.lang;
21  
22  import org.peaseplate.TemplateEngine;
23  import org.peaseplate.TemplateException;
24  import org.peaseplate.chunk.Chunk;
25  import org.peaseplate.internal.designator.ContentDesignator;
26  import org.peaseplate.internal.model.CompileContext;
27  import org.peaseplate.internal.parser.Token;
28  
29  /**
30   * A designator knows how to compile a code fragment enclosed by
31   * the "${" and "}". It has a keyword which identifies this designator. 
32   * 
33   * Default designators are (among others): "print", "if", "while", "end", "import", "include",...
34   * 
35   * @author Manfred HANTSCHEL
36   */
37  public interface Designator {
38  
39  	/**
40  	 * Returns the keyword of the designator. The keyword
41  	 * must be unique within the {@link TemplateEngine}.
42  	 * The following characters are allowed: any letter,
43  	 * any digit, '.', '_', '-' and '/'.
44  	 * 
45  	 * @return the keyword of the designator, not null
46  	 */
47  	public String getKeyword();
48  	
49  	/**
50  	 * If this method returns true it indicates that the code fragment
51  	 * does not contain code and does not need to get compiled
52  	 * (e.g. ${end}, ${else}, ${break},...).
53  	 * 
54  	 * @return true if empty, false otherwise
55  	 */
56  	public boolean isEmpty();
57  	
58  	/**
59  	 * Returns true if the chunk generated by the designator is visible, 
60  	 * false otherwise. If the chunk can generate visible output,
61  	 * this method returns true. 
62  	 * 
63  	 * A content chunk with only white spaces in it, is by definition
64  	 * not visible. This method cannot compute this, since is does not get
65  	 * the source. Handle {@link ContentDesignator} separately.
66  	 * 
67  	 * @return true if visible, false otherwise 
68  	 */
69  	public boolean isVisible();
70  	
71  	public boolean isBlockHead();
72  	
73  	public boolean isBlockTail();
74  	
75  	public boolean isExpandableBlock();
76  	
77  	public boolean isBlockExpansion();
78  	
79  	public Chunk compile(TemplateEngine engine, CompileContext context, Token token) throws TemplateException;
80  	
81  }