Design method and device of extensible GUI markup document rendering framework

文档序号:1127738 发布日期:2020-10-02 浏览:19次 中文

阅读说明:本技术 一种可扩展的gui标记文档渲染框架的设计方法及装置 (Design method and device of extensible GUI markup document rendering framework ) 是由 贾金刚 于 2020-06-12 设计创作,主要内容包括:本发明提供一种可扩展的GUI标记文档渲染框架的设计方法及装置,所述方法包括如下步骤:收集编写通用语言的代码所提供的标记语言的信息;将收集的标记语言的信息进行转换处理;根据转换处理后的信息生成标记语言文档。根据收集到的HTML信息建构AST结构;对AST结构进行相关的处理和转换,生产新的AST结构;根据新的AST结构中所包含的信息,生成HTML文档。可扩展的GUI标记文档渲染框架,在提供类型安全和灵活的表达能力的基础上,同时保持了类似与标记语言文档的声明式语法,比较适合编写UI代码,还能大幅提高开发者的生产力。(The invention provides a method and a device for designing an extensible GUI markup document rendering framework, wherein the method comprises the following steps: collecting information of a markup language provided by writing codes of a common language; converting the collected information of the markup language; and generating a markup language document according to the information after the conversion processing. Constructing an AST structure according to the collected HTML information; carrying out relevant processing and conversion on the AST structure to produce a new AST structure; an HTML document is generated based on the information contained in the new AST structure. The extensible GUI markup document rendering framework maintains the declarative grammar similar to markup language documents on the basis of providing type safety and flexible expression capability, is more suitable for compiling UI codes and can also greatly improve the productivity of developers.)

1. A design method of an extensible GUI markup document rendering framework is characterized by comprising the following steps:

collecting information of a markup language provided by writing codes of a common language;

converting the collected information of the markup language;

and generating a markup language document according to the information after the conversion processing.

2. The method of claim 1, wherein the step of collecting information in a markup language provided by writing code in a common language is preceded by the step of:

when the code of the general language is written, the information of the mark language is expressed; wherein, the common language comprises Java and C #;

the markup language includes HTML.

3. The method of claim 2, wherein the information of the markup language comprises elements, attributes of the elements, attribute values, and nested structures between the elements.

4. The method of claim 3, wherein the step of collecting markup language information provided by writing code in a common language comprises:

information of a markup language provided by writing code of a general language is collected through a visitor mode or a listener mode.

5. The method of claim 4, wherein the collecting markup language information provided by writing a code in a common language by a listener mode comprises:

writing Java codes and defining all HTML document elements by using Java language;

writing HTML information by using an instance initialization statement block of Java language;

and calling a toString method of each element to generate an HTML document.

6. The method of claim 4, wherein the step of converting the collected markup language information comprises:

constructing an AST structure according to the collected HTML information;

and performing relevant processing and conversion on the AST structure to generate a new AST structure.

7. The method of claim 4, wherein the step of generating a markup language document based on the converted information comprises:

an HTML document is generated based on the information contained in the new AST structure.

8. The method of claim 6, wherein the step of performing the associated processing and transformation on the AST structure to generate the new AST structure comprises:

deleting and combining the nested levels of the HTML elements;

converting HTML elements customized by a user into standard HTML elements;

and converting the elements in the old version of HTML standard into new HTML elements added in the new version of HTML standard to generate a new AST structure.

9. A design device of an extensible GUI markup document rendering framework is characterized by comprising an aggregator, a converter and a generator;

the assembler is used for collecting information of a markup language provided by writing codes of a general language;

the converter is used for processing and converting according to the information of the markup language collected by the aggregator;

and a generator for generating a markup language document according to the information converted by the converter.

10. The apparatus of claim 9, wherein the transformer is further configured to construct an AST structure according to the collected HTML information; and the AST structure is processed and converted correspondingly to generate a new AST structure.

Technical Field

