Domain Specific Languages for Interactive Web Services

Document Sample
Domain Specific Languages for Interactive Web Services Powered By Docstoc
					       Domain Specific Languages
      for Interactive Web Services

                          Claus Brabrand
[ Joint work with Anders Møller, Michael Schwartzbach, BRICS, Denmark ]
                       Compose Research Group
      INRIA/LaBRI, University of Bordeaux I


   GPCE 2003, Erfurt       Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Program Family

           Interactive (Form-Based) Web Services:
    ”Web servers on which clients can initiate sessions
     that involve several exchanges of information
     mediated by HTML forms”.




                    client    Internet     server


GPCE 2003, Erfurt     Dynamic Generation of XML     September 22, 2003
A Program from the Program Family
  public class SessionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
                                                                    Java Servlet
               HttpServletResponse response) throws ServletException, IOException {
      ServletContext context = getServletContext();
      HttpSession session = request.getSession(true);
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
      if (session.isNew()) {
        out.println("<FORM ACTION=SessionServlet>" +
        "Enter your name: <INPUT NAME=handle>" +
        "<INPUT TYPE=SUBMIT></FORM>");
        session.putValue("state", "1");
      } else {
        String state = (String) session.getValue("state");
        if (state.equals("1")) {
          String name = (String) request.getParameter("handle");
          int users = ((Integer) context.getAttribute("users")).intValue() + 1;
          context.setAttribute("users", new Integer(users));
          session.putValue("name", name);
          out.println("Hello " + name + ", you are user number " + users);
          session.putValue("state", "2");
        } else /* state.equals("2") */ {
          String name = (String) session.getValue("name");
          out.println("Goodbye " + name);
          session.invalidate();
        }
      }
      out.println("</BODY></HTML>");
    }
  }
 GPCE 2003, Erfurt           Dynamic Generation of XML            September 22, 2003
A Program from the Program Family




                                                       Web
                                                       Service



            CLIENT          INTERNET             SERVER

 GPCE 2003, Erfurt   Dynamic Generation of XML     September 22, 2003
A Program from the Program Family
  public class SessionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
                                                                    Java Servlet
               HttpServletResponse response) throws ServletException, IOException {
      ServletContext context = getServletContext();
      HttpSession session = request.getSession(true);
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
      if (session.isNew()) {
        out.println("<FORM ACTION=SessionServlet>" +
        "Enter your name: <INPUT NAME=handle>" +
        "<INPUT TYPE=SUBMIT></FORM>");
        session.putValue("state", "1");
      } else {
        String state = (String) session.getValue("state");
        if (state.equals("1")) {
          String name = (String) request.getParameter("handle");
          int users = ((Integer) context.getAttribute("users")).intValue() + 1;
          context.setAttribute("users", new Integer(users));
          session.putValue("name", name);
          out.println("Hello " + name + ", you are user number " + users);
          session.putValue("state", "2");
        } else /* state.equals("2") */ {
          String name = (String) session.getValue("name");
          out.println("Goodbye " + name);
          session.invalidate();
        }                                            session management
      }
      out.println("</BODY></HTML>");
    }
  }
 GPCE 2003, Erfurt           Dynamic Generation of XML            September 22, 2003
A Program from the Program Family
  public class SessionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
                                                                    Java Servlet
               HttpServletResponse response) throws ServletException, IOException {
      ServletContext context = getServletContext();
      HttpSession session = request.getSession(true);
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
      if (session.isNew()) {
        out.println("<FORM ACTION=SessionServlet>" +
        "Enter your name: <INPUT NAME=handle>" +
        "<INPUT TYPE=SUBMIT></FORM>");
        session.putValue("state", "1");
      } else {
        String state = (String) session.getValue("state");
        if (state.equals("1")) {
          String name = (String) request.getParameter("handle");
          int users = ((Integer) context.getAttribute("users")).intValue() + 1;
          context.setAttribute("users", new Integer(users));
          session.putValue("name", name);
          out.println("Hello " + name + ", you are user number " + users);
          session.putValue("state", "2");
        } else /* state.equals("2") */ {
          String name = (String) session.getValue("name");
          out.println("Goodbye " + name);
          session.invalidate();
        }
      }
      out.println("</BODY></HTML>");                 state management
    }
  }
 GPCE 2003, Erfurt           Dynamic Generation of XML            September 22, 2003
A Program from the Program Family
  public class SessionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
                                                                    Java Servlet
               HttpServletResponse response) throws ServletException, IOException {
      ServletContext context = getServletContext();
      HttpSession session = request.getSession(true);
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
      if (session.isNew()) {
        out.println("<FORM ACTION=SessionServlet>" +
        "Enter your name: <INPUT NAME=handle>" +
        "<INPUT TYPE=SUBMIT></FORM>");
        session.putValue("state", "1");
      } else {
        String state = (String) session.getValue("state");
        if (state.equals("1")) {
          String name = (String) request.getParameter("handle");
          int users = ((Integer) context.getAttribute("users")).intValue() + 1;
          context.setAttribute("users", new Integer(users));
          session.putValue("name", name);
          out.println("Hello " + name + ", you are user number " + users);
          session.putValue("state", "2");
        } else /* state.equals("2") */ {
          String name = (String) session.getValue("name");
          out.println("Goodbye " + name);
          session.invalidate();
        }
      }
      out.println("</BODY></HTML>");

  }
    }
 GPCE 2003, Erfurt
                                                     document construction
                             Dynamic Generation of XML            September 22, 2003
