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.internal.chunk;
21  
22  import java.io.IOException;
23  import java.io.Writer;
24  
25  import org.peaseplate.TemplateException;
26  import org.peaseplate.chunk.AbstractBlock;
27  import org.peaseplate.internal.BuildContext;
28  import org.peaseplate.locator.TemplateLocator;
29  
30  public final class MacroBlock extends AbstractBlock {
31  
32  	private final String qualifiedName;
33  	private final String[] parameters;
34  	
35  	public MacroBlock(TemplateLocator locator, int line, int column, String qualifiedName, String[] parameters) {
36  	    super(locator, line, column);
37  	    
38  	    this.qualifiedName = qualifiedName;
39  	    this.parameters = parameters;
40      }
41  
42  	public String getQualifiedName() {
43  		return qualifiedName;
44  	}
45  
46  	public String[] getParameters() {
47      	return parameters;
48      }
49  
50  	/**
51  	 * @see org.peaseplate.chunk.Chunk#isVisible()
52  	 */
53  	public boolean isVisible() {
54  	    return false;
55      }
56  
57  	/**
58  	 * @see org.peaseplate.chunk.Chunk#isEssential()
59  	 */
60  	public boolean isEssential() {
61  	    return true;
62      }
63  
64  	/**
65  	 * @see org.peaseplate.chunk.Chunk#render(BuildContext, java.io.Writer)
66  	 */
67  	public void render(BuildContext context, Writer writer) throws TemplateException, IOException {
68  		// intentionally left blank
69      }
70  	
71  	/**
72  	 * @see java.lang.Object#toString()
73  	 */
74  	@Override
75      public String toString() {
76  		StringBuilder builder = new StringBuilder("MacroBlock(");
77  		
78  		builder.append(getLine()).append(":").append(getColumn());
79  		builder.append(") [").append(getQualifiedName());
80  		
81  		if (parameters != null) {
82  			builder.append("(");
83  
84  			for (int i=0; i<parameters.length; i+=1) 
85  				builder.append((i > 0) ? ", " : "").append(parameters[i]);
86  			
87  			builder.append(")");
88  		}
89  		
90  		builder.append("] ");
91  		builder.append(super.toString());
92  		
93  		return builder.toString();
94      }
95  	
96  }