Enforcing Strict Model- View Separation in Template Engines Terence Parr University of San Francisco

Slides:



Advertisements
Similar presentations
ASP.NET Intro An introduction to the languages and communication of an ASP.NET system.
Advertisements

The Role Of Template Engines in Code Generation Terence Parr University of San Francisco
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
ECE122 L4: Creating Objects February 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
Solutions for XML Document Navigation and Delivery Lori Wong and T.R. Girill Customer Services Group Services and Development Division Integrated Computing.
CSE 190: Internet E-Commerce Lecture 17: XML, XSL.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
XML CS 105. What is XML? XML stands for Extensible Markup Language. XML is a markup language like HTML. XML was designed to describe data. You must define.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Chapter 4 Database Management Systems. Chapter 4Slide 2 What is a Database Management System (DBMS)?  Database An organized collection of related data.
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
StringTemplate Terence Parr University of San Francisco
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
XML and XSL Institutional Web Management 2001: Organising Chaos.
Creating Databases for Web Applications Work session Open Source versus Proprietary important topics HW: finish* projects. Look at final quiz guide. Final.
“Enhancing Reuse with Information Hiding” ITT Proceedings of the Workshop on Reusability in Programming, 1983 Reprinted in Software Reusability, Volume.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Types for Programs and Proofs Lecture 1. What are types? int, float, char, …, arrays types of procedures, functions, references, records, objects,...
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
DSpace UI Alexey Maslov. DSpace in general A digital library tool useful for storage, maintenance, and retrieval of digital documents Two types of interaction:
® IBM Software Group © 2007 IBM Corporation J2EE Web Component Introduction
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
CubicWeb – The Semantic Web is a construction game! Student: Uglješa Milić University of Belgrade School of Electrical.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Case Study + MVC Lec Error Pages By means of the page directive, a JSP can be given the responsibility of an Error page An Error JSP will be called.
Symfony web development framework is used to develop rapid, complex and large scale web applications faster and in an effective way.
HTML: Hyptertext Markup Language Doman’s Sections.
Cohesion and Coupling CS 4311
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
Chapter 2 An Overview of Servlet and JSP Technology.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.
Overview of Form and Javascript fundamentals. Brief matching exercise 1. This is the software that allows a user to access and view HTML documents 2.
Documentation Costs Avoided using Python and other Open Standards Andrew Jonathan Fine Operating Systems Software Organization Engines, Systems, and Services.
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
The Evolution of the StringTemplate Engine Presented to the UC Berkeley Harmonia group 15 December 2004 Terence Parr University of San Francisco
Chapter 8 Specialization aka Inheritance. 2 Inheritance  Review of class relationships  Uses – One class uses the services of another class, either.
Chapter 8 Inheritance. 2  Review of class relationships  Uses – One class uses the services of another class, either by making objects of that class.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
IT Accessibility Committee XML as Content Management Presented by Michael B. Short May 11, 2006 Prepared by the NYS Forum IT Accessibility Committee
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
JSP / Servlets and Beans
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
JAFER Toolkit Project Oxford University 1 JAFER Java-based high level Z39.50 toolkit Matthew Dovey; Colin Tatham; Antony Corfield; Richard Mawby Oxford.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
C++ First Steps.
Types for Programs and Proofs
11.1 The Concept of Abstraction
Towards Automatic Model Synchronization from Model Transformation
Presentation transcript:

Enforcing Strict Model- View Separation in Template Engines Terence Parr University of San Francisco

Dynamic Pages out.println(" "); out.println(" Servlet test "); String name = request.getParameter("name"); out.println("Hello, "+name+"."); out.println(" "); JSP test Hello,. Note: XSLT is not a template mechanism Servlet: JSP:

Example Entanglements $if(user==“parrt” && machine=“yoda”)$ $if(user==“parrt” && machine=“yoda”)$ $price*.90$, $bloodPressure>130$ $price*.90$, $bloodPressure>130$ $a=db.query(“select subject from ”)$ $a=db.query(“select subject from ”)$ $model.pageRef(getURL())$ $model.pageRef(getURL())$ $ClassLoader.loadClass(somethingEvil)$ $ClassLoader.loadClass(somethingEvil)$ $names[ID]$ $names[ID]$ st.setAttribute(“color”, “Blue”); st.setAttribute(“color”, “Blue”);

Motivation For Separation Encapsulation Encapsulation Clarity Clarity Division of labor Division of labor Component reuse Component reuse Single point-of-change Single point-of-change Maintenance Maintenance Interchangeable views Interchangeable views Security Security Note: these benefits all derive from single principle of separation