A Program from the Program Family
  public class SessionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
                                                                    Java Servlet
               HttpServletResponse response) throws ServletException, IOException {
      ServletContext context = getServletContext();
      HttpSession session = request.getSession(true);
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
      if (session.isNew()) {
        out.println("<FORM ACTION=SessionServlet>" +
        "Enter your name: <INPUT NAME=handle>" +
        "<INPUT TYPE=SUBMIT></FORM>");
        session.putValue("state", "1");
      } else {
        String state = (String) session.getValue("state");
        if (state.equals("1")) {
          String name = (String) request.getParameter("handle");
          int users = ((Integer) context.getAttribute("users")).intValue() + 1;
          context.setAttribute("users", new Integer(users));
          session.putValue("name", name);
          out.println("Hello " + name + ", you are user number " + users);
          session.putValue("state", "2");
        } else /* state.equals("2") */ {
          String name = (String) session.getValue("name");
          out.println("Goodbye " + name);
          session.invalidate();
        }                                            session management
      }
      out.println("</BODY></HTML>");                 state management
  }
    }
 GPCE 2003, Erfurt
                                                     document construction
                             Dynamic Generation of XML            September 22, 2003
A Program from the Program Family
  public class SessionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
                                                                    Java Servlet
               HttpServletResponse response) throws ServletException, IOException {
      ServletContext context = getServletContext();
      HttpSession session = request.getSession(true);
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
      if (session.isNew()) {
        out.println("<FORM ACTION=SessionServlet>" +
        "Enter your name: <INPUT NAME=handle>" +
        "<INPUT TYPE=SUBMIT></FORM>");
        session.putValue("state", "1");
      } else {
        String state = (String) session.getValue("state");
        if (state.equals("1")) {
          String name = (String) request.getParameter("handle");
          int users = ((Integer) context.getAttribute("users")).intValue() + 1;
          context.setAttribute("users", new Integer(users));
          session.putValue("name", name);
          out.println("Hello " + name + ", you are user number " + users);
          session.putValue("state", "2");
        } else /* state.equals("2") */ {
          String name = (String) session.getValue("name");
          out.println("Goodbye " + name);
          session.invalidate();
        }                                            session management
      }
      out.println("</BODY></HTML>");                 state management
  }
    }
 GPCE 2003, Erfurt
                                                     document construction
                             Dynamic Generation of XML            September 22, 2003
The <bigwig> Language/System

• A high-level domain-specific programming
  language for developing interactive Web
  services.
                                                    HTML

                                                  JavaScript
  Complete
   Service                 <bigwig>              CGI Scripts
 Specification
                                                 HTTP Auth.

                                                 Java Applets


 GPCE 2003, Erfurt   Dynamic Generation of XML     September 22, 2003
<bigwig> = a Collection of
Domain Specific Languages
• C-like core language with
        • Session-based runtime system
        • Dynamic documents
        • Form-field validation
        • Relational database
        • Concurrency control
        • Semantic security
        • Cryptographic security
        • Syntactic-level macros

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
<bigwig> = a Collection of
Domain Specific Languages
• C-like core language with
        • Session-based runtime system
        • Dynamic documents
        • Form-field validation
        • Relational database
        • Concurrency control
        • Semantic security
        • Cryptographic security
        • Syntactic-level macros

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Implementation Approaches

• Traditionally 2 approaches:

   – Script-centered:
      • Perl/CGI, Java Servlets, …

   – Page-centered:
      • ASP, PHP, JSP, ...


 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e




                                                       Web
                                                       Service



            CLIENT          INTERNET             SERVER

 GPCE 2003, Erfurt   Dynamic Generation of XML     September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e
                     request




                                                          Web
                                                          Service



            CLIENT             INTERNET             SERVER

 GPCE 2003, Erfurt      Dynamic Generation of XML     September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e
                                                        compute
                                                        reply




                                                       Web
                                                       Service



            CLIENT          INTERNET             SERVER

 GPCE 2003, Erfurt   Dynamic Generation of XML     September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e



                     HTML
                e



                                                         Web
                                                         Service



            CLIENT            INTERNET             SERVER

 GPCE 2003, Erfurt     Dynamic Generation of XML     September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e




                e

                     submit
                                                           Web
                                                           Service



            CLIENT              INTERNET             SERVER

 GPCE 2003, Erfurt       Dynamic Generation of XML     September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e




                e



                                                       Web
                                                       Service
                                                 compute
                                                 reply

            CLIENT          INTERNET             SERVER

 GPCE 2003, Erfurt   Dynamic Generation of XML      September 22, 2003
Script-Centered:
Perl/CGI, Servlets, ...
                e




                e



                                                         Web
                e    HTML                                Service



            CLIENT            INTERNET             SERVER

 GPCE 2003, Erfurt     Dynamic Generation of XML     September 22, 2003
Page-Centered:
PHP, ASP, JSP, ...
               e




               e



                                                      Web
               e                                      Service



           CLIENT          INTERNET             SERVER

