Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1c2918787146f9f7f85ae749e5cddec81e45e24a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<%@jet package="org.eclipse.jet.internal.compiler.templates" 
               class="JET2JavaGenerator" 
               imports="org.eclipse.jet.internal.compiler.* org.eclipse.jet.compiler.* org.eclipse.jet.internal.JavaUtil org.eclipse.jet.taglib.TagLibraryReference java.util.Iterator"
               %>
<%
	JET2CompilationUnit cu = (JET2CompilationUnit)argument;
	
	final StringBuffer declarations = new StringBuffer();
	cu.accept(new DefaultJET2ASTVisitor() {
		public void visit(JET2Declaration declaration) { 
			declarations.append(declaration.getJavaContent());
		}
	}); 
	
	final StringBuffer tagNamespaceVariables = new StringBuffer();
	TagLibraryReference[] tlRefs = cu.getTagLibraryReferences();
	for(int i = 0; i < tlRefs.length; i++ ) {
		;
				tagNamespaceVariables.append("public static final String _jetns_")
					.append(tlRefs[i].getPrefix())
					.append(" = \"")
					.append(tlRefs[i].getTagLibraryId())
					.append("\";")
					.append("//$NON-NLS-1$")
					.append(NL);
		
	}

	final StringBuffer tagDataDeclarations = new StringBuffer();
	cu.accept(new DefaultJET2ASTVisitor() {
		private void writeDecl(XMLElement element) {
			tagDataDeclarations.append("final TagInfo ")
				.append(MethodBodyCreator.tagInfoVariableName(element))
				.append(" = new TagInfo( ")
				.append('"').append(element.getName()).append("\", ")
				.append(element.getLine()).append(", ")
				.append(element.getColumn()).append(", ")
				;
			tagDataDeclarations.append(" new String[] {");
			for (Iterator i = element.getAttributes().keySet().iterator(); i.hasNext();) {
				String attrName = (String) i.next();
				tagDataDeclarations.append('"').append(attrName).append("\", ");
			}
			tagDataDeclarations.append("}, ");
			tagDataDeclarations.append(" new String[] {");
			for (Iterator i = element.getAttributes().values().iterator(); i.hasNext();) {
				String attrValue = (String) i.next();
				tagDataDeclarations.append(JavaUtil.asJavaQuotedString(attrValue.toCharArray())).append(", ");
			}
			tagDataDeclarations.append("});").append(NL);
		}
		
		public void visit(XMLBodyElement element) {
			writeDecl(element);
		}
		
		public void visit(XMLEmptyElement element) {
			writeDecl(element);
		}
	});
	MethodBodyCreator generatedBody = new MethodBodyCreator();
	cu.accept(generatedBody);
%>
package <%= cu.getOutputJavaPackage() %>;

import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.RuntimeTagElement;
import org.eclipse.jet.taglib.TagInfo;
<% for(Iterator i=cu.getImports().iterator();i.hasNext();) { 
	String importName = (String)i.next();%>
import <%=importName%>;
<% } %>

public class <%= cu.getOutputJavaClassName() %> implements JET2Template {

	<%= tagNamespaceVariables %>

	<%= declarations %>
	
	public <%= cu.getOutputJavaClassName() %>() {
		super();
	}

	public void generate(JET2Context context, JET2Writer out) {
		
		<%= tagDataDeclarations %>

		<%= generatedBody.getBuffer() %>
	}

}
               

Back to the top