The Tea framework Developed by Disney as a way to separate logic from presentation.

36
The Tea framework Developed by Disney as a way to separate logic from presentation
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    224
  • download

    8

Transcript of The Tea framework Developed by Disney as a way to separate logic from presentation.

Page 1: The Tea framework Developed by Disney as a way to separate logic from presentation.

The Tea framework

Developed by Disney as a way to separate logic from presentation

Page 2: The Tea framework Developed by Disney as a way to separate logic from presentation.

There are many application frameworks…• http://www.lowensystems.com/javasoftware.htm

• Application frameworks• Frameworks give a structure to the development of new applications: • Struts

– An MVC framework. • Avalon

– Framework for designing components and services, adhering to a set of design patterns. Aimed at server-side development. Used by Cocoon 1 and 2, James, and others.

• Cocoon 1 and Cocoon 2 – A servlet-based publishing platform built with Avalon. Developer and user mailing lists.

Includes XSP and ESQL logic tags (and more), XML/XSL support via Xalan/Xerces. The OPP demo was programmed in 4 days by a novice, in an ACS way: creation of a set of independent pages calling various APIs, without any thick Avalon service/module. This approach seems suitable and very efficent, for small projects.

• Turbine – A servlet-based framework.

• JBoss – An EJB container and framework.

• Open Symphony – An EJB-based framework.

• ACS Java – Currently in 4.6, which is mainly about lower-layers of the architecture. – Documentation: doc, business doc, and UML.

Page 3: The Tea framework Developed by Disney as a way to separate logic from presentation.

Tea download from sourceforge

• Tea is open source. Go to• http://sourceforge.net/project/showfiles.php?grou

p_id=43867• Download kettle, teaservlet, bean-doc, teatrove.• There is also a pdf tutorial and manual at:• http://teatrove.sourceforge.net/docs/

TeaServletTutorial.pdf• http://teatrove.sourceforge.net/docs/

TeaServletUserManual.pdf

Page 4: The Tea framework Developed by Disney as a way to separate logic from presentation.

TeaServlet classes add functionality to httpservlet

com.go.teaservlet Interface ApplicationResponse

All Superinterfaces: javax.servlet.http.HttpServletResponse,

javax.servlet.ServletResponse

public interface ApplicationResponse

extends javax.servlet.http.HttpServletResponse

An ordinary HttpServletResponse, but with additional operations specific to the TeaServlet.

Page 5: The Tea framework Developed by Disney as a way to separate logic from presentation.

Kettle is an editing environment for creating tea applications (select:file/new)

Page 6: The Tea framework Developed by Disney as a way to separate logic from presentation.

A sample tea page (note url mapping from web.xml)

Page 7: The Tea framework Developed by Disney as a way to separate logic from presentation.

Files and directories

• Couldn’t get it to work until I put the TeaServlet.jar file in lib (not in com.go.teaserlvet…)

• I used the text web and properties files with my own paths

• My SimplePage.tea file:

<%template SimplePage() %>

This is a sample tea test page...

Page 8: The Tea framework Developed by Disney as a way to separate logic from presentation.