GPCE 2003, Erfurt   Dynamic Generation of XML     September 22, 2003
Page-Centered
   “Service code embedded in tags and
    interpreted by specialized Web server”

• Increased level of abstraction:
        • CGI protocol details abstracted away
• Easy to add dynamics to static pages:
        •   <html><body>Time: <%= Now() %>
                                        %></body></html>

• Scalability:
        • Specialized Web server
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Script-Centered vs. Page-Centered

• As the service complexity increases:
   – Page-Centered  Script-Centered
      • A lot of HTML is generated by script elements

• Interesting duality:
        • Script-centered:
              – Default: programming, Escape: printing       (print)
        • Page-centered:
              – Default: printing, Escape: programming       (<%...%>)

 GPCE 2003, Erfurt        Dynamic Generation of XML      September 22, 2003
Fundamental Drawbacks

• A service = a collection of scripts/pages!

        • Implicit control-flow:
                                                  Web
                                                  Service
        • No interaction correspondence:
     <input name=”x”>                             <%= $y %>
                            submit
          a_script                         another_script
 GPCE 2003, Erfurt    Dynamic Generation of XML         September 22, 2003
Session-Centered:
Mawl and <bigwig>!
               e
                                                    Web Service



               e                        x            show x;
                    submit

               e                        y
                                                     show y;



         CLIENT               INTERNET                SERVER

GPCE 2003, Erfurt       Dynamic Generation of XML      September 22, 2003
Session-Centered:
Mawl and <bigwig>!
               e
                                                    Web Service



               e                        x            show x;
                    submit

• Domain specific abstration: show
                                                     show y;
• Explicit control-flow
• Check interaction correspondence

GPCE 2003, Erfurt       Dynamic Generation of XML      September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
General Purpose  Manually
               e




               e



                                                      Web
               e                                      Service



           CLIENT          INTERNET             SERVER

GPCE 2003, Erfurt   Dynamic Generation of XML     September 22, 2003
General Purpose  Manually
               e

                                                save


               e



                                                       Web
               e                                       Service



           CLIENT          INTERNET             SERVER

GPCE 2003, Erfurt   Dynamic Generation of XML      September 22, 2003
General Purpose  Manually
               e

                                                   save


               e


                                         restore
                                                          Web
               e                                          Service



           CLIENT          INTERNET                SERVER

GPCE 2003, Erfurt   Dynamic Generation of XML         September 22, 2003
General Purpose  Manually

• Private (to each session thread):
  ServletContext context = getServletContext();
  int p ((Integer)
             context.getAttribute("p")).intValue();
  p++;
  context.setAttribute("p", new Integer(var));




 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
General Purpose  Manually

• Private (to each session thread):
  ServletContext context = getServletContext();
  int p ((Integer)
             context.getAttribute("p")).intValue();
  p++;
  context.setAttribute("p", new Integer(var));


• Shared (among all session threads):
  HttpSession session = request.getSession(true);
  int s ((Integer)
             session.getValue("s")).intValue();
  s++;
  session.setValue("s", new Integer(var));

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Domain Specific: shared modifier

• Private (to each session thread):
  int p;

  ...
  p++;
  ...




 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Domain Specific: shared modifier

• Private (to each session thread):
  int p;

  ...
  p++;
  ...


• Shared (among all session threads):
  shared int s;

  ...
  s++;
  ...

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Domain Specific  Automatically
               e
                                                    Web Service



               e                        x            show x; [ save ]
                                                             [ restore ]
                    submit

               e                        y
                                                     show y;



         CLIENT               INTERNET                SERVER

GPCE 2003, Erfurt       Dynamic Generation of XML      September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Dynamically Generated XML:
Current Problems
• Traditionally:
        • print(...)                    in Perl/CGI, ...
        • <% print(...) %>              in PHP, ASP, JSP, ...

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML      September 22, 2003
Our Solution:
HTML documents in <bigwig>
• Templates (1st class, higher-order values):
        • XML fragments with named gaps:
                     [[
                       Hello <[what]>!
                     ]]


• Operations:
        • plug:      for document construction
        • show:      for client interaction

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Plug
• Plug:             exp <[ id = exp ]




GPCE 2003, Erfurt      Dynamic Generation of XML   September 22, 2003
Plug
• Plug:             exp <[ id = exp ]



• Example:
             html hello = [[ Hello <[what]>! ]];
             html world = [[ <b>World</b> ]];

             html h = hello <[what = world];
             ...;


GPCE 2003, Erfurt      Dynamic Generation of XML   September 22, 2003
Show
• Show:                 show   exp ;
                    e            x
                                             show x; suspend
    submit                                           resume

              CLIENT      INTERNET         SERVER




GPCE 2003, Erfurt         Dynamic Generation of XML     September 22, 2003
Show
• Show:                 show   exp ;
                    e            x
                                             show x; suspend
    submit                                           resume

              CLIENT      INTERNET         SERVER

• Example:
            html hello = [[ Hello <[what]>! ]];
            html world = [[ <b>World</b> ]];

            html h = hello <[what = world];
            show h;


GPCE 2003, Erfurt         Dynamic Generation of XML     September 22, 2003
Show-Receive
• Show:                 show      exp receive[v =f, ...];
                    e              x
                                               show x receive[v=f,..];
    submit
                         f, ...
              CLIENT       INTERNET          SERVER