The invention relates to the technical field of program development and design, in particular to a method and a device for designing an extensible GUI markup document rendering framework.

Background

Markup languages are represented by HTML, XAML, JSX, etc., and have the advantage of declarative syntax, ease of understanding and writing, and are well-suited for designers to use to design UIs. Meanwhile, the defects are very obvious, the mark language is not a general programming language, complex operation logic cannot be flexibly expressed, and the mutual operation with Java is inconvenient; for developers, markup languages are not type-safe, are not convenient for code reconstruction, and manage both Java and markup language documents simultaneously.

In back-end development, HTML documents are typically generated by means of a template language, and such a technique is represented by Thymeleaf et al. Java code is embedded in the template, so that the expression capability is greatly enhanced, and the interoperability of the template and the Java language is greatly improved. With the same considerations, in front-end development, template languages such as JSX are also heavily relied on to build UI components.

In the current development process, a developer needs to manage various code assets such as Java, template documents, JavaScript, JSX and the like at the same time, and although the template documents can partially relieve the defect of insufficient expression capability of HTML documents, the burden of the developer cannot be reduced fundamentally.

Disclosure of Invention

The invention provides a design method and a device of an extensible GUI document rendering framework, aiming at the problems that in the current development process, developers need to manage various code assets such as Java, template documents, JavaScript, JSX and the like at the same time, and although the template documents can partially relieve the defect of insufficient expression capability of HTML documents, the burden of the developers cannot be reduced fundamentally.

The technical scheme of the invention is as follows:

in one aspect, the present invention provides a method for designing an extensible GUI markup document rendering framework, comprising the steps of:

collecting information of a markup language provided by writing codes of a common language;

converting the collected information of the markup language;

and generating a markup language document according to the information after the conversion processing.

Preferably, the step of collecting information of a markup language provided by writing code of a common language further comprises: when the code of the general language is written, the information of the mark language is expressed; wherein, the common language comprises Java and C #; the markup language includes HTML.

Preferably, the information of the markup language includes elements, attributes of the elements, attribute values, and nested structures between the elements.

Preferably, the step of collecting information of a markup language provided by writing code of a common language includes:

information of a markup language provided by writing code of a general language is collected through a visitor mode or a listener mode. The visitor mode means that the information processor actively acquires and processes the relevant information, and the information processor actively PULLs (PULL) the information from the information source. The listener mode indicates that the relevant information is passively acquired and processed, and the information source PUSH (PUSH) information is generally implemented by an event mechanism.

Preferably, the listener mode collects information of a markup language provided by writing codes of a common language, and the method includes the specific steps of:

writing Java codes and defining all HTML document elements by using Java language;

writing HTML information by using an instance initialization statement block of Java language;

and calling a toString method of each element to generate an HTML document.

Preferably, the step of converting the collected information of the markup language includes:

constructing an AST structure according to the collected HTML information; the AST structure is used for representing some intermediate form of HTML information before the HTML document is generated, and comprises all information required for generating the HTML document;

carrying out relevant processing and conversion on the AST structure to generate a new AST structure;

the step of generating the markup language document according to the converted information is: an HTML document is generated based on information contained in the converted new AST structure.

Preferably, on the premise of not influencing the UI appearance presented by the final HTML document, firstly, a series of conversions are carried out on the AST structure; the step of performing relevant processing and conversion on the AST structure to generate a new AST structure specifically includes:

deleting and combining the nested levels of the HTML elements;

converting HTML elements customized by a user into standard HTML elements;

and converting the elements in the old version of HTML standard into new HTML elements added in the new version of HTML standard to generate a new AST structure.

Preferably, the method specifically includes reading information in the AST structure by the visitor mode, performing related processing and conversion on the AST structure, generating a new AST structure, and generating an HTML document according to information included in the new AST structure, wherein the method specifically includes:

defining information required by all HTML document elements in Java;

collecting the information provided in the previous step and constructing an AST structure;

the information provided by the JavaBean is used to convert its data into an HTML document.

