SmapUtilpublic class SmapUtil extends Object Contains static utilities for generating SMAP data based on the
current version of Jasper. |
Fields Summary |
---|
private org.apache.juli.logging.Log | log | public static final String | SMAP_ENCODING |
Methods Summary |
---|
public static void | evaluateNodes(Node.Nodes nodes, SmapStratum s, java.util.HashMap innerClassMap, boolean breakAtLF)
try {
nodes.visit(new SmapGenVisitor(s, breakAtLF, innerClassMap));
} catch (JasperException ex) {
}
| public static java.lang.String[] | generateSmap(org.apache.jasper.JspCompilationContext ctxt, Node.Nodes pageNodes)Generates an appropriate SMAP representing the current compilation
context. (JSR-045.)
//*********************************************************************
// Public entry points
// Scan the nodes for presence of Jasper generated inner classes
PreScanVisitor psVisitor = new PreScanVisitor();
try {
pageNodes.visit(psVisitor);
} catch (JasperException ex) {
}
HashMap map = psVisitor.getMap();
// set up our SMAP generator
SmapGenerator g = new SmapGenerator();
/** Disable reading of input SMAP because:
1. There is a bug here: getRealPath() is null if .jsp is in a jar
Bugzilla 14660.
2. Mappings from other sources into .jsp files are not supported.
TODO: fix 1. if 2. is not true.
// determine if we have an input SMAP
String smapPath = inputSmapPath(ctxt.getRealPath(ctxt.getJspFile()));
File inputSmap = new File(smapPath);
if (inputSmap.exists()) {
byte[] embeddedSmap = null;
byte[] subSmap = SDEInstaller.readWhole(inputSmap);
String subSmapString = new String(subSmap, SMAP_ENCODING);
g.addSmap(subSmapString, "JSP");
}
**/
// now, assemble info about our own stratum (JSP) using JspLineMap
SmapStratum s = new SmapStratum("JSP");
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
// Map out Node.Nodes
evaluateNodes(pageNodes, s, map, ctxt.getOptions().getMappedFile());
s.optimizeLineSection();
g.addStratum(s, true);
if (ctxt.getOptions().isSmapDumped()) {
File outSmap = new File(ctxt.getClassFileName() + ".smap");
PrintWriter so =
new PrintWriter(
new OutputStreamWriter(
new FileOutputStream(outSmap),
SMAP_ENCODING));
so.print(g.getString());
so.close();
}
String classFileName = ctxt.getClassFileName();
int innerClassCount = map.size();
String [] smapInfo = new String[2 + innerClassCount*2];
smapInfo[0] = classFileName;
smapInfo[1] = g.getString();
int count = 2;
Iterator iter = map.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
String innerClass = (String) entry.getKey();
s = (SmapStratum) entry.getValue();
s.optimizeLineSection();
g = new SmapGenerator();
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
g.addStratum(s, true);
String innerClassFileName =
classFileName.substring(0, classFileName.indexOf(".class")) +
'$" + innerClass + ".class";
if (ctxt.getOptions().isSmapDumped()) {
File outSmap = new File(innerClassFileName + ".smap");
PrintWriter so =
new PrintWriter(
new OutputStreamWriter(
new FileOutputStream(outSmap),
SMAP_ENCODING));
so.print(g.getString());
so.close();
}
smapInfo[count] = innerClassFileName;
smapInfo[count+1] = g.getString();
count += 2;
}
return smapInfo;
| private static java.lang.String | inputSmapPath(java.lang.String path)Returns a file path corresponding to a potential SMAP input
for the given compilation input (JSP file).
return path.substring(0, path.lastIndexOf('.") + 1) + "smap";
| public static void | installSmap(java.lang.String[] smap)
if (smap == null) {
return;
}
for (int i = 0; i < smap.length; i += 2) {
File outServlet = new File(smap[i]);
SDEInstaller.install(outServlet, smap[i+1].getBytes());
}
| private static java.lang.String | unqualify(java.lang.String path)Returns an unqualified version of the given file path.
path = path.replace('\\", '/");
return path.substring(path.lastIndexOf('/") + 1);
|
|