GPCE 2003, Erfurt           Dynamic Generation of XML     September 22, 2003
Show-Receive
• Show:                 show      exp receive[v =f, ...];
                    e              x
                                               show x receive[v=f,..];
    submit
                         f, ...
              CLIENT       INTERNET          SERVER

• Example:
string s;
html input = [[
  Enter email: <input type=”text” name=”email”>
]];

show input receive[s = email];

GPCE 2003, Erfurt           Dynamic Generation of XML     September 22, 2003
Example: ”Welcome”

 html greeting = [[
   Hello <[who]>, welcome to <[what]>.
 ]];

 html cover = [[
   <head><title>Welcome</title></head>
   <body><[contents]></body>
 ]];

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Flexibility: PHP/ASP/JSP

• List of results (e.g. “search engine”):
        • One template with 10,20,30,
           or 40 hardwired server-side             <% ..1.. %>
           script elements:                        <% ..2.. %>
                                                         :
 ...or...                                          <% ..20.. %>

        • One template with one big
           ”generate-all” server-side
                                                   <% for
           script element:                          i=1 to N do
                        script-centered            { ..i.. } %>

 GPCE 2003, Erfurt     Dynamic Generation of XML       September 22, 2003
Flexibility: <bigwig>                                      <ul>
                                                             <li>1
                                                             <li>2
                                                               :
• List of results (e.g. “search engine”):                    <li>N
                                                           </ul>




 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Flexibility: <bigwig>                                      <ul>
                                                             <li>1
                                                             <li>2
                                                               :
• List of results (e.g. “search engine”):                    <li>N
                                                           </ul>
        • Two templates: “layout” and “entry”...
html layout = [[ <ul><[items]></ul> ]];
html entry = [[ <li><[num]><[items]> ]];




 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Flexibility: <bigwig>                                       <ul>
                                                              <li>1
                                                              <li>2
                                                                :
• List of results (e.g. “search engine”):                     <li>N
                                                            </ul>
        • Two templates: “layout” and “entry”...
html layout = [[ <ul><[items]></ul> ]];
html entry = [[ <li><[num]><[items]> ]];

        • ...and one recursive function: “f”
html f(int n) {
  if (n == 0) return layout;
  return f(n-1) <[items = entry <[num = n]];
}



 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Flexibility: <bigwig>                                       <ul>
                                                              <li>1
                                                              <li>2
                                                                :
• List of results (e.g. “search engine”):                     <li>27
                                                            </ul>
        • Two templates: “layout” and “entry”...
html layout = [[ <ul><[items]></ul> ]];
html entry = [[ <li><[num]><[items]> ]];

        • ...and one recursive function: “f”
html f(int n) {
  if (n == 0) return layout;
  return f(n-1) <[items = entry <[num = n]];
}

        • Example usage:       show f(27);

 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Flexibility: Separates
Designer / Programmer Aspects
html layout = [[ <ul><[items]></ul> ]];
html entry = [[ <li><[num]><[items]> ]];




html f(int n) {
  if (n == 0) return layout;
  return f(n-1) <[items = entry <[num = n]];
}

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Flexibility: Separates
Designer / Programmer Aspects
html layout = [[ <ul><[items]></ul> ]];
html entry = [[ <li><[num]><[items]> ]];

html layout = [[ <table><[items]></table> ]];
html entry = [[
  <tr><td><[num]></td></tr>
  <[items]>
]];

html f(int n) {
  if (n == 0) return layout;
  return f(n-1) <[items = entry <[num = n]];
}

 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?

   <input name=”x”>                              <%= $y %>
                         submit
        a_script                        another_script


• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML          September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Type Safety
(in terms of <bigwig>)
• Show/Receive correspondence:
html d = [[
  Enter email: <input type=“text” name=“email”>
]];

show d receive[s = age];           
• Gap presence:
html hello = [[ Hello <[what]>! ]];
html world = [[ <b>World</b> ]];
html h;

h = hello <[contents = world];               
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Static Analysis!


 Apply standard, data-flow analysis techniques,
     but with highly domain-specific lattices




 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Static Analysis!

• Conservatively approximate
     for all HTML variables & program points:
        • Their gaps and fields (and their kinds)
                      all possible runtime values


• Forward data-flow analysis:
        1. Control-flow graph (trivial for <bigwig>)
        2. Finite lattice: Gap-and-Field
        3. Monotone transfer functions: plug, assign, ...
 GPCE 2003, Erfurt         Dynamic Generation of XML   September 22, 2003
Gap-and-Field Lattice
       GKind                                     FKind
        nogap                                    error

       string
                        text       radio     checkbox    rel(F1) .. rel(Fn)
         html
                                             nofield     tup(F1) .. tup(Fn)
        error




• An abstract document is:                               FName
                                                          GName
                                                                   FKind
                                                                   GKind
                                                           a       html
  (GName  GKind) x (FName  FKind)                        g
                                                            a      html
                                                                   html
                                                            g      html
                                                           n       nogap
                                                            n      nogap
 GPCE 2003, Erfurt   Dynamic Generation of XML           September 22, 2003
Monotone Transfer Functions

• Plug:              x1 <[g = x2]




 GPCE 2003, Erfurt        Dynamic Generation of XML   September 22, 2003
 Monotone Transfer Functions

 • Plug:               x1 <[g = x2]


