April 2005
Intermediate to advanced
344 pages
11h 59m
English
Example 6-6 provides the full source code of the DynSqlSelectStmts.java example discussed in this chapter.
Example 6-6. Source code for DynSqlSelectStmts.jav
package net.sourceforge.pmd.rules.web.security; import net.sourceforge.pmd.AbstractRule; import net.sourceforge.pmd.ast.*; import net.sourceforge.pmd.RuleContext; import org.apache.regexp.*; import java.util.*; import java.text.MessageFormat; public class DynSqlSelectStmts extends AbstractRule { private static boolean debug = true; private static final String PATTERN = "select.+from"; private String currMethName; private int currMethXsVis; private Map currMethParams; private String currMethSymptomCode; private List currMethExprsToChase; private List currMethVarsChased; private void init ( ) { currMethName = ""; currMethXsVis = 0; currMethParams = new HashMap( ); currMethSymptomCode = ""; currMethExprsToChase = new ArrayList( ); currMethVarsChased = new LinkedList( ); } public void setDebug (boolean x) { debug = x; } public void printDebug (String str) { if (debug) System.out.print(str + "\n"); } public Object visit(ASTCompilationUnit node, Object data) { getInfo(node); printDebug("Rule: " + this.getName( ) + "\n\n"); return super.visit(node,data); } public Object visit(ASTClassBodyDeclaration node, Object data) { getInfo(node); if (!(node.jjtGetChild(0) instanceof ASTMethodDeclaration)) { return null; } this.init( ); return super.visit(node,data); } public Object visit(ASTMethodDeclaration node, Object ...Read now
Unlock full access