In another aspect, the present invention further provides a design apparatus of an extensible GUI markup document rendering framework, comprising an assembler, a transformer, and a generator;

the assembler is used for collecting information of a markup language provided by writing codes of a general language;

the converter is used for processing and converting according to the information of the markup language collected by the aggregator;

and a generator for generating a markup language document according to the information converted by the converter.

Preferably, the converter is further configured to construct an AST structure according to the collected HTML information; and the AST structure is processed and converted correspondingly to generate a new AST structure.

According to the technical scheme, the invention has the following advantages: the extensible GUI identification document rendering framework maintains the similar declarative grammar with the markup language document on the basis of providing type safety and flexible expression capability, is suitable for compiling UI codes, and can greatly improve the productivity of developers.

In addition, the invention has reliable design principle, simple structure and very wide application prospect.

Therefore, compared with the prior art, the invention has prominent substantive features and remarkable progress, and the beneficial effects of the implementation are also obvious.

Drawings

In order to more clearly illustrate the embodiments or technical solutions in the prior art of the present invention, the drawings used in the description of the embodiments or prior art will be briefly described below, and it is obvious for those skilled in the art that other drawings can be obtained based on these drawings without creative efforts.

FIG. 1 is a schematic flow diagram of a method of one embodiment of the invention.

Fig. 2 is a schematic flow diagram of a method of another embodiment of the invention.

Detailed Description

In order to make those skilled in the art better understand the technical solution of the present invention, the technical solution in the embodiment of the present invention will be clearly and completely described below with reference to the drawings in the embodiment of the present invention, and it is obvious that the described embodiment is only a part of the embodiment of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

The terms appearing in the present invention are explained below:

abstract Syntax Tree (AST): an abstract syntax tree;

viristor pattern: a visitor mode;

the observer pattern: a listener mode;

instance association block (IIB): instance initialization statement blocks;

object Initializer (OIS): an object initial value setting item;

collection Initializer (CIS): setting items of an initial value are collected;

as shown in fig. 1, an embodiment of the present invention provides a method for designing an extensible GUI markup document rendering framework, including the following steps:

s1: collecting information of a markup language provided by writing codes of a common language;

s2: converting the collected information of the markup language;

s3: and generating a markup language document according to the information after the conversion processing.

The general programming languages are represented by C, Java and C #, etc., and the patent document mainly uses Java to illustrate the intention of the present invention, but does not represent that the present invention is limited to Java technology. The representative markup languages include HTML, XAML, JSX and the like, the patent mainly uses HTML to explain the purpose of the invention, but does not represent that the invention is only limited to HTML technology;

all information for generating the HTML document is contained in the Java code, and specifically includes elements, attributes of the elements, attribute values, and nested structures between the elements.

It should be noted that in some embodiments, the information of the markup language provided by writing the code of the common language is collected by the visitor mode or the listener mode. The visitor mode means that the information processor actively acquires and processes the relevant information, and the information processor actively PULLs (PULL) the information from the information source. The listener mode indicates that the relevant information is passively acquired and processed, and the information source PUSH (PUSH) information is generally implemented by an event mechanism.

Collecting information of a markup language provided by writing codes of a common language through a listener mode, the method comprising the specific steps of:

(1) writing Java codes and defining all HTML document elements by using Java language;

some examples are given below:

head section of HTML

As an example, a commonly used title element is defined.

Then the head element is defined.

The body part of the html first defines the parent classes required below.

class Element{

String text;

}

Then, as an example, a commonly used div element is defined.

Figure BDA0002537066280000091

Finally, the body element is defined.

Figure BDA0002537066280000101

Root node of HTML

Figure BDA0002537066280000102

(2) Writing HTML information by using an instance initialization statement block of Java language; if C # language is used, OIS/CIS can be used instead;

an example of writing HTML information using the elements defined in (1) above:

Figure BDA0002537066280000111

(3) and calling a toString method of each element to generate an HTML document.