FName     FKind                FName     FKind
 GName
  a       GKind
          html
                                 GName
                                  a       GKind
                                          html
   a      html                    a      nogap
  g       html                   g       html
   g      html                    g      nogap
  n       nogap                  n       nogap
   n      nogap                   n      html




   GPCE 2003, Erfurt        Dynamic Generation of XML   September 22, 2003
 Monotone Transfer Functions

 • Plug:               x1 <[g = x2]


FName     FKind                FName     FKind             FName     FKind
 GName
  a       GKind
          html
                                 GName
                                  a       GKind
                                          html
                                                              GName
                                                               a       GKind
                                                                       html
   a      html                    a      nogap                a     
                                                        ]
  g       html                   g       html                g       html
  n
   g      html
          nogap
                        <[g =     n
                                   g      nogap
                                          nogap               n
                                                                g     
                                                                       nogap
   n      nogap                   n      html                 n     


                       G : GKind x GKind  GKind

   GPCE 2003, Erfurt        Dynamic Generation of XML        September 22, 2003
 Monotone Transfer Functions

 • Plug:               x1 <[g = x2]


FName     FKind                FName     FKind             FName     FKind
 GName
  a       GKind
          html
                                 GName
                                  a       GKind
                                          html
                                                              GName
                                                               a       GKind
                                                                       html
   a      html                    a      nogap                a      html
                                                        ]
  g       html                   g       html                g       html
  n
   g      html
          nogap
                        <[g =     n
                                   g      nogap
                                          nogap               n
                                                                g     
                                                                       nogap
   n      nogap                   n      html                 n     


                       G : GKind x GKind  GKind

   GPCE 2003, Erfurt        Dynamic Generation of XML        September 22, 2003
 Monotone Transfer Functions

 • Plug:               x1 <[g = x2]


FName     FKind                FName     FKind             FName     FKind
 GName
  a       GKind
          html
                                 GName
                                  a       GKind
                                          html
                                                              GName
                                                               a       GKind
                                                                       html
   a      html                    a      nogap                a      html
                                                        ]
  g       html                   g       html                g       html
  n
   g      html
          nogap
                        <[g =     n
                                   g      nogap
                                          nogap               n
                                                                g      nogap
                                                                       nogap
   n      nogap                   n      html                 n     


                       G : GKind x GKind  GKind

   GPCE 2003, Erfurt        Dynamic Generation of XML        September 22, 2003
 Monotone Transfer Functions

 • Plug:               x1 <[g = x2]


FName     FKind                FName     FKind             FName     FKind
 GName
  a       GKind
          html
                                 GName
                                  a       GKind
                                          html
                                                              GName
                                                               a       GKind
                                                                       html
   a      html                    a      nogap                a      html
                                                        ]
  g       html                   g       html                g       html
  n
   g      html
          nogap
                        <[g =     n
                                   g      nogap
                                          nogap               n
                                                                g      nogap
                                                                       nogap
   n      nogap                   n      html                 n      html


                       G : GKind x GKind  GKind

   GPCE 2003, Erfurt        Dynamic Generation of XML        September 22, 2003
 Monotone Transfer Functions

 • Plug:               x1 <[g = x2]


FName     FKind                FName     FKind             FName     FKind
 GName
  a       GKind
          html
                                 GName
                                  a       GKind
                                          html
                                                              GName
                                                               a       GKind
                                                                       html
   a      html                    a      nogap                a      html
                                                        ]
  g       html                   g       html                g       html
  n
   g      html
          nogap
                        <[g =     n
                                   g      nogap
                                          nogap               n
                                                                g      nogap
                                                                       nogap
   n      nogap                   n      html                 n      html




   GPCE 2003, Erfurt        Dynamic Generation of XML        September 22, 2003
Then: Check Solution
• Traverse solution: intercept errors




  GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Then: Check Solution
• Traverse solution: intercept errors
•  E1 <[g = E2]            FName  FKind
                             GName  GKind
                              a     html
                                                   a    html
                                                  g     html
                                                   g    html
                  gap present                     n     nogap
                                                   n    nogap




  GPCE 2003, Erfurt       Dynamic Generation of XML        September 22, 2003
Then: Check Solution
• Traverse solution: intercept errors
•  E1 <[g = E2]            FName  FKind
                             GName  GKind
                              a     html
                                                   a    html
                                                  g     html
                                                   g    html
                                                  n     nogap
                  gap present
                                                   n    nogap

                                                        GName  GKind

•     show E receive[v=f, ...];                                FKind
                                                         FName  html
                                                          a
                                                           e    radio
                                                          g     html
                                                          nf    text
                                                                nogap
                  field present
                                                          t           text
                  type check: v ~ text

  GPCE 2003, Erfurt       Dynamic Generation of XML           September 22, 2003
Type Safety?

• Show/Receive interaction correspondence:
html d = [[
  Enter email: <input type=“text” name=“email”>
]];

show d receive[s = age];           
• Gap presence:
html hello = [[ Hello <[what]>! ]];
html world = [[ <b>World</b> ]];
html h;

h = hello <[contents = world];               
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Type Safety!

• Show/Receive interaction correspondence:
html d = [[
  Enter email: <input type=“text” name=“email”>
]];       *** receive.wig:5: input field „email‟ not received
                                    no such input field „age‟
show d receive[s = age];

• Gap presence:
html hello = [[ Hello <[what]>! ]];
html world = [[ <b>World</b> ]];
html h;
               *** plug.wig:5: no such gap „contents‟

h = hello <[contents = world];
 GPCE 2003, Erfurt       Dynamic Generation of XML      September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Example: ”Welcome”

 html greeting = [[
   Hello <[who]>, welcome to <[what]>.
 ]];

 html cover = [[
   <head><title>Welcome</title></head>
   <body><[contents]></body>
 ]];

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Example: ”Welcome”

 html greeting = [[
   Hello <[who]>, welcome to <[what]>.
 ]];

 html cover = [[
   <head><title>Welcome</title></head>
   <body><[contents]></body>
 ]];
                                    Valid HTML !?
 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Static Analysis (again)!

• Conservatively approximate
     for all HTML variables & program points:
        • A summary graph  all possible runtime values

• Forward data-flow analysis:
        1. Control-flow graph: (trivial for <bigwig>)
        2. Finite lattice: summary graphs
        3. Monotone transfer functions: plug, assign, ...

 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Summary Graph

 html greeting = ...;

 html cover = ...;

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];




GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Summary Graph

 html greeting = ...;

 html cover = ...;

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

                     greeting                   ”Stranger”
                                      who



GPCE 2003, Erfurt   Dynamic Generation of XML          September 22, 2003
Summary Graph

 html greeting = ...;

 html cover = ...;

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

                     greeting                   ”Stranger”
                                      who

                                  what              gpce
GPCE 2003, Erfurt   Dynamic Generation of XML          September 22, 2003
Summary Graph

 html greeting = ...;

 html cover = ...;

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

                          greeting                   ”Stranger”
                    contents               who

             cover                     what              gpce
GPCE 2003, Erfurt        Dynamic Generation of XML          September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]




 GPCE 2003, Erfurt        Dynamic Generation of XML   September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g
         g

 g       g




 GPCE 2003, Erfurt        Dynamic Generation of XML   September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g
         g
                 <[g =                    ]
 g       g




 GPCE 2003, Erfurt        Dynamic Generation of XML   September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g                                                    g
         g
                 <[g =                    ]                  g
 g       g                                            g       g




 GPCE 2003, Erfurt        Dynamic Generation of XML           September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g                                                    g
         g
                 <[g =                    ]                  g
 g       g                                            g       g




 GPCE 2003, Erfurt        Dynamic Generation of XML           September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g                                                    g
         g
                 <[g =                    ]                  g
 g       g                                            g       g


                                However, too imprecise...!

 GPCE 2003, Erfurt        Dynamic Generation of XML           September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g                                                    g
         g
                 <[g =                    ]                  g
 g       g                                            g       g

             open gaps


 GPCE 2003, Erfurt        Dynamic Generation of XML           September 22, 2003
Monotone Transfer Function

• Plug:              x1 <[g = x2]



     g                                                    g
         g
                 <[g =                    ]                  g
 g       g                                            g       g

             open gaps


 GPCE 2003, Erfurt        Dynamic Generation of XML           September 22, 2003
GapTrack Analysis

• GapTrack data-flow analysis:
     –  program points compute:  : GName  2TEMPLATES
         • “Tracks the origins (templates) of open gaps”

     g                                                   g
         g
                 <[g =                   ]                  g
 g       g                                           g       g

                              ’
              (g)

 GPCE 2003, Erfurt       Dynamic Generation of XML           September 22, 2003
Validation?

• Now: summary graph show statements
        • Then what...?
  ...;
  h = greeting <[who = ”Stranger”];
  h = h <[what = [[ <b>GPCE</b> ]]];
  show cover <[contents = h];


                           greeting                   ”Stranger”
                     contents               who

              cover                     what              brics
 GPCE 2003, Erfurt        Dynamic Generation of XML          September 22, 2003
Validation?
A summary graph
describes:


   a set of
   hopeful
  XML docs



GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Validation?
A summary graph                         A DTD describes
describes:                              (e.g. XHTML 1.0):


   a set of                                      a set of
   hopeful                                        valid
  XML docs                                      XML docs



GPCE 2003, Erfurt   Dynamic Generation of XML       September 22, 2003
Validation!
A summary graph                          A DTD describes
describes:                               (e.g. XHTML 1.0):



                            
    a set of                                      a set of
    hopeful                                        valid
   XML docs            validation!               XML docs



 GPCE 2003, Erfurt   Dynamic Generation of XML       September 22, 2003
Validation!
• Decidable!:
   • Summary graph traversal (parsing vs. DTD)
   • Memoization  termination
   • Sound and complete!


                            
    a set of                                      a set of
    hopeful                                        valid
   XML docs            validation!               XML docs



 GPCE 2003, Erfurt   Dynamic Generation of XML       September 22, 2003
Compiler Validation Recipe
• Step-by-Step:
     1. Extract control-flow graph
     2. Gap-and-Field          data-flow analysis
     3. GapTrack               data-flow analysis
     4. Summary Graph          data-flow analysis
     5. Validation (shows) graph analysis




 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Experiments
