Reform Java Web Template Technology - FASTM

zhaozj2021-02-16  61

Reform Java Web Template Technology - FASTM

1. "Simple is beautiful" is anxious (ring)

In the field of software design, there is a famous saying that the famous name is simple.

Almost all masters of software design will be trained in their works:

"Simple and beautiful",

"Keep IT Simple, Stupid",

"Less is more",

... ..

This is a good voice, everyone will say.

But in fact, this is also the most widely used in violation of it.

"Simple is beautiful" this truth is like heaven, everyone says heaven, but everyone is desperate to delay the time to arrive at paradise.

In general, software development technologies have always become more complicated and increasingly huge.

Let's see the development history of Java Web performance layer technology.

(1) First, servlet is born. Web programmers are very happy, I feel that it is much more cool than CGI.

(2) After a while, people think that HTML is too unhappy in the Java program. After all, in HTML, static text tags account for most, and the dynamic display part is just a small part. It is better to write Java code in HTML. So JSP was born. Become a strong competitor of ASP.

(3) After a while, people think that HTML and Java code are mixed together, not only the page structure is poor, but the Java code is difficult to maintain. This is the famous "Java Code Poll" problem. It is better to replace Java code with custom XML elements, so that the entire page is XML. So, taglib appeared.

(4) There is still a problem, Taglib cannot be displayed in a general HTML browser or editor, the page cannot be seen. The ASP.NET is quickly visible to the advantages of developing, and is being taught in the Web Development field. Java world rush to fight, start JSF projects. A large number of Web Framework camps has an authoritative heavyweight player.

Various new concepts have endless, and the page process is more complicated.

It is said that this is to reduce development difficulty, so that the programmer only focuses on business logic, not to care about the underlying technical details; it is said to be an enterprise application, and the demand for enterprise applications is complex, so the simple problem is complicated It is reasonable - it is said that this is for the systematic facing expandability, scalable ...

This is an era of mythology, which is a concept of negative manufacturing.

Deep thinking, I think the complex trend of technology, maybe it is the commercial market for commercial demand?

There are two types of driving force in new technologies:

(1) The first driving force is to solve the true problem.

For example, the appearance of servlet is to solve the problem of spatial time consumption of CGI. More than CGI, servlet is a new idea, an alternative technology.

The new technologies caused by the first driving force are relatively long, not sufficient to maintain people's technical needs.

(2) The second driving force is to make up for the shortcomings of the previous technique.

Complex technologies have some shortcomings, so it creates domestic demand for the next technological innovation. Moreover, the more complex technology, the more inadequate, the technology "innovation" (or "repair" more suitable?) Domestic demand and business opportunities are, forming a technical "repair" industry chain of self-produced sales.

For example, the emergence of JSP is to assist in generating servlet; and Taglib's appearance is to make up for the lack of JSP; the Taglib visualization plug-in is to make up for the shortcomings of Taglib. The business opportunities are unlimited, and a large number of technical vendors that offer a variety of Taglib and Taglib visual plugins, the technology market is booming. The new technique of this second driving force is relatively short, and the children of the children will be unfusited, and there is no broken.

But I firmly believe that the technology will return to the true.

One day, we will return to the road that really solves the problem, rather than continuing a road to technology "repair replenishment".

2. The birth of FASTM - "Simple is the beauty" king returned

The Java World is an open world. I think it is because of this, the majority of Java programmers must not leave this Java development camp.

Java.sun.com announced all Java technical specifications.

Apache.org Open Source Community has attracted a lot of programmers to join the Java development camp.

SourceForge.net provides a larger programmer (not only Java), providing space for communication, sharing, and development.

It is because such openness has promoted the unprecedented development of Java development technology.

It is also because of this openness, forming a Java Web performance layer technology group.

In the field of Java Web performance layer, JSP TAGLIB page technology is authority and standard, but this area does not exclude other technologies.

As mentioned above, JSP Taglib is not perfect, so it has the inherent demand for development.

At the same time, this also has prompted people to continue to explore, compare other technical possibilities.

All levels of the Web performance layer - O / R layer, business layer, web framework, etc. are directly implemented by Java code, which can be well structured, objective, and there is no problem. Only the Web performance layer, the natural structure is loose, and the wild is hard.

I am a Java WebApp programmer, has always worked hard to do the same structured, objectivity. For two or three years, I have applied, studies, compared a variety of web performance layer technology:

(1) velocity http://jakarta.apache.org/Velocity/ (and Webmacro, FreeMarker .. etc)

(2) TapeStry http://jakarta.apache.org/tapestry/

(3) echo http://sourceforge.net/projects/echo

(4) Cocoon (XML XSLT) http://cocoon.apache.org/

(5) XMLC (Static Dom) http://xmlc.enhydra.org/

(6) Nekohtml (Dynamic Dom) http://www.apache.org/~andyc/neko/doc/html/

(7) JDYNAMITE (PHP Template Port) https://sourceforge.net/projects/jdynamite