web.xml file <servlet-class> com.go.teaservlet.TeaServlet </servlet-class> <init-param> <param-name> properties.file </param-name> <param-value> <!-- Edit this to be an absolute path to your prop file --> c:/progra~1/tomcat~1.5/webapps/tea/WEB-INF/TeaServlet.properties <!-- /TeaServlet.properties--> </param-value> </init-param> </servlet> <servlet-mapping> <servlet-name> tea </servlet-name> <url-pattern> /tea/* </url-pattern> </servlet-mapping>

Page 9: The Tea framework Developed by Disney as a way to separate logic from presentation.

Properties file from the tea distribution# TeaServlet properties.# Path to locate Tea templates, in .tea files.template.path = c:/progra~1/tomcat~1.5/webapps/tea/WEB-INF/templates# Optional path to write compiled templates, as .class files.template.classes = ./templateClasses# Applications to load into the TeaServlet.applications { "System" { # The SystemApplication provides TeaServlet # administration support. class = com.go.teaservlet.AdminApplication init { # The security key for the Admin page. admin.key = admin admin.value = true }

log { debug = true info = true warn = true error = true } } "NameApp"{ class=NameApp }

Page 10: The Tea framework Developed by Disney as a way to separate logic from presentation.

Jazzing it up….<% template SimplePage(String name) %>This is a simple page that does nothing specialexcept show a name: <% name %><P>

<%if (name == null) { "You gave a null name"}if (name == "Slim Shady") { "Please stand up"}%>

Page 11: The Tea framework Developed by Disney as a way to separate logic from presentation.
Page 12: The Tea framework Developed by Disney as a way to separate logic from presentation.

The administration tool: note url

Page 13: The Tea framework Developed by Disney as a way to separate logic from presentation.

You can use the admin tool to check compile errors…note errors in text code Snoop

Page 14: The Tea framework Developed by Disney as a way to separate logic from presentation.

Compiling and editing using the admin tool

• Tea does not reload templates until they correctly compile… until then it uses the old version.

• There are quite a few java-syntax related errors in the code for snoop.tea but using the compiler they weren’t hard to fix

Page 15: The Tea framework Developed by Disney as a way to separate logic from presentation.

Recompiling all templates

Page 16: The Tea framework Developed by Disney as a way to separate logic from presentation.

Snoop with errors fixed and cookie info cut

Page 17: The Tea framework Developed by Disney as a way to separate logic from presentation.

Compiled Templates

• Since templates can be precompiled a web app using tea can be shipped without shipping the source. Unlike JSP there are no container classes. JSP also has container specific tags and uses container-specific name-mangling.

Page 18: The Tea framework Developed by Disney as a way to separate logic from presentation.

How tea works

• Templates call functions and a template may access any function (or bean property) in any application installed into the TeaServlet via the properties file.

• Functions may accept parameters and return values.

• The admin screen shows a list of all functions from all installed applications.

• Templates can prefix function names to qualify them in order that collision doesn’t occur.

Page 19: The Tea framework Developed by Disney as a way to separate logic from presentation.

How tea works

• The text lists pages of text processing, content handling and request-response handling functions. (pages 434-435)

• The usual servlet request functions are there plus lots more.

Page 20: The Tea framework Developed by Disney as a way to separate logic from presentation.

When you add a template to your directory you can request the admin tool to recompile all

Page 21: The Tea framework Developed by Disney as a way to separate logic from presentation.

clicks displays date and percentage with French locale setting

Page 22: The Tea framework Developed by Disney as a way to separate logic from presentation.

directories

webapps

tea

webinf

lib

classes

properties (file)

Templates

templateclasses

etc

Web.xml

Page 23: The Tea framework Developed by Disney as a way to separate logic from presentation.

An application

• As with conventional servlets you’ll have to compile tea application and context files.

• You’ll have to make sure com.go.teaservlet.* is in the class path for your compiler.

• Classes generated by java compile go in the classes sub-directory of webapps/thiswebapp/WEB-INF.

• You have to add a reference to the application in the properties file.

Page 24: The Tea framework Developed by Disney as a way to separate logic from presentation.

The nameapp working

Page 25: The Tea framework Developed by Disney as a way to separate logic from presentation.

About this app• There will be two files, a context file and an app file.• Any template can access the application, once successfully

deployed.• In this case, the names() template calls the application’s getName

function:<% template names() %>

<%setContentType("text/plain")nullFormat("Unknown")%>

Your name is <% getName() %>.

Page 26: The Tea framework Developed by Disney as a way to separate logic from presentation.

About this app

• The NameApp tries to find the user’s name from a cookie, a parameter, or by calling request.getRemoteUser(). If all fail, null is returned and “your name is unknown” is displayed.

• In the screenshot above I provided a parameter.• Add the following code to the properties file to

complete deployment of NameApp:“NameApp”{Class=NameApp}

Page 27: The Tea framework Developed by Disney as a way to separate logic from presentation.

A couple of tea applications come with the distribution

• As in the previous example, tea application includes an App.java and a Context.java file, as well as some .tea templates.

• The java files need to be compiled and put into the classes directory.

• your properties file needs to be updated. (The tea distribution also comes with a sample .properties)

• The tea template files need to be dropped into the templates directory.

Page 28: The Tea framework Developed by Disney as a way to separate logic from presentation.

BrowserSampleApp

Page 29: The Tea framework Developed by Disney as a way to separate logic from presentation.

More examples: another get name example comes with distribution

Page 30: The Tea framework Developed by Disney as a way to separate logic from presentation.

HelloSample.tea<% template HelloSample() myName = getName()%>Hello <%myName%><%/* It should be noted that this template is overkill and the HelloSampleApp in general is unnecessary except for demonstration purposes. The ability to retrieve query string parameters is already included in the teaservlet. For example: <% template SimpleHelloSample(String name)%> Hello <%name%> would do the same thing without even having to write a tea application.*/%>