800MHz Pentium III / Linux
    Program          # Lines         # Templates   Time (sec.)
    chat                65                   3          0.1
    guess               75                   6          0.1
    calendar            77                   5          0.1
    xbiff              561                  18          0.1
    webboard          1132                  37          0.6
    cdshop            1709                  36          0.5
    jaoo              1941                  73          2.4
    bachelor          2535                 137          8.2
    courses           4465                  57          1.3
    eatcs             5345                 133          6.7

Many validation errors found, no spurious errors
 GPCE 2003, Erfurt    Dynamic Generation of XML     September 22, 2003
Example Revisited

 html greeting = [[
   Hello <[who]>, welcome to <[what]>.
 ]];

 html cover = [[
   <head><title>Welcome</title></head>
   <body><[contents]></body>
 ]];

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Planting an Error

 html greeting = [[
   <td>Hello <[who]>, welcome to <[what]>.</td>
 ]];

 html cover = [[
   <head><title>Welcome</title></head>
   <body><table><[contents]></table></body>
 ]];

 html h;
 h = greeting <[who = ”Stranger”];
 h = h <[what = [[ <b>GPCE</b> ]]];
 show cover <[contents = h];

GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
          --- welcome.wig:13 HTML Validation:
          welcome.wig:7

 Example Revisited
            warning: possible illegal subelement „td‟ of „table‟
            template: <table><[contents]></table>
            contents: td
            plugs: contents:{welcome.wig:13}


 1   html greeting = [[
 2     <td>Hello <[who]>, welcome to <[what]>.</td>
 3   ]];
 4
 5   html cover = [[
 6     <head><title>Welcome</title></head>
 7     <body><table><[contents]></table></body>
 8   ]];
 9
10   html h;
11   h = greeting <[who = ”Stranger”];
12   h = h <[what = [[ <b>GPCE</b> ]]];
13   show cover <[contents = h];

     GPCE 2003, Erfurt     Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Domain Specific Representation




GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Domain Specific Representation

• Constant:
        •    [[ hello <[what]>! ]]                 O (1)
• Plug:
        •    x <[g = y]                            O (1)
• Show:
        •    show d;                               O (|d|)




 GPCE 2003, Erfurt     Dynamic Generation of XML           September 22, 2003
Domain Specific Representation
 document structure




GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Domain Specific Representation
 document structure




                    string


GPCE 2003, Erfurt            Dynamic Generation of XML   September 22, 2003
Domain Specific Representation
 document structure




                    string                               templates


GPCE 2003, Erfurt            Dynamic Generation of XML   September 22, 2003
Domain Specific Representation
                    dynamic




GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Domain Specific Representation
                    dynamic




                                                 static

GPCE 2003, Erfurt    Dynamic Generation of XML            September 22, 2003
Domain Specific Representation
                          dynamic
“Transmit JavaScript
 recipe for client-side
 doc. reconstruction”




                                                       static

  GPCE 2003, Erfurt        Dynamic Generation of XML            September 22, 2003
Domain Specific Representation
                          dynamic
“Transmit JavaScript
 recipe for client-side
 doc. reconstruction”




                      “Write each template
                       to a separate file so            static
                       that it can be cached”

  GPCE 2003, Erfurt         Dynamic Generation of XML            September 22, 2003
Experiments
• Size of HTML:                             original HTML
                                            JavaScript reconstruction
                                            ...all templates cached




                     Cut to 2.6% – 25% size
 GPCE 2003, Erfurt     Dynamic Generation of XML        September 22, 2003
Experiments
(700MHz, 28.8 Modem)
• Time (download+render):                        original HTML
                                                 ...all templates cached




                     2.2x – 10x faster
 GPCE 2003, Erfurt   Dynamic Generation of XML             September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Problems?
• “DynDoc”:
        • Templates with named gaps
        • Plug and show

• Problems:
        • Forces linear document construction
        • Intermixes programmer / designer aspects
        • No interaction correspondence
        • No static XML validation
        • No common fragments caching
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Example: ”EnterEmail”


html input = [[
  Please enter your email:<br>
  <input type=”text” name=”email”>
]];

html output = [[ Your email is: <[email]> ]];

string s;
show input receive[s = email];
show output <[email = s];


  GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Example: ”EnterEmail”

format Email = regexp(”<word>@<word>(\.<word>)+”);

html input = [[
  Please enter your email:<br>
  <input type=”text” name=”email”>
]];

html output = [[ Your email is: <[email]> ]];

string s;
show input receive[s = email];
show output <[email = s];


  GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Example: ”EnterEmail”

format Email = regexp(”<word>@<word>(\.<word>)+”);

html input = [[
  Please enter your email:<br>
  <input type=”text” name=”email” format=”Email”>
]];

html output = [[ Your email is: <[email]> ]];

string s;
show input receive[s = email];
show output <[email = s];


  GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Example: ”EnterEmail”

format Email = regexp(”<word>@<word>(\.<word>)+”);

html input = [[
  Please enter your email:<br>
  <input type=”text” name=”email” format=”Email”>
]];

html output = [[ Your email is: <[email]> ]];

string s;
show input receive[s = email];
show output <[email = s];


  GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Form Field Validation:
“PowerForms”
• Domain specific language:
        • uniquely for form-field validation