Through research comparisons, I found the "Source" in template technology - the logic code contained in the template (IF, Else, For, assignment, operation, call, etc.).

These logic code contained in the template is the natural enemies developed by "what you see", and it is also the first culprit to destroy the reuse.

JSP Taglib, Velocity, TapeStry, XSLT, etc. are all logical templates. If there is no special plugin, these templates cannot be properly displayed correctly in a normal HTML browser or editor. Moreover, the logic of mixed in HTML is no way to reuse; you cannot separate these logic into general methods or classes.

JDynamite is an open source project that transplants PHP template technology to Java. JDYNAMITE Template Marks the Dynamic Block with the begin-end. Tag placed variables with the {}. The JDYNAMITE template does not contain any logic, which is a template technology that "WYSIWY", which is capable of correctly displayed in a normal HTML browser or editor.

XMLC and other DOM template techniques directly use the HTML file as a template, of course, the template technology of "what you get".

JDYNAMITE and XMLC is in common, and there is no logic in the template. All template processing logic (inspection judgment, node assembly, variable replacement, etc.) are completed in the code.

Although these two techniques have separated from the template definitions, they do not completely separate the logic and data from the template.

Let's take a look at the usage of HTML DOM in XMLC technology. A HTML DOM just generated, or a pure template. However, the program directly changes the node data of the HTML DOM, and even change the position and quantity of the node. This HTML DOM can no longer be used as a pure template, let alone multiple threads in multithreaded environments. At the same time. Think about it, in a static text accounting for most DOM structures, this practice will cause how big space and time.

JDYNAMITE usage has the same performance problem as XMLC.

I think how to solve this performance defect. Finally, on the basis of JDynamite, PHP, and DOM, I created the concept of Template Dom and ValueSet DOM. From the usage, further data and logic thoroughly from the template. Separate. Thus, the FASTM open source project was born.

3. Small, fast, simple, easy, strong "silver bomb" - FASTM

FASTM has an unparalleled superiority of other pages generation techniques:

What you have come, easy to learn, fast development, small running space, fast running speed, complete separation of template and data, multi-to-many free matching data.

FASTM is the best template technology from all aspects - the fastest, minimum, most easy to use, the most flexible and powerful (very flexible with pure servlet / JSP). I expect FASTM page generation methods to better solve the web page generation problem and can be popular in the world's Java web programmers.

Is it just self-selling self-selling self-selling?

This is easy to distinguish: FASTM is a fully open source project, a trial. Due to FASTM's ideas, implementation and usage easy to understand, this trial can't spend any time.

FASTM truly proves that "simple, beautiful". Let me explain the FASTM ideas and usage.

3.1 FASTM template is a lightweight DOM

Like the PHP template, the FASTM template contains only three elements:

(1) Static text.

(2) Place a variable. Use the {} sign.

(3) Dynamic block. Use the begin-end dynamic logo.

Among them, the dynamic block can contain other elements - sub-dynamic blocks, placeholders, static text. Therefore, the FASTM template is a tree structure, which is equivalent to a lightweight DOM structure. Behind We call this structure as a Template DOM. The following is a simple example. For example, the HTML piece below.

[code]

Dynamic block Zipcodes - | --- Static text

PT

ion value = "| --- Variable {zipcode} | --- static text"> | --- Variable {zipcode} | --- Static text

PT

ION> Static Text [/ Code]

It seems that FASTM Template Dom is not very special. But Template DOM has a vital feature - read-only and cannot be changed. Since only read only, of course, the thread is safe, the same template DOM can be used concurrently by multiple threads simultaneously.

So how do we get dynamic pages from read-only Template Dom? We must load dynamic data into a ValueSet DOM structure (also a tree structure), then match the Template DOM with this ValySet DOM to generate dynamic results. 3.2 Template DOM VALUESET DOM = DYNAMIC RESULT

Template DOM contains three elements nodes: static text nodes, variable assignment nodes, dynamic block nodes. Due to the statically text node does not need to be assigned, ValueSet DOM only contains two element nodes-variable assignment nodes, and dynamic block assignment nodes. Wherein, the dynamic block assignment node can include sub-dynamic block assignment nodes and variable assignment nodes. Therefore, ValueSet DOM is a tree structure corresponding to the dynamic part of the Template DOM.

The node correspondence between the Template DOM and ValueSet DOM is as follows: The Template DOM variable node and the ValueSet DOM variable assignment node are one-on-one relationship. There is a pair of relationships between the dynamic block nodes of the Template DOM and the dynamic block assignment nodes of ValueSet DOM, which is to make dynamic blocks multiple times in the page.

Let's construct a ValueSet Dom for the Template DOM structure (Zipcode Select).

String [] zipcodes = {"361005", "100008"};

IvalueSet Top = new valueSet (); // Corresponding to the entire HTML piece list items = new arraylist (); // corresponds to dynamic part zipcodes for (int i = 0; i

We combine TOP this VALUESET DOM and Template DOM. Generate the following results.

[code]

CopyRight © 2020 All Rights Reserved
Processed: 0.039, SQL: 9