org.makumba.analyser.engine
Class JspParseData

java.lang.Object
  extended by org.makumba.analyser.engine.JspParseData
All Implemented Interfaces:
SourceSyntaxPoints.PreprocessorClient

public class JspParseData
extends Object
implements SourceSyntaxPoints.PreprocessorClient

This class performs a rudimentary detection of JSP-relevant tags in a JSP page.

Version:
$Id: JspParseData.java 5153 2010-05-18 21:37:50Z rosso_nero $
Author:
Cristian Bogdan

Field Summary
(package private) static int analyzedPages
          Cache of all page analyses.
(package private)  JspAnalyzer analyzer
          The analyzer plugged in.
(package private)  File file
          The JSP file path
(package private)  Object holder
          The holder of the analysis status, and partial results.
(package private)  SourceSyntaxPoints syntaxPoints
          The syntax points of this page.
(package private)  String uri
          The JSP URI, for debugging purposes.
 
Constructor Summary
JspParseData(String path, String uri, JspAnalyzer an)
          Private constructor, construction can only be made by getParseData().
 
Method Summary
(package private) static String attribute(String attName)
           
(package private) static String attribute(String attName, String quote)
          This helps to create regex for the 'attribute' pattern easily.
 void discardParsingData()
          Releases parsing data that is useful during analysis and for error handling, but not needed anymore afterwards
static void fill(Tag t, Map<String,String> attributes)
          Fills the data for a tag by invoking the setter method through Java reflexion
 Object getAnalysisResult(Object initStatus)
          Performs the analysis if not performed already, or if the file has changed.
 String[] getCommentPatternNames()
           
 Pattern[] getCommentPatterns()
           
 Pattern getIncludePattern()
           
 String getIncludePatternName()
           
 String[] getLiteralPatternNames()
           
 Pattern[] getLiteralPatterns()
           
static JspParseData getParseData(String webappRoot, String path, JspAnalyzer an)
          Returns the pageData of the page at the given path in the given webapp.
 SyntaxPoint[] getSyntaxPointArray(Object initStatus)
           
 SourceSyntaxPoints getSyntaxPoints()
          Gets the collection of syntax points.
 boolean isUsingHibernate()
           
(package private)  void parse(Object initStatus)
          Parses the file.
(package private)  Map<String,String> parseAttributes(String s, int origin)
          Identifies tag attributes from a tag string and puts them in a Map.
static void tagDataLine(ElementData td, StringBuffer sb)
          Prints the line of a tag and points the beginning of the tag.
(package private)  void treatELExpression(Matcher m, String content, JspAnalyzer an, boolean isJsf)
          Treats a single EL expression, extracts all the maps of the kind Expr[...]
 void treatInclude(int position, String includeDirective, SyntaxPoint start, SyntaxPoint end, SourceSyntaxPoints host)
          Treats include directives in the page
(package private)  void treatIncludeDirective(String directive, SyntaxPoint start, SyntaxPoint end, JspAnalyzer an)
          Treats an include directive: parses its different parts and stores the analysis.
(package private)  void treatPageContent(String content, JspAnalyzer an)
          Goes through the page and matches tags, system tags, and EL expressions in such a way that the calls to the handling methods happen in sequential order.
(package private)  void treatSystemTag(Matcher m, String content, JspAnalyzer an)
          Treats a system tag: parses its different parts and stores the analysis.
(package private)  void treatTag(Matcher m, String content, JspAnalyzer an)
          Treats a jsp or taglib tag: parses its different parts and stores the analysis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

File file
The JSP file path


analyzer

JspAnalyzer analyzer
The analyzer plugged in.


syntaxPoints

SourceSyntaxPoints syntaxPoints
The syntax points of this page.


holder

Object holder
The holder of the analysis status, and partial results.


uri

String uri
The JSP URI, for debugging purposes.


analyzedPages

static int analyzedPages
Cache of all page analyses.

Constructor Detail

JspParseData

public JspParseData(String path,
                    String uri,
                    JspAnalyzer an)
Private constructor, construction can only be made by getParseData().

Parameters:
path - the path to the page
uri - the uri, for debugging purposes
an - the analyzer used for analysis
Method Detail

attribute

static String attribute(String attName)

attribute

static String attribute(String attName,
                        String quote)
This helps to create regex for the 'attribute' pattern easily.

Parameters:
attName - the name of the attribute
quote - the kind of quote used. Is either " or ' .

discardParsingData

public void discardParsingData()
Releases parsing data that is useful during analysis and for error handling, but not needed anymore afterwards


getAnalysisResult

public Object getAnalysisResult(Object initStatus)
Performs the analysis if not performed already, or if the file has changed. The method is synchronized, so other accesses are blocked if the current access determines that an analysis needs be performed

Parameters:
initStatus - an initial status to be passed to the JspAnalyzer. For example, the pageContext for an example-based analyzer

