14.1 The Tea Language

Java Servlet Programming, 2nd Edition > 14. The Tea Framework > 14.1 The Tea Language

 
< BACKCONTINUE >

14.1 The Tea Language

Tea is a programming language designed for text formatting. It is strongly typed, compiled, and designed to work within a Java-based hosting environment. The TeaServlet is that hosting environment, making use of Tea for web page creation and providing a standard hook into servlet engines with which to call Tea template files.[1]

[1] Although Tea was designed for text formatting, it's actually possible for a Tea template to control an image-producing application class and easily script together a dynamic image. Unlike other content creation tools we'll discuss, Tea templates may output binary data as well as character data.

The main goal of the Tea language is to enforce separation between content and presentation, without sacrificing basic programming constructs. To this end, Tea was created with four basic constraints:

  • Data or datatypes cannot be directly created; they are acquired.

  • Acquired data cannot be directly modified in any way.

  • A template cannot directly cause harm to its hosting environment.

  • Only the minimum amount of programming constructs is provided.

These constraints additionally protect the system from a buggy or poorly written template, something that's extremely desirable when you have a site accepting new templates by the dozen, as occurs on popular news sites. This design also benefits web hosting companies that need to provide clients with the ability to create dynamic pages but don't want any particular client's mistake to negatively impact the rest of the server.

But do we need another language, especially a language that does less than Java? The Tea Template Language Manual answers this question:

Tea resulted from several years of experience with other web page building mechanisms. Most web-based applications start out with HTML tags embedded in code, whether it be C, Perl, or Java. This approach is adequate for small or first-time projects because it doesn't take very long to develop.

Because changes to page formatting can occur frequently, and developers don't wish to make these changes, they inevitably evolve into using some kind of token replacement templating mechanism. Each token is just a placeholder for a string, which contains application-created data. These template systems further evolve into supporting special constructs for formatting tables, forms, and simple conditional logic.

When introducing programming constructs into a template, the challenge is to come up with something that is powerful enough, yet at the same time be simple and safe. If it's too powerful, then complete applications could be developed in templates. If it is too weak, then HTML formatting ends up in the application. If it isn't simple or safe, then application developers end up writing and maintaining templates.

Rather than embedding an existing language into something like an ASP or JSP, Tea is a language specially designed to meet the requirements of a templating system. It is safe, simple, efficient, and powerful.

In one instance, Tea is integrated with a special servlet. This servlet gives Tea templates control over page building, while retaining strong ties to a backend application written by a Java developer. While this servlet provides functionality similar to that of JSPs, Tea enforces correct model-view separation because of the intentional language limitations. Although this is also the suggested separation model in JSPs, it cannot be enforced. In addition, Tea templates don't support programming features that can be used irresponsibly. Modifications need not go through a strict review and testing phase, which would still be required for JSPs.

Everyone working on a project should be empowered to do their job the most effectively, and Tea does its part by letting you do exactly what you need, as easily as possible, and no more. Even on projects run by just developers, using Tea is still beneficial. It encourages good development practices and it makes applications easier to maintain.

Readers of this book should also remember, Tea isn't a language intended for you; it's a language to be used by technical producers. It's a simpler language than Java, a safer language than Java, and equally as efficient as Java.


Last updated on 3/20/2003
Java Servlet Programming, 2nd Edition, © 2001 O'Reilly

< BACKCONTINUE >


Java servlet programming
Java Servlet Programming (Java Series)
ISBN: 0596000405
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net