Page 31: The Tea framework Developed by Disney as a way to separate logic from presentation.

http://teatrove.sourceforge.net/docs/TeaServletTutorial.pdf

• The pdf has explanations on how to use the kettle IDE (I did not use it) and also more examples. But since they are in pdf format it is not a handy site from which to cut and paste.

• The old Tea URL, http://opensource.go.com is no longer working.

Page 32: The Tea framework Developed by Disney as a way to separate logic from presentation.

Read(file)App context filepublic class ReadContext { ApplicationRequest request; ApplicationResponse response; String filecontents; public ReadContext(ApplicationRequest request, ApplicationResponse response) { this.request = request; this.response = response; } public String getFileContents() { BufferedReader br=null; FileReader fr=null; String filename = request.getParameter("name"); try { fr=new FileReader(filename); br=new BufferedReader(fr); String line=null; while((line=br.readLine())!=null) filecontents=filecontents+"<p>"+line+"</p>"; } catch (IOException e) { filecontents="error"+e.toString(); //throw new ServletException(e); } return filecontents; }}

Page 33: The Tea framework Developed by Disney as a way to separate logic from presentation.

Display file with url:http://localhost:8080/tea/tea/contents?name=c:/pro

gra~1/tomcat~1.5/webapps/tea/contents.txt

Page 34: The Tea framework Developed by Disney as a way to separate logic from presentation.

The ToolsApp

• This tea application uses a tea app file, a tea context file as well as a java class Tools which builds a jdom (tree) from a tools.xml file. This tree structure is used for display purposes in the tea application

• For compilation, you will need jdom, teaservlet and trove in your classpath.

Page 35: The Tea framework Developed by Disney as a way to separate logic from presentation.

Unfortunately…• Although I found a link on sourceforge for the teaservlet jar file, the

trove jar file wasn’t there. I couldn’t find it.• The trove source directory comes with a build tool to create this jar

file… it uses jdk1.3 and because of changes since then, some files won’t compile in jdk1.5

• I was able to use the buildtool to create a jar file com.go.trove.trove.jar but I had to download the jdk1.3 and do some minor editing of the batch files setenv.bat and build.bat

• (This is a pretty nice tool and could probably be used in more general context to create jar files from directories with many java source files.)

• Now I have the com.go.trove.trove.jar file if you want it.• For some reason, my jdom.jar was corrupted or incomplete, so it

took a while to get all the jdom stuff where it was supposed to go. (There is a build tool, which I used, for jdom.jar

Page 36: The Tea framework Developed by Disney as a way to separate logic from presentation.

The (tea) ToolApp: pretty nice display, huhn?