FASTM design idea depth analysis

zhaozj2021-02-12  187

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.

Dynamic block Zipcodes - | --- Static text

PT

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

PT

ION> Static Text 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.

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