360 likes | 512 Views
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.
E N D
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.
Tea download from sourceforge • Tea is open source. Go to • http://sourceforge.net/project/showfiles.php?group_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
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.
Kettle is an editing environment for creating tea applications (select:file/new)
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...
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>
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 }
Jazzing it up…. <% template SimplePage(String name) %> This is a simple page that does nothing special except show a name: <% name %> <P> <% if (name == null) { "You gave a null name" } if (name == "Slim Shady") { "Please stand up" } %>
You can use the admin tool to check compile errors…note errors in text code Snoop
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
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.
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.
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.
When you add a template to your directory you can request the admin tool to recompile all
clicks displays date and percentage with French locale setting
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.
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() %>.
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 }
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.
More examples: another get name example comes with distribution
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. */%>
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.
Read(file)App context file public 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; }}
Display file with url:http://localhost:8080/tea/tea/contents?name=c:/progra~1/tomcat~1.5/webapps/tea/contents.txt
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.
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