The Problem With Engines Web demands dynamic content, leading to rise of template engines Web demands dynamic content, leading to rise of template engines Goal: separate display from business logic Goal: separate display from business logic Problem: engines don’t enforce separation, they only encourage separation (Murphy, IBM keybrd, etc…) Problem: engines don’t enforce separation, they only encourage separation (Murphy, IBM keybrd, etc…) Reason: engine builders and users fear that enforcement implies fatal weakness Reason: engine builders and users fear that enforcement implies fatal weakness Result: developers exploit loopholes, encoding logic in templates, thus, entangling model/view Result: developers exploit loopholes, encoding logic in templates, thus, entangling model/view Situation partially due to lack of formal treatment: no def. of template nor separation Situation partially due to lack of formal treatment: no def. of template nor separation

My Proposition Separating logic from display is widely-accepted as a worthy goal (MVC pattern) Separating logic from display is widely-accepted as a worthy goal (MVC pattern) Enforcing the separation principle is better than encouraging its use Enforcing the separation principle is better than encouraging its use We can enforce separation without emasculating the power of a template engine We can enforce separation without emasculating the power of a template engine I have empirical evidence in the form of my StringTemplate engine and its use at jGuru, … I have empirical evidence in the form of my StringTemplate engine and its use at jGuru, … I have formally shown restricted templates generate sufficiently large language classes I have formally shown restricted templates generate sufficiently large language classes Herein, I motivate and define separation then illustrate use of StringTemplate Herein, I motivate and define separation then illustrate use of StringTemplate

Rules of Separation 1. the view cannot modify the model 2. cannot perform computations upon dependent data values 3. cannot compare dependent data values 4. cannot make type assumptions 5. data from model cannot contain display, layout information

Entanglement Index Equal to the number of separation rules an engine violates: 1..5 Equal to the number of separation rules an engine violates: 1..5 Undecidable rule (data cannot contain layout information) yields min index of 1 Undecidable rule (data cannot contain layout information) yields min index of 1 Slippery slope: engines are either 1 or 5 Slippery slope: engines are either 1 or 5

What you need Attribute reference: $name$ Attribute reference: $name$ Conditional include $if(title)$ $title$ $endif$ Conditional include $if(title)$ $title$ $endif$ Template references (possibly recursive): $navbar()$ Template references (possibly recursive): $navbar()$ Apply template to multi-valued attribute: $aList:{ $attr$ }$ or $aList:bold()$ Apply template to multi-valued attribute: $aList:{ $attr$ }$ or $aList:bold()$

StringTemplate: Fill Table $users:row()$ $attr.name$ $attr.age$ Boris 39 Natasha goal: page: row: page.setAttribute("users", list); public class User { String name; int age;... }

MVCR Pattern How do you escape ‘<‘ to be ‘<’? Model/controller may not escape a priori and template cannot scan/replace How do you escape ‘<‘ to be ‘<’? Model/controller may not escape a priori and template cannot scan/replace Clearly must be code somewhere, but if not in M, V, or C then where? Clearly must be code somewhere, but if not in M, V, or C then where? Silent partner at work already where escaping should live: renderer, an aspect embodied by all attribute toString methods Silent partner at work already where escaping should live: renderer, an aspect embodied by all attribute toString methods View: layout. Renderer: convert binary to char View: layout. Renderer: convert binary to char Ex: view says where/color, renderer says (10) vs -10 Ex: view says where/color, renderer says (10) vs -10 Solution: controller wraps attributes with objects from an HTMLRenderer package, for example Solution: controller wraps attributes with objects from an HTMLRenderer package, for example

Summary Most engines do not enforce separation, a worthy goal; they support constructs that allow violations, fearing lack of power Most engines do not enforce separation, a worthy goal; they support constructs that allow violations, fearing lack of power Programmers use these constructs as expedients Programmers use these constructs as expedients I provide empirical evidence and formal arguments demonstrating that the ideal is possible: strict separation and a potent engine I provide empirical evidence and formal arguments demonstrating that the ideal is possible: strict separation and a potent engine Engines no longer have an excuse to support entanglement of model and view Engines no longer have an excuse to support entanglement of model and view StringTemplate embodies principles described herein: StringTemplate embodies principles described herein:

But wait! There’s more! New! StringTemplate 2.0b1 brings a lot including group file format, useful for source-to-source translation New! StringTemplate 2.0b1 brings a lot including group file format, useful for source-to-source translation group javaTemplates; method(type,name,args,body) : << public ( ) { } >> assign(lhs,expr) : “ = ;” if(expr,stat) : “if ( ) ” call(name,args) : “ ( );” …