getSyntaxPointArray

public SyntaxPoint[] getSyntaxPointArray(Object initStatus)
Specified by:
getSyntaxPointArray in interface SourceSyntaxPoints.PreprocessorClient

getParseData

public static JspParseData getParseData(String webappRoot,
                                        String path,
                                        JspAnalyzer an)
Returns the pageData of the page at the given path in the given webapp. This is the only way for clients of this class to obtain instances of JspPageData.

Parameters:
webappRoot - the root of the webapp
path - the path to the file
the - JspAnalyzer used to parse the page

getSyntaxPoints

public SourceSyntaxPoints getSyntaxPoints()
Gets the collection of syntax points.

Specified by:
getSyntaxPoints in interface SourceSyntaxPoints.PreprocessorClient

parse

void parse(Object initStatus)
Parses the file.

Parameters:
initStatus - an initial status to be passed to the JspAnalyzer. For example, the pageContext for an example-based analyzer

parseAttributes

Map<String,String> parseAttributes(String s,
                                   int origin)
Identifies tag attributes from a tag string and puts them in a Map. Sets the attribute syntax points.

Parameters:
s - the tag string to be parsed
origin - the origin of the string in the parsed page

treatInclude

public void treatInclude(int position,
                         String includeDirective,
                         SyntaxPoint start,
                         SyntaxPoint end,
                         SourceSyntaxPoints host)
Treats include directives in the page

Specified by:
treatInclude in interface SourceSyntaxPoints.PreprocessorClient
Parameters:
position - position of the include directive
includeDirective - include directive to be treated
host - SourceSyntaxPoints object that is going to host this included page

getCommentPatterns

public Pattern[] getCommentPatterns()
Specified by:
getCommentPatterns in interface SourceSyntaxPoints.PreprocessorClient

getCommentPatternNames

public String[] getCommentPatternNames()
Specified by:
getCommentPatternNames in interface SourceSyntaxPoints.PreprocessorClient

getIncludePattern

public Pattern getIncludePattern()
Specified by:
getIncludePattern in interface SourceSyntaxPoints.PreprocessorClient

getIncludePatternName

public String getIncludePatternName()
Specified by:
getIncludePatternName in interface SourceSyntaxPoints.PreprocessorClient

treatPageContent

void treatPageContent(String content,
                      JspAnalyzer an)
Goes through the page and matches tags, system tags, and EL expressions in such a way that the calls to the handling methods happen in sequential order. TODO add support for JSF EL expressions

Parameters:
content - the content of the page
an - a JspAnalyzer implementation

treatELExpression

void treatELExpression(Matcher m,
                       String content,
                       JspAnalyzer an,
                       boolean isJsf)
Treats a single EL expression, extracts all the maps of the kind Expr[...] TODO also parse Expr.some.thing TODO parse attributes for methods, if these exist

Parameters:
m - the Matcher used to parse the expression
content - the content of the page
an - the JspAnalyzer used to analyze the page
isJsf - whether this is a JSP EL value ${...} or a JSF method #{...}

treatTag

void treatTag(Matcher m,
              String content,
              JspAnalyzer an)
Treats a jsp or taglib tag: parses its different parts and stores the analysis.

Parameters:
m - the Matcher used to parse the tag
content - the content of the page
an - the JspAnalyzer used to analyze the page

treatSystemTag

void treatSystemTag(Matcher m,
                    String content,
                    JspAnalyzer an)
Treats a system tag: parses its different parts and stores the analysis. FIXME this contains mak-specific code and should move together with the makJspAnalyser

Parameters:
m - the Matcher used to parse the tag
content - the content of the page
an - the JspAnalyzer used to analyze the page

treatIncludeDirective

void treatIncludeDirective(String directive,
                           SyntaxPoint start,
                           SyntaxPoint end,
                           JspAnalyzer an)
Treats an include directive: parses its different parts and stores the analysis.

Parameters:
m - the Matcher used to parse the directive
directive - the content of the page
an - the JspAnalyzer used to analyze the page

tagDataLine

public static void tagDataLine(ElementData td,
                               StringBuffer sb)
Prints the line of a tag and points the beginning of the tag. Seems to be a nice illustration for parse-error messages.

Parameters:
td - the TagData of the tag
sb - the StringBuffer used to print out

fill

public static void fill(Tag t,
                        Map<String,String> attributes)
Fills the data for a tag by invoking the setter method through Java reflexion

Parameters:
t - the tag to be filled with data
attributes - the attributes of the tag

isUsingHibernate

public boolean isUsingHibernate()

getLiteralPatternNames

public String[] getLiteralPatternNames()
Specified by:
getLiteralPatternNames in interface SourceSyntaxPoints.PreprocessorClient

getLiteralPatterns

public Pattern[] getLiteralPatterns()
Specified by:
getLiteralPatterns in interface SourceSyntaxPoints.PreprocessorClient