• Declarative specification (regexps):
        • Abstracts away operational details
        HTML                                        HTML
                           PowerForms
      Regexps                                     JavaScript
                                                   (subset)

• PowerForms also available as stand-alone tool
 GPCE 2003, Erfurt    Dynamic Generation of XML    September 22, 2003
Form-Field Interdependency




• “Favorite Letter”
        • Select filtering
• “NYC Office”
        • Complex interdependency

 GPCE 2003, Erfurt     Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Outline

• Introduction (Program Family)
• Session Management
        • State Management
• Document Construction
        • Domain Specific Verifications
        • Domain Specific Optimization
• Form-Field Validation
• Conclusion
 GPCE 2003, Erfurt    Dynamic Generation of XML   September 22, 2003
Domain Specific Language
Design and Analyses:
• Yield:             Flexible, Safe, and Efficient
                     Dynamic Generation of XML




 GPCE 2003, Erfurt       Dynamic Generation of XML   September 22, 2003
Domain Specific Language
Design and Analyses:
• Yield:             Flexible, Safe, and Efficient
                     Dynamic Generation of XML
• AND:
        • Non-linear document construction
        • Separates programmer / designer aspects
        • Guaranteed interaction correspondence
        • Static XML validation
        • Common fragments caching

 GPCE 2003, Erfurt       Dynamic Generation of XML   September 22, 2003
Objective Assessments

• Robustness:
        • Session integrity
        • State integrity
        • Interaction correspondence
        • XML validity
• Performance
        • Well...
• Conciseness
        • 1/5 code (compared to Java Servlets)
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
Conciseness (Servlets)
 public class SessionServlet extends HttpServlet {
   public void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
     ServletContext context = getServletContext();
     HttpSession session = request.getSession(true);
     response.setContentType("text/html");
     PrintWriter out = response.getWriter();
     out.println("<HTML><HEAD><TITLE>Servlet Demo</TITLE></HEAD><BODY>");
     if (session.isNew()) {
       out.println("<FORM ACTION=SessionServlet>" +
       "Enter your name: <INPUT NAME=handle>" +
       "<INPUT TYPE=SUBMIT></FORM>");
       session.putValue("state", "1");
     } else {
       String state = (String) session.getValue("state");
       if (state.equals("1")) {
         String name = (String) request.getParameter("handle");
         int users = ((Integer) context.getAttribute("users")).intValue() + 1;
         context.setAttribute("users", new Integer(users));
         session.putValue("name", name);
         out.println("Hello " + name + ", you are user number " + users);
         session.putValue("state", "2");
       } else /* state.equals("2") */ {
         String name = (String) session.getValue("name");
         out.println("Goodbye " + name);
         session.invalidate();
       }                                            session management
     }
     out.println("</BODY></HTML>");                 state management
 }
   }
GPCE 2003, Erfurt
                                                    document construction
                            Dynamic Generation of XML            September 22, 2003
Conciseness (<bigwig>)
 service {
   shared int users = 0;

     session Hello() {
       string name;
       show [[Enter your name: <input name=handle>]] receive[name=handle];
       users++;
       show [[Hello <[who]>, you are user number <[count]>]] <[who=name,count=users];
       show [[Goodbye <[who]>]] <[who=name];
     }
 }




GPCE 2003, Erfurt            Dynamic Generation of XML            September 22, 2003
Conciseness (<bigwig>)
  service {
    shared int users = 0;

      session Hello() {
        string name;
        show [[Enter your name: <input name=handle>]] receive[name=handle];
        users++;
        show [[Hello <[who]>, you are user number <[count]>]] <[who=name,count=users];
        show [[Goodbye <[who]>]] <[who=name];
      }
  }

400
                                                      session management
300                                                   state management
200                                                   document construction
                                                      misc.
100
  0
                                                          Overall: 1/5 code
           Servlets          <bigwig>

 GPCE 2003, Erfurt            Dynamic Generation of XML            September 22, 2003
The <bigwig> Compiler

• Version 2.0:
        • Implemented in C (for UNIX / Linux)
        • Complete source code available
              – Approximately 2.5 MB source              HTML

                                                       JavaScript
           Complete
            Service               <bigwig>            CGI Scripts
          Specification
                                                      HTTP Auth.

                                                      Java Applets

• License: GPL (Gnu Public License)
 GPCE 2003, Erfurt        Dynamic Generation of XML         September 22, 2003
http://www.brics.dk/bigwig/
• Homepage:
  – Introduction
  – Examples
  – Ref. manual
  – Tutorials
  – Papers
  – Presentations
  – Downloads:
     • src / bin
  – 2 Recorded Presentations (MS & IBM Research)
 GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
<bigwig> Publications
•    Concurrency Control         ETAPS/FASE,                    1998
•    Runtime System              Computer Networks J.,          1999
•    Dynamic Documents           POPL,                          2000
•    Form-Field Validation       WWW Journal,                   2000
•    HTML Validation             PASTE,                         2001
•    The <bigwig> Project        TOIT Journal,                  2002
•    Syntax Macros               PEPM,                          2002
•    Document Caching            WWW Journal,                   2002




    GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
<bigwig>                         JWIG (Java)



       http://www.brics.dk/JWIG/




GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003
                    Thank you!




GPCE 2003, Erfurt   Dynamic Generation of XML   September 22, 2003