1 17 18 package org.apache.jasper.compiler; 19 20 import java.util.List ; 21 import java.util.ArrayList ; 22 23 30 public class SmapGenerator { 31 32 35 43 44 45 48 private String outputFileName; 49 private String defaultStratum = "Java"; 50 private List strata = new ArrayList (); 51 private List embedded = new ArrayList (); 52 private boolean doEmbedded = true; 53 54 57 61 public synchronized void setOutputFileName(String x) { 62 outputFileName = x; 63 } 64 65 77 public synchronized void addStratum(SmapStratum stratum, 78 boolean defaultStratum) { 79 strata.add(stratum); 80 if (defaultStratum) 81 this.defaultStratum = stratum.getStratumName(); 82 } 83 84 91 public synchronized void addSmap(String smap, String stratumName) { 92 embedded.add("*O " + stratumName + "\n" 93 + smap 94 + "*C " + stratumName + "\n"); 95 } 96 97 103 public void setDoEmbedded(boolean status) { 104 doEmbedded = status; 105 } 106 107 110 public synchronized String getString() { 111 if (outputFileName == null) 113 throw new IllegalStateException (); 114 StringBuffer out = new StringBuffer (); 115 116 out.append("SMAP\n"); 118 out.append(outputFileName + '\n'); 119 out.append(defaultStratum + '\n'); 120 121 if (doEmbedded) { 123 int nEmbedded = embedded.size(); 124 for (int i = 0; i < nEmbedded; i++) { 125 out.append(embedded.get(i)); 126 } 127 } 128 129 int nStrata = strata.size(); 131 for (int i = 0; i < nStrata; i++) { 132 SmapStratum s = (SmapStratum) strata.get(i); 133 out.append(s.getString()); 134 } 135 136 out.append("*E\n"); 138 139 return out.toString(); 140 } 141 142 public String toString() { return getString(); } 143 144 147 public static void main(String args[]) { 148 SmapGenerator g = new SmapGenerator(); 149 g.setOutputFileName("foo.java"); 150 SmapStratum s = new SmapStratum("JSP"); 151 s.addFile("foo.jsp"); 152 s.addFile("bar.jsp", "/foo/foo/bar.jsp"); 153 s.addLineData(1, "foo.jsp", 1, 1, 1); 154 s.addLineData(2, "foo.jsp", 1, 6, 1); 155 s.addLineData(3, "foo.jsp", 2, 10, 5); 156 s.addLineData(20, "bar.jsp", 1, 30, 1); 157 g.addStratum(s, true); 158 System.out.print(g); 159 160 System.out.println("---"); 161 162 SmapGenerator embedded = new SmapGenerator(); 163 embedded.setOutputFileName("blargh.tier2"); 164 s = new SmapStratum("Tier2"); 165 s.addFile("1.tier2"); 166 s.addLineData(1, "1.tier2", 1, 1, 1); 167 embedded.addStratum(s, true); 168 g.addSmap(embedded.toString(), "JSP"); 169 System.out.println(g); 170 } 171 } 172 | Popular Tags |