View Javadoc

1   package net.sf.jstp;
2   
3   import java.util.Map;
4   import java.util.HashMap;
5   
6   public class JstpElement
7   {
8       public static final int TYPE_TEXT        = 0;  // blah
9       public static final int TYPE_EXPRESSION  = 1;  // <%= expr %>
10  
11      public static final int TYPE_COMMENT     = 11;  // <%-- blah --%>
12      public static final int TYPE_DIRECTIVE   = 12;  // <%@ name attr='value' ... %>
13      public static final int TYPE_DECLARATION = 13;  // <%! decl %>
14      public static final int TYPE_SCRIPTLET   = 14;  // <%  stmt %>
15      
16      public int type;
17      public StringBuffer content;
18      //follow 2 only make sense for directive type
19      public String directiveName;
20      public Map directiveAttributes;
21      
22      public int row;
23      public int col;
24  
25      public JstpElement(int type, int row, int col)
26      {
27          this.type = type;
28          if(type==TYPE_DIRECTIVE)
29              this.directiveAttributes = new HashMap();
30          else
31              this.content = new StringBuffer();
32          
33          this.row = row;
34          this.col = col;
35      }
36      
37      public String getTypeStartToken()
38      {
39          switch(type)
40          {
41              case TYPE_TEXT : return "";
42              case TYPE_COMMENT : return "<%--";
43              case TYPE_DIRECTIVE : return "<%@";
44              case TYPE_DECLARATION : return "<%!";
45              case TYPE_EXPRESSION : return "<%=";
46              case TYPE_SCRIPTLET : return "<%";
47              default : throw new Error("assertion fails");
48          }
49      }
50      
51      public JstpElement prev = null;
52      public JstpElement next = null;
53  }