SmapUtilpublic class SmapUtil extends Object Contains static utilities for generating SMAP data based on the
current version of Jasper. |
Fields Summary |
---|
private org.apache.jasper.JspCompilationContext | ctxt | private List | classInfos | public static final String | SMAP_ENCODING |
Methods Summary |
---|
private void | evaluateNodes(Node.Nodes nodes, SmapStratum s, boolean breakAtLF)
try {
nodes.visit(new SmapGenVisitor(s, breakAtLF, classInfos));
} catch (JasperException ex) {
}
| public void | generateSmap(Node.Nodes pageNodes)Generates an appropriate SMAP representing the current compilation
context. (JSR-045.)
classInfos = new ArrayList<ClassInfo>();
String className = ctxt.getFullClassName();
// Instantiate a SmapStratum for the main JSP page.
SmapStratum s = new SmapStratum("JSP");
classInfos.add(new ClassInfo(className, s));
// Map out Node.Nodes and putting LineInfo into SmapStratum
evaluateNodes(pageNodes, s, ctxt.getOptions().getMappedFile());
String classFileName = ctxt.getClassFileName();
for (ClassInfo entry: classInfos) {
// Get SmapStratum
s = entry.getSmapStratum();
s.optimizeLineSection();
// Set up our SMAP generator
SmapGenerator g = new SmapGenerator();
g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
g.addStratum(s, true);
String name = entry.getClassName(); // class name
// Compute the class name and output file name for inner classes
if (!className.equals(name)) {
classFileName = ctxt.getOutputDir() +
name.substring(name.lastIndexOf('.")+1) + ".class";
}
entry.setClassFileName(classFileName);
entry.setSmap(g.getString());
if (ctxt.getOptions().isSmapDumped()) {
File outSmap = new File(classFileName + ".smap");
PrintWriter so =
new PrintWriter(
new OutputStreamWriter(
new FileOutputStream(outSmap),
SMAP_ENCODING));
so.print(g.getString());
so.close();
}
}
| public void | installSmap()
for (ClassInfo ci: classInfos) {
String className = ci.getClassName();
byte[] classfile = ctxt.getRuntimeContext().getBytecode(className);
if (classfile == null) {
SDEInstaller.install(new File(ci.getClassFileName()),
ci.getSmap().getBytes());
}
else {
classfile = SDEInstaller.install(classfile,
ci.getSmap().getBytes());
ctxt.getRuntimeContext().setBytecode(className, classfile);
}
}
| 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);
|
|