Modernizing Java Ser ver Pages By Transformationpost.queensu.ca/~trd/research/pres/WSE2005.pdf ·...
Transcript of Modernizing Java Ser ver Pages By Transformationpost.queensu.ca/~trd/research/pres/WSE2005.pdf ·...
Modernizing Java Server Pages By
TransformationS h a n n o n X u
T h o m a s D e a nQ u e e n ’ s U n i v e r s i t y
Background CSER - Consortium for Software Engineering Research Dynamic Web Pages
Multiple Technologies - CGI, shtml, JSP, ASP, .NET Mixing Code and Data
Ok for small projects, seems to be proving a detriment to larger projects
Separate Concerns: Application Code and Graphics Design
Abstract User Interface [Schneider 2001] Custom Tags (JSP)
replaces code with abstract tags
JSP Basics
Mix Java and Template Text Template Text is sent to browser
modified by inline Java HTML, Javascript, Applet Tags, CSS
Java Code + standard Actions <% for (int i = 0; i < bean.titles.length; i++) {
%> <jsp:useBean> forward pages, import classes, declare fields
and methods
Custom Tags<%taglib uri=”xxx” prefix=”mylib”%>…<mylib:cdtitle/>…
<taglib> <uri>xxx</uri> <tag> <name>cdtitle</name/> <tag_class>CdTitle</tag_class> </tag></taglib>
CdTitle.class
Custom Tags<%taglib uri=”xxx” prefix=”mylib”%>…<mylib:cdtitle/>…
<taglib> <uri>xxx</uri> <tag> <name>cdtitle</name/> <tag_class>CdTitle</tag_class> </tag></taglib>
CdTitle.class
Custom Tags<%taglib uri=”xxx” prefix=”mylib”%>…<mylib:cdtitle/>…
<taglib> <uri>xxx</uri> <tag> <name>cdtitle</name/> <tag_class>CdTitle</tag_class> </tag></taglib>
CdTitle.class
Custom Tags<%taglib uri=”xxx” prefix=”mylib”%>…<mylib:cdtitle/>…
<taglib> <uri>xxx</uri> <tag> <name>cdtitle</name/> <tag_class>CdTitle</tag_class> </tag></taglib>
CdTitle.class
Custom Tags<%taglib uri=”xxx” prefix=”mylib”%>…<mylib:cdtitle/>…
<taglib> <uri>xxx</uri> <tag> <name>cdtitle</name/> <tag_class>CdTitle</tag_class> </tag></taglib>
CdTitle.class
Custom Tags<%taglib uri=”xxx” prefix=”mylib”%>…<mylib:cdtitle/>…
<taglib> <uri>xxx</uri> <tag> <name>cdtitle</name/> <tag_class>CdTitle</tag_class> </tag></taglib>
CdTitle.class
Requirements
No Change to Functionality Identical Behaviour
No change to Appearance Same HTML / Javascript is generated
to browser Same web site structure (paths to pages) Keep Code Comments
Maintenance Issue
MuiltiLingualGrammar [Synytskyy03]
HTML Base Grammar
ASPGrammar
MuiltiLingualGrammar [Synytskyy03]
HTML Base Grammar
JSPGrammar
[Li 2004]
MuiltiLingualGrammar [Synytskyy03]
HTML Base Grammar
JSPGrammar
Custom TagGrammar
TLD XMLGrammar
[Li 2004]
[Xu 2005]
Parsing JSP …<table> <%for(i=1;i<10;i++){%> <th><td><%=i%></td></th>
<%}%> </table>…
Interesting
<table>
Interesting
<%for(i=1;i<10;i++){%>
Interesting
<%=i%>
Interesting
<%}%>
Interesting
</table>
Parsing JSP …<table> <%for(i=1;i<10;i++){%> <th><td><%=i%></td></th>
<%}%> </table>…
Interesting
<table>
Interesting
<%for(i=1;i<10;i++){%>
Interesting
<%=i%>
Interesting
<%}%>
Interesting
</table>
Parsing JSP …<table> <%for(i=1;i<10;i++){%> <th><td><%=i%></td></th>
<%}%> </table>…
Interesting
<table>
Interesting
<%=i%>
<%
</table>
}
%>
for(i=1;i<10;i++){
<% %>for_statement
Parsing JSP …<table> <%for(i=1;i<10;i++){%> <th><td><%=i%></td></th>
<%}%> </table>…
Interesting
<table>
Interesting
<%=i%>
<%
</table>
}
%>
for(i=1;i<10;i++){
<% %>for_statement
Parsing JSP …<table> <%for(i=1;i<10;i++){%> <th><td><%=i%></td></th>
<%}%> </table>…
Interesting
<table>
Interesting
<%=i%>
<%
</table>
}
%>
for(i=1;i<10;i++){
<% %>for_statement
Parsing JSP …<table> <%for(i=1;i<10;i++){%> <th><td><%=i%></td></th>
<%}%> </table>…
Interesting
<table>
Interesting
<%=i%>
<%
</table>
}
%>
for(i=1;i<10;i++){
<% %>for_statement
Java statements, expressions and declarations are moved to custom tag classes
HTML code moved out of Java strings
out.println(“<TR><TD>”)
%> <TR><TD> <%
General Approach
Java Bean action elements translated to equivalent Java Code
<jsp:useBean><jsp:getProperty><jsp:setProperty>
JSP Page import directive generates an import statement in the resulting class
<%@page import=”java.sql.ResultSet” %><% import java.sql.ResultSet; %>
General Approach
Normalization
4 General Cases
General Transformation
Case 1– Simple Code<HTML><BODY><% HttpSession s = request.getSession(true); String userId = ((String) s.getValue(“userId”)).trim(); s.putValue(“username”, userId);%></BODY></HTML>
<HTML><BODY><mylib: userSession></mylib:userSession></BODY></HTML>
Case 1b – Simple Code<HTML><BODY><% HttpSession s = request.getSession(true); String userId = ((String) s.getValue(“userId”)).trim();%> Welcome<% s.putValue(“username”, userId); %></BODY></HTML>
<HTML><BODY><mylib: userSession> Welcome</mylib:userSession></BODY></HTML>
Case 2 - Nested Code<HTML><BODY><% HttpSession s = request.getSession(true); String userId = ((String) s.getValue(“userId”)).trim(); s.putValue(“username”, userId);%>Welcome <%= username %></BODY></HTML>
<HTML><BODY><mylib: userSession> Welcome <mylib:userName/> </mylib:userSession></BODY></HTML>
Case 3 – Choice<HTML><BODY><% …
if (condition) {%> HTML TEXT <% } else {%> … }%></BODY></HTML>
Case 3 – Choice<HTML><BODY><% … bool choice = condition; if (choice) {%> HTML TEXT <% } if (!choice) {%> … }%></BODY></HTML>
Case 3 – Choice<HTML><BODY><mylib:checkCondition> <mylib:validCondition> HTML TEXT </mylib:validCondition> <mylib:invalidCondition> </mylib:invalidCondition></mylib:checkCondition></BODY></HTML>
CASE 4 - Iteration<HTML><BODY><% … while(condition){%> HTML TEXT <%}%></BODY></HTML>
<HTML><BODY><mylib:whileCondition> HTML TEXT</mylib:whileCondition></BODY></HTML>
The 4 cases compose to cover all code cases
Case 2 provides basis for nesting
tags are nested, classes are not
classes find the class for the parent tag at runtime using JSP API
Add get/set routines for variables
Composing Cases
Nesting Cases 4,2<HTML><BODY><% … while(condition){%> HTML <%= value %> TEXT <%}%></BODY></HTML>
<HTML><BODY><mylib:whileCondition> HTML <mylib:getValue/> TEXT</mylib:whileCondition></BODY></HTML>
Implementation
TXLSource Transformation LanguageGrammar + Transformation Rules
Markup ApproachIdentify key statements of each case
if statements, while statements (both with HTML text)
propagate markups to include all statements
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
Normalization& Lexical Issues
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
Custom Tag Identification
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
Namesfor Tags
Implementation
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
Move to Java
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
RemoveJava
Implementation
Preprocessing
Grouping
Original JSP
Naming
Postprocesing
Page and TLDClass Gen
TLD Pages Tag Classes
Comments
Final Words
Tested on 4 small systems (14 files)
Each case generates separate custom tags
Implementation is a greedy approach
Better separation into tags
Data and Control Flow Analys
Clones
E.g. Session management code
Questions?