Figure BDA0002537066280000121

As shown in fig. 2, in some embodiments, the step of converting the collected markup language information further includes:

s21: constructing an AST structure according to the collected HTML information; the AST structure is used for representing some intermediate form of HTML information before the HTML document is generated, and comprises all information required for generating the HTML document;

s22: carrying out relevant processing and conversion on the AST structure to generate a new AST structure; in step S3, an HTML document is generated based on the information contained in the new AST structure.

It should be noted that, on the premise of not affecting the UI appearance presented by the final HTML document, a series of conversions are first made to the AST structure; the step of performing the related processing and conversion on the AST structure specifically includes:

deleting and combining the nested levels of the HTML elements; converting HTML elements customized by a user into standard HTML elements; and converting the elements in the old version HTML standard into new HTML elements added in the new version HTML standard to generate a new AST structure.

In some embodiments, the relevant information is provided by annotations, and the annotations in Java (annotation) and the properties in C # (attribute) are declarative syntax, by which metadata can be added to the program and collected; the method specifically comprises the following steps of reading information in an AST structure through a visitor mode, carrying out relevant processing and conversion on the AST structure, generating a new AST structure, and generating an HTML document according to the information contained in the new AST structure, wherein the method specifically comprises the following steps:

(a) defining information required by all HTML document elements in Java;

JavaBean required for defining table element

The javabeans required by the tr element and the td element are defined first.

Finally defining the JavaBean required by the table element.

(b) Collecting the information provided in step (a) and constructing an AST structure; obtaining relevant information provided in the last step through a field, getDeclearAnnoutations () and other relevant reflection (reflection) APIs in Java to construct an AST structure;

(c) the information provided by the JavaBean is used to convert its data into an HTML document.

The backend is now largely using the Spring Framework to develop Java programs, and in a typical Spring MVC project, a Controller (Controller) would return data javabeans. To further simplify the development process, these java beans can be annotated as in step (a), then the return value of the controller is intercepted using a mechanism such as a filter of Spring Framework, and then the generator automatically converts its data into an HTML document using the information provided by the java beans.

The development of the era is continuous, the HTML standard is continuously updated, various differences exist among browsers, and the various details are considered to bring heavy burden to developers. The generator of the invention is used for generating the HTML document according to the AST structure, and can convert according to a certain rule during working to take care of the details, thereby reducing the burden of a developer. This conversion process is very extensive.

An input control (input) of datatime-local type is defined in the HTML standard, and the chrome browser supports this control, but the Firefox browser currently displays it as a normal input control. Taking this control as an example, how to accommodate different browsers by the extension generator will be described below.

(i) Acquiring a browser used by a current visitor:

the browser request typically includes browser information in header information UA, which can be obtained by http server. The UA of the Firefox browser contains Mozilla typeface to determine whether the current browser needs special processing.

(ii) The conversion is done by the extended rules:

if the current browser is Firefox, the generator finds all the datatime-local type input controls in the AST structure, converting them to one datatype input control plus one time type input control. After all the conversions are performed, the HTML document is generated again, so that the Firefox browser can well show the user with the input control.

The embodiment of the invention also provides a device for designing the extensible GUI markup document rendering framework, which comprises an aggregator, a converter and a generator;

the assembler is used for collecting information of a markup language provided by writing codes of a general language;

the converter is used for processing and converting according to the information of the markup language collected by the aggregator;

and a generator for generating a markup language document according to the information converted by the converter.

It is further noted that the converter is further configured to construct an AST structure according to the collected HTML information; and the AST structure is processed and converted correspondingly to generate a new AST structure.

Although the present invention has been described in detail by referring to the drawings in connection with the preferred embodiments, the present invention is not limited thereto. Various equivalent modifications or substitutions can be made on the embodiments of the present invention by those skilled in the art without departing from the spirit and scope of the present invention, and these modifications or substitutions are within the scope of the present invention/any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.

14页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种磁卡数据的处理方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!