FASTM design idea depth analysis
1. PHP (& FASTM) cuts documents as simple DOM structure
The design idea of the PHP template is very beautiful, and the HTML (WML, or any XML) page is cut into different blocks in the comments, and the block can also be cut in the block.
In this way, a page is cut into a tree structure, very like a DOM structure. Only the DOM structure is too cumbersome, and a node is established for each element, and the type of node is very complicated. For example, an HTML DOM structure, how many HTML elements, how many node types, such as Body, Table, Tr, TD, Form, Input, etc.
The PHP template is a lightweight DOM structure, and a begin-End block is a node. Begin-End block only includes three contents - static text, variables, and other Begin-End blocks.
Design ideas is so simple and powerful, easy to use (can be used in any specification or irregular XML page, such as HTML, WML, Eye XUL, XAML, and can be seen in the HTML editor. Throughout the world template technology, it is not right.
I have passed a variety of Java page technology torture, and I have known PHP template technology. I am very happy. It turns out such a good thing. I hate it too late.
The idea of the FASTM template is completely drawn on the PHP template idea, just have some extensions. (For details, please refer to my previous article - JDYNAMITE - A Summary of the Java Page Technology).
The BEGIN-End Dynamic block of the FASTM template is equivalent to the Begin-End block of the PHP template.
The BEGIN-End Ignored block of the FASTM template is equivalent to the BEGIN-END block that is ignored by the PHP template.
For example, the HTML piece below.
PT
ION value = "{zipcode}"> {zipcode} o
PT
ION>
select>
We see that this piece contains a begin-end block (zipcodes), which contains two identical variables {state}, and other parts are static text.
The Fastm Template DOM structure of this piece is as follows:
Static text Dynamic block Zipcodes - | --- Static text
PT
ion value = "| --- Variable {zipcode} | --- static text"> | --- Variable {zipcode} | --- Static text O
PT
ION> Static Text SELECT> 2. FASTM's ValueSet is a core feature of the DOM concept. The core feature of the FASTM template DOM structure is that it can only be read and cannot be changed. PHP code is loaded each time a PHP template and then dynamically replaces the value of the variable portion in the inside. The PHP template is essentially readable and can operate. This is even more likely to HTML (WML, XML) DOM. The program directly modifies the value of the DOM node to get different dynamic results. It can be said that XML DOM is born is used to operate changes. The XML DOM itself is template and is data.
The DOM structure that can be changed cannot be used in a multi-threaded environment. Each thread must obtain your own fresh DOM backup, perform changes to your own dynamic results. Think about it, in a static text accounting for most DOM structures, this practice will cause how big space and time.
The DOM structure of the FASTM template is read-only and cannot be changed. So a FASTM DOM can be used in a multi-threaded environment. Since we can't change FASTM Template Dom, how do we assign a FASTM TEMPLATE DOM? How do we use FASTM TEMPLATE DOM to get dynamic results? FASTM introduced the concept of the ValueSet. ValueSet is a dynamic data set of a tree structure that matches a read-only FASTM template DOM structure to generate dynamic results. The programmer must construct the entire tree dynamic dataset in advance, then combine the VALUESET DOM and FASTM TEMPLATE DOM to generate dynamic results.
Therefore, FASTM's entire use of the following: (1) During the entire run of the program, the FASTM template file (that is, the html file added to the begin-end annotation) only needs to be parsed once, generating a FASTM Template DOM. (FASTM template resolution is fast, compiled by JSP, Velocity resolution, XML DOM parsing, very fast, most of the situation even faster than SAX resolution. And the size of FastM Dom and the original FASTM template file is almost as big, only more A List records different blocks, spatial efficiency also have high outgoing) (2) The program generates different ValueSet Doms, matching read-only FASTM DOM, generates different dynamic results. (Because the FastM Template DOM structure is simple and efficient, the entire matching process is very fast. Usually, time efficiency is even higher than the fastest pure JSP or servlet.valueset DOM's spatial efficiency is less than pure JSP or servlet, but is reasonably reuse At least close to the spatial efficiency of the pure JSP or Servlet. The following advanced application topics will explain this problem in detail.)
For example, we come to 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.
PT
ION value = "361005"> 361005 o
PT
ION>
PT
ION Value = "10008"> 100008 o
PT
ION>
select>
We can see that the Template DOM node and the ValueSet DOM node are not one-to-one correspondence, but a couple of relationships. A Template DOM node corresponds to a ValueSet List. How many ValueSets contain each of the VALUESET LISTs, which showcases the Template DOM node.
Compared to taglib, the advantage of FASTM is obvious. A few lines of FASTM, or a method that enables one or several Taglib functions. Compared to any other page technology, other page technology can do, or good, FASTM can do, and do better. FASTM can do things that many other page technology do. All right. Not much to say. J
The separation of Valueset Dom and Template DOM is a great idea innovation and leap.
After all, the dynamic part of the page, and static comparison, is a very small part. Valueset DOM represents the dynamic part, generated by the program, there can be multiple copies. Template DOM represents a static part and only needs to be analyzed once and only one copy is needed.
The separation of Valueset Dom and Template DOM is a unprecedented display and data separation. More thorough than XML / XSLT. XML is indeed pure data, but inevitable in XSLT should include logic. ValueSet Dom is pure data, without any logic, Template Dom is a pure display template, nor is there any logic.
A Template DOM can assign a value with multiple ValueSet Dom. Similarly, a ValueSet DOM can also be used in a plurality of Template DOMs, display the same data in different styles of templates.
For example, we have such an HTML piece:
{zipcode} td> tr>
TABLE>
We assigned the top valueset to this template. The result obtained is as follows.
361005 TD> 100008 TD> tr> table> We can see that Template DOM is template, only display Style and block definition. ValueSet DOM is data and contains only data. FASTM has other page generation techniques uncomfortable superiority: the time you have obtained, the template and data is completely separated, the template and data are more free to match, easy to use, fast development, small running space, fast running speed. As far as my personal feeling, FASTM is simply solving a silver bomb that solves all page technology issues.
Some of the above may be "self-selling boasts", the special explanation is as follows: I am not a person who is good at boasting. Otherwise, I have long been engaged in salesman and public relations. And due to the lack of self-sales capabilities and social relations, it has caused its own ability, energy and time. I am painful, but I don't regret it. I understand the rules of the game, but I have no ability, I don't want, disdainful. There is always an infatuation, I hope to create a miracle outside the existing rules. In addition, I am an objective truthful and clear, and the mind has a responsible academic spirit "exogenous and unvermnation, inner can't take a son. There is a point, let's say a point, I will never say a point, and I will never say a little one.
3. FastM's reusability of reusability is Valueset Dom
The core of the reusability of JSP technology is TAGLIB. The core of XML DOM is the common operation of the DOM node.
The core of FASTM's reusability is a general purpose operation of the ValueSet DOM node. For example, the paragraph that is speaking above generates the code of the ValueSet. The Template DOM itself can be used as a read-only template, and like the Template DOM includes any Template DOM structure that can be used as a separate read-only template. This is the same as XML DOM. Any one of the XML DOM can be used as a separate node.
ValueSet DOM is not only the core of data reuse, but also the central template assembly reuse. FASTM realizes the handling assembly of each block between the templates, and it is easy. Implement a so-called Tile function, a snatch.
JSP, there are some representations that represent logic Taglib, Velocity Templates, XSL files, are templates that contain logic. Personally, the template contains logic, is a very ridiculous behavior. The length of the template is the performance page layout, the style, not logic. Why not let the Java to deal with the logic? In FASTM, there is no logic in the Template Dom and ValueSet DOM. All logic fall in the Java code. Java is a highly object-oriented language that is structural and reused in any template language that cannot be comparable. Therefore, the core of FASTM's reusability is the common operation of the ValueSet DOM node. The code for these general operations is of course implemented by Java.
转载请注明原文地址:https://www.9cbs.com/read-6617.html