CN113568622A - Method and device for converting codes and electronic equipment - Google Patents

Method and device for converting codes and electronic equipment Download PDF

Info

Publication number
CN113568622A
CN113568622A CN202110900202.1A CN202110900202A CN113568622A CN 113568622 A CN113568622 A CN 113568622A CN 202110900202 A CN202110900202 A CN 202110900202A CN 113568622 A CN113568622 A CN 113568622A
Authority
CN
China
Prior art keywords
file
java
code
extensible markup
folder
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110900202.1A
Other languages
Chinese (zh)
Inventor
张洋
张雪
王建辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology Co Ltd
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC, ICBC Technology Co Ltd filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202110900202.1A priority Critical patent/CN113568622A/en
Publication of CN113568622A publication Critical patent/CN113568622A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/76Adapting program code to run in a different environment; Porting

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The disclosure provides a method and a device for converting codes and electronic equipment, which are applied to the fields of Internet of things or finance and the like. The method is used for converting codes supported by a first program into codes supported by a second program, wherein the first program comprises a first extensible markup language file and a Java file, and the first extensible markup language file comprises a structured query language code, and the method comprises the following steps: acquiring a first extensible markup language file and a Java file; and reconstructing the structured query language code by an extensible markup language analysis method, and reconstructing the Java code in the Java file by a template generation method to obtain a folder of the second program, wherein the folder of the second program comprises the reconstructed structured query language code and the reconstructed Java code.

Description

Method and device for converting codes and electronic equipment
Technical Field
The present disclosure relates to the field of internet of things and financial technologies, and in particular, to a method and an apparatus for converting codes, and an electronic device.
Background
Some companies run programs developed based on dynamic web page development technology (such as Java Server Pages, JSP for short) on a production environment, and the JSP technology is a technology in which front and back ends are not separated. However, the separation of the front end and the back end can effectively reduce the pressure of the server and help to reduce the development difficulty.
In carrying out the disclosed concept, the applicant has found that there are at least the following problems in the related art: the transplantation cost between the program developed based on the JSP technology and the program developed by the existing front-end and back-end separation technology is high.
Disclosure of Invention
In view of the above, the present disclosure provides a method, an apparatus, and an electronic device for transcoding to reduce migration costs between a program developed based on JSP technology and a program developed by an existing front-end and back-end separation technology.
One aspect of the present disclosure provides a method of converting code for converting code supported by a first program into code supported by a second program, wherein the first program includes a first extensible markup language file and a Java file, the first extensible markup language file including structured query language code, the method comprising: acquiring a first extensible markup language file and a Java file; and reconstructing the structured query language code by an extensible markup language analysis method, and reconstructing the Java code in the Java file by a template generation method to obtain a folder of the second program, wherein the folder of the second program comprises the reconstructed structured query language code and the reconstructed Java code.
According to an embodiment of the present disclosure, the first extensible markup language file includes a business statement and a template statement, and the business statement and the template statement are capable of generating a structured query language code; reconstructing structured query language code by an extensible markup language parsing method includes: respectively analyzing the business statement and the template statement by using an extensible markup language file analyzer to obtain an analysis result; and generating a second extensible markup language file aiming at the analysis result according to the persistent format requirement, and generating a Java file corresponding to the second extensible markup language file under the data access object folder.
According to the embodiment of the disclosure, the service statement and the template statement are respectively analyzed by using an extensible markup language file analyzer, and the analysis result is obtained by: traversing and analyzing template sentences according to the file, wherein the template sentences are sentences obtained by analyzing the first extensible markup language file; traversing and analyzing the business sentences according to the files, and storing the template sentences and the business sentences in a mapping set in a correlation manner; and jointly analyzing the business statement and the template statement to obtain a reconstructed structured query language code.
According to an embodiment of the present disclosure, generating the second extensible markup language file for the parsing result according to the persistence requirement format includes: and storing the reconstructed structured query language code as a second extensible markup language file meeting the requirement of the persistent format.
According to an embodiment of the present disclosure, generating a Java file corresponding to the second extensible markup language file under the data access object folder includes: and aiming at each second extensible markup language file meeting the requirement of the persistent format, generating a Java file corresponding to the second extensible markup language file meeting the requirement of the persistent format under the data access object folder.
According to the embodiment of the disclosure, reconstructing the Java code in the Java file by the template generating method includes: the Java code is parsed to generate Java files in the service folder, and Java files corresponding to the Java files in the service folder are generated in the program interface folder.
According to an embodiment of the present disclosure, parsing the Java code to generate the Java file in the service folder includes: traversing and analyzing Java files in the first program according to files; converting the calling method of the structured query language code in the Java file in the first program into a method corresponding to the calling method of the structured query language code under a data access object folder; and generating the Java file in the service folder based on the method corresponding to the calling method of the structured query language code.
According to an embodiment of the present disclosure, generating a Java file in a program interface folder corresponding to a Java file in a service folder includes: after at least one Java file is generated in the service folder, a Java file corresponding to the Java file in the service folder is generated in the program interface file.
According to an embodiment of the present disclosure, the method further includes: after the Java file in the service folder is generated, the Java file in the service folder is modified in response to a user operation.
An aspect of the present disclosure provides an apparatus for converting code, for converting code supported by a first program into code supported by a second program, wherein the first program includes a first extensible markup language file and a Java file, and the first extensible markup language file includes structured query language code, the apparatus comprising: the device comprises a file acquisition module and a code reconstruction module. The file acquisition module is used for acquiring a first extensible markup language file and a Java file; the code reconstruction module is used for reconstructing the structured query language codes through an extensible markup language analysis method and reconstructing the Java codes in the Java file through a template generation method to obtain a folder of the second program, and the folder of the second program comprises the reconstructed structured query language codes and the reconstructed Java codes.
Another aspect of the present disclosure provides an electronic device comprising one or more processors and a storage device, wherein the storage device is configured to store executable instructions, which when executed by the processors, implement the method as above.
Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions for implementing the above method when executed.
Another aspect of the disclosure provides a computer program comprising computer executable instructions for implementing the method as above when executed.
Drawings
The above and other objects, features and advantages of the present disclosure will become more apparent from the following description of embodiments of the present disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an exemplary system architecture of a method, apparatus, and electronic device to which transcoding may be applied, according to embodiments of the present disclosure;
FIG. 2 schematically illustrates a flow diagram of a method of transcoding according to an embodiment of the present disclosure;
FIG. 3 schematically illustrates a flow diagram of a method of restructuring structured query language code in accordance with an embodiment of the present disclosure;
FIG. 4 schematically illustrates a block diagram of an XML parser in accordance with an embodiment of the present disclosure;
FIG. 5 schematically shows a flow chart of a method of generating a Java file in a service folder according to an embodiment of the present disclosure;
fig. 6 schematically illustrates a block diagram of a freemaker according to an embodiment of the disclosure;
FIG. 7 schematically illustrates a block diagram of an apparatus for transcoding according to an embodiment of the present disclosure; and
FIG. 8 schematically shows a block diagram of an electronic device according to an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). The terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more features.
In order to facilitate understanding of the embodiments of the present disclosure, a description will be first given of a part of concepts related to the present disclosure.
A Transmission Control Protocol (TCP) is a connection-oriented, reliable transport layer communication Protocol based on byte streams. TCP is intended to accommodate layered protocol hierarchies that support multiple network applications.
The hypertext Transfer Protocol (HTTP) is a simple request-response Protocol that typically runs on top of TCP.
Java is an object-oriented programming language, not only absorbs various advantages of C + + language, but also abandons concepts such as multi-inheritance and pointers which are difficult to understand by C + + force, so that the Java language has two characteristics of strong function, simplicity and easiness in use. Java has the characteristics of simplicity, object-oriented property, distribution, robustness, safety, platform independence and portability, multithreading, dynamicity and the like.
JavaScript, JS for short, is a lightweight, interpreted or just-in-time programming language with function preference.
Extensible Markup Language (XML) is a subset of standard universal Markup languages, and is used for Markup electronic documents to make them have a structural Markup Language.
The JS Object Notation (JSON for short) is a lightweight data exchange format. It stores and represents data in a text format that is completely independent of the programming language.
A Representational State Transfer, RESTFUL for short, is a design style and development mode of a network application program, and XML format definition or JSON format definition can be used based on HTTP.
Application Programming Interface (API), which is a predefined Interface (such as function, HTTP Interface) or a convention for linking different components of a software system.
Front end and back end separation: the front end may refer to a web server responsible for returning user page information. The backend may refer to an application server, which is responsible for processing the business logic. The front end And the back end are separated, which means that a Hyper Text Markup Language (HTML) page at the front end calls a RESTFUL API interface at the back end through Asynchronous JavaScript And XML (Asynchronous JavaScript And XML And HTML, AJAX for short) And uses JSON data for interaction.
JSP: the full name Java Server Pages is a dynamic webpage development technology, and Java codes are inserted into an HTML webpage by using JSP tags. The technology is a technology with front and back ends not separated, and the front end and the back end are not different.
spring: the method is an open-source lightweight Java back-end development framework and has two core characteristics of reverse control and section orientation. The method is mainly used for back-end service development.
Some companies are now running programs written using JSP technology on production environments. These procedures are basically technically old, have a poor idea and are difficult to maintain. But if the new technology is used for reconstructing the programs written based on the JSP technology, the time and labor are wasted, and the cost is high. For example, the JSP technology development system is basically incompatible with the existing front-end and back-end separated development system, and the migration cost is high. The JSP code can be reconstructed into the spring code in a manual reconstruction mode through manpower in the related art, and therefore the requirement of operators for both the JSP technology and the spring technology is required, and high requirements are put on programming literacy of the operators. For example, the operator needs to analyze the code of the JSP system before performing manual reconstruction. Such a method not only needs a great amount of labor cost, but also is easy to generate program defects (bugs) in the reconstruction process, resulting in economic losses.
In the related art, the mainstream code conversion method mainly depends on manual operation to realize the reconstruction from the JSP code to the spring code, and the defects include the following steps.
For example, the degree of automation is low: the code reconstruction can be carried out only by manpower, which wastes time and labor. Business knowledge needs to be known, and reconstruction efficiency is not high.
For example, the operator demands are high: the reconstruction work can be carried out only by proficient JSP and front-and-back end separation technology by operators, and the requirements on the operators are high.
For example, there is a problem of malfunction: the manual operation may cause problems due to subjective recognition by a human, and the like, and the problems also need to be solved by consuming manpower.
In summary, many companies have not been motivated to reconstruct JSP code.
To at least partially ameliorate the above pain points, embodiments of the present disclosure provide a method, apparatus, and electronic device for transcoding. The method for converting the codes comprises a file acquisition process and a code reconstruction process. And in the file acquisition process, acquiring a first extensible markup language file and a Java file. And entering a code reconstruction process after the file acquisition process is finished, reconstructing the structured query language code by using an extensible markup language analysis method, and reconstructing the Java code in the Java file by using a template generation method to obtain a folder of a second program, wherein the folder of the second program comprises the reconstructed structured query language code and the reconstructed Java code.
The method, the device and the electronic equipment for converting the codes effectively overcome the defect that the JSP codes are complicated and difficult to reconstruct, provide a technical scheme which is efficient, convenient and fast and can automatically reconstruct the JSP codes into the spring codes, effectively improve the reconstruction efficiency and quickly convert the simple and clear JSP codes into the spring codes.
The method, the device and the electronic device for converting the codes provided by the embodiments of the present disclosure can be used in the field of internet of things in the aspects related to code conversion, and can also be used in various fields other than the field of internet of things, such as the financial field.
Fig. 1 schematically illustrates an exemplary system architecture of an electronic device and method, apparatus, and device to which transcoding may be applied, according to embodiments of the present disclosure. It should be noted that fig. 1 is only an example of a system architecture to which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, and does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.
As shown in fig. 1, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 may include a plurality of gateways, routers, hubs, network wires, etc. to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with other terminal devices and the server 105 via the network 104 to receive or transmit information or the like, such as receiving Java files, transmitting code or the like. The terminal devices 101, 102, 103 may be installed with various communication client applications. Such as web browser applications, mapping-type applications, software development-type applications, banking-type applications, government-type applications, monitoring-type applications, search-type applications, office-type applications, instant messaging tools, mailbox clients, social platform software, and the like (by way of example only). For example, the user may perform transcoding using the terminal apparatus 101 or send a transcoding instruction to the server side, or the like.
The terminal devices 101, 102, 103 include, but are not limited to, smart phones, virtual reality devices, augmented reality devices, tablets, laptop portable computers, desktop computers, etc. capable of using a web browser or client.
The server 105 may receive the request and process the request, and specifically may be a storage server, a background management server, a server cluster, or the like. For example, the server 105 may store a program developed based on JSP technology. For example, the server 105 may be used to run a transcoded program or the like.
It should be noted that the method for generating a message provided by the embodiment of the present disclosure may be generally executed by the terminal devices 101, 102, 103 or the server 105. Accordingly, the apparatus for generating a message provided by the embodiments of the present disclosure may be generally disposed in the terminal device 101, 102, 103 or the server 105. The method for generating a message provided by the embodiment of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks, and servers are merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
FIG. 2 schematically shows a flow diagram of a method of transcoding according to an embodiment of the present disclosure. The code conversion method is used for converting codes supported by a first program into codes supported by a second program, wherein the first program comprises a first extensible markup language file and a Java file, and the first extensible markup language file comprises structured query language codes.
As shown in fig. 2, the method of converting code may include operations S210 to S220.
In operation S210, a first extensible markup language file and a Java file are acquired.
In this embodiment, a Java folder and a first extensible markup Language (xml) file containing a Structured Query Language (SQL) statement may be obtained from a program installed in an electronic device. The program developed based on the JSP technology may include two types of folders: 1. an XML folder containing SQL statements. 2. A Java folder.
Various types of folders can be included in a program developed based on the spring technology: 1. and a program interface folder (e.g., controller folder) for storing the program interface. 2. A service type folder (e.g., a service folder) for storing the service-related code. 3. A Data Access Object (DAO) type folder (e.g., DAO folder, where each XML file in the XML folder generates a Java file in the DAO folder). 4. An extensible markup language type folder (e.g., an XML folder) for storing SQL statements.
In operation S220, the structured query language code is reconstructed by the xml parsing method, and the Java code in the Java file is reconstructed by the template generating method, so as to obtain a folder of the second program, where the folder of the second program includes the reconstructed structured query language code and the reconstructed Java code.
Specifically, the present embodiment includes two types of operations, on one hand, parsing and reconstructing SQL, and on the other hand, parsing and reconstructing Java. The program developed based on the JSP technology can be reconstructed into the spring program by combining the two types of operations. It should be noted that a small amount of manual processing may be required to operate during the conversion process.
For the characteristics of the JSP code, the JSP code is divided into two types, an XML file and a Java file in this embodiment, where an XML parsing method is used to reconstruct the SQL code and a template generation method is used to reconstruct the Java code. By the method, spring code engineering can be constructed quickly, a large amount of workload is saved, and various problems possibly introduced by manual reconstruction are reduced.
In some embodiments, the first extensible markup language file includes business statements and template statements, the business statements and template statements capable of generating structured query language code.
FIG. 3 schematically illustrates a flow diagram of a method of restructuring structured query language code in accordance with an embodiment of the disclosure.
As shown in FIG. 3, reconstructing the structured query language code by the extensible markup language parsing method may include operations S301 to S302.
In operation S301, the service statement and the template statement are respectively parsed by using an xml document parser to obtain parsing results. For example, the XML file parser may be a Dom4j, Dom, or the like parser. Dom4j is a Java XML application interface (API), and is an upgrade of jdom, which is used to read and write XML files.
In operation S302, a second extensible markup language file for the parsing result is generated according to the persistent format requirement, and a Java file corresponding to the second extensible markup language file is generated under the data access object folder.
For example, the persistent format requirement may be a format requirement of MyBatis, or the like. MyBatis is a persistent layer framework that supports customized SQL, stored procedures, and advanced mapping. MyBatis avoids almost all Java Database Connectivity (JDBC) code and manual setting of parameters and acquisition of result sets. MyBatis can use simple XML or annotations to configure and map native information, mapping interfaces and Java generic Java objects (POJOs) into records in the database.
In some embodiments, the above process may be implemented by an SQL parsing reconstruction module. For example, the SQL parsing and reconstruction module is based on XML parsing technology, using Dom4j (an XML parsing and generating tool) as a concrete implementation. Rewriting the XML file of the JSP into an XML file which can be read by mybatis (a persistence tool), and putting the XML file into an XML folder; and simultaneously, generating a Java file in a corresponding dao folder for matching with the XML file of mybatis.
Specifically, the SQL parsing and reconstructing module first traverses all XML files in a program developed based on the JSP technology. XML files in a program developed based on JSP technology are mainly divided into business statements and template statements, and the business statements and the template statements are combined to generate readable SQL statements. And respectively analyzing the business statement and the template statement by using Dom4j, and formatting and storing. And then, regenerating the XML file according to the format required by mybatis, and generating the Java file under the corresponding dao folder while generating the XML file.
FIG. 4 schematically illustrates a block diagram of an XML parser in accordance with an embodiment of the present disclosure.
As shown in FIG. 4, the XML parser may include a DOM class, a SAX class, and a JAXP class. The DOM classes can be parsed by a DOM4j parser or a DOM parser. The SAX class can be parsed by a SAX parser. In addition, JAXP can also be parsed by DOM and SAX parsers.
Dom4j is an open source XML parse package, and is a readily available, open source library for XML, XPath, and XSLT. The method is applied to a Java platform, adopts a Java set framework and completely supports DOM, SAX and JAXP.
Dom4j implements its functionality primarily based on the XML-DOM model. The main interfaces of Dom4j are all defined in org.dom4j. For example, Attribute Attribute defines the attributes of XML. Branch is a node such as an XML Element (Element) and a document that can contain child nodes.
In some embodiments, the parsing the business statement and the template statement separately by using the xml document parser, and obtaining the parsing result includes the following operations.
Firstly, traversing and analyzing template sentences according to files, wherein the template sentences are sentences obtained by analyzing a first extensible markup language file; and traversing and analyzing the business sentences according to the file, and storing the template sentences and the business sentences in a mapping set in a correlation manner.
And then, jointly analyzing the business statement and the template statement to obtain a reconstructed structured query language code.
XML parsing using Dom4j is exemplified below.
With respect to parsing an XML document.
Reading and writing the XML document mainly depend on the org.Dom4j.io packet, wherein two different modes of DOMReader and SAXReader are provided, and calling modes are called by interfaces.
Read XML from a File, enter the filename, return an XML document
public Document read(String fileName)throws MalformedURLException,DocumentException{
SAXReader reader=new SAXReader();
Document document=reader.read(new File(fileName));
return document;
}
The read method of the reader is overloaded, and can be read from various different sources such as InputStream, File, Url, and the like. The resulting Document object represents the entire XML.
The read character encoding is converted according to the encoding defined by the XML file header. If the problem of code confusion is encountered, the code names at all positions need to be kept consistent.
Next after reading, a Root node needs to be obtained.
public Element getRootElement(Document doc){
return doc.getRootElement();
}
Next, the XML tree is traversed.
Specifically, the nodes of the XML tree may be traversed by any of enumeration, recursion, and guest.
For example, 1. enumeration (Iterator).
V/enumerate all child nodes
for(Iterator i=root.elementIterator();i.hasNext();){
Element element=(Element)i.next();
//do something
}
// enumerate nodes named foo
for(Iterator i=root.elementIterator(foo);i.hasNext();){
Element foo=(Element)i.next();
//do something
}
// enumerate Properties
for(Iterator i=root.attributeIterator();i.hasNext();){
Attribute attribute=(Attribute)i.next();
//do something
}
E.g., 2. recursion.
Recursion may also employ Iterator as an enumeration means, but additional practices are provided in the document
public void treeWalk(){
treeWalk(getRootElement());
}
public void treeWalk(Element element){
for(int i=0,size=element.nodeCount();i<size;i++){
Node node=element.node(i);
if(node instanceof Element){
treeWalk((Element)node);
}else{//do something....
}
}
}
For example, 3.Visitor mode.
The DOM4J can greatly reduce the code amount by supporting the Visitor, and only one class needs to be customized to realize the Visitor interface.
public class MyVisitor extends VisitorSupport{
public void visit(Element element){
System.out.println(element.getName());
}
public void visit(Attribute attr){
System.out.println(attr.getName());
}
}
With respect to the invocation: accept (new MyVisitor ()).
The Visitor interface provides multiple heavy loads of Visit (), and different ways are adopted to access the object according to different XML objects. This Visitor is automatically traversed through all child nodes. If it is root.
Regarding the conversion of character strings and XML.
Sometimes string conversion to XML or vice versa is often used.
// XML-to-string
Document document=...;
String text=document.asXML();
// string to XML
String text=<name>James</name></person>;
Document document=DocumentHelper.parseText(text);
For example, transforming XML with XSLT
public Document styleDocument(
Document document,
String stylesheet
)throws Exception{
//load the transformer using JAXP
TransformerFactory factory=TransformerFactory.newInstance();
Transformer transformer=factory.newTransformer(
new StreamSource(stylesheet)
);
//now lets style the given document
DocumentSource source=new DocumentSource(document);
DocumentResult result=new DocumentResult();
transformer.transform(source,result);
//return the transformed document
Document transformedDoc=result.getDocument();
return transformedDoc;
}
Regarding creating XML.
Creating XML may be a job prior to writing a file.
public Document createDocument(){
Document document=DocumentHelper.createDocument();
Element root=document.addElement("root");
Element author1=
root
.addElement(author)
.addAttribute(name,James)
.addAttribute(location,UK)
.addText(James Strachan);
Element author2=
root
.addElement(author)
.addAttribute(name,Bob)
.addAttribute(location,US)
.addText(Bob McWhirter);
return document;
}
In some embodiments, generating the second extensible markup language file for the parsing result according to the persistence requirement format comprises: and storing the reconstructed structured query language code as a second extensible markup language file meeting the requirement of the persistent format. For example, an XML file stored as readable by mybatis
In some embodiments, generating the Java file corresponding to the second extensible markup language file under the data access object folder comprises: and aiming at each second extensible markup language file meeting the requirement of the persistent format, generating a Java file corresponding to the second extensible markup language file meeting the requirement of the persistent format under the data access object folder.
In one particular embodiment, restructuring the structured query language code is accomplished by the following operations.
Firstly, parsing XML template statements in JSP programs by using Dom4j according to file traversal, and storing the XML template statements in a map.
And then, traversing and analyzing the XML business statement in the JSP program according to the file.
And then, combining the XML business statement with the XML template statement in the first operation for joint analysis.
Then, the SQL statement parsed in step 2 is stored as an XML file readable by mybatis using Dom4j.
Next, each time an XML file is generated, a corresponding Java file is generated under the dao folder.
In some embodiments, reconstructing the Java code in the Java file by the template generation method may include: the Java code is parsed to generate Java files in the service folder, and Java files corresponding to the Java files in the service folder are generated in the program interface folder.
Specifically, the code generation based on the template method can be realized by a Java parsing reconstruction module. For example, Java code generation is performed using FreeMarker (a template code generation method). Similar to the SQL parsing method, the template method also needs to parse Java codes, parse the Java codes to generate Java files in the service folder, and generate a Java file in the controller folder correspondingly.
Fig. 5 schematically shows a flowchart of a method of generating a Java file in a service folder according to an embodiment of the present disclosure.
As shown in fig. 5, parsing the Java code to generate a Java file in the service folder may include operations S501 to S503.
In operation S501, a Java file in a first program is parsed by file traversal.
In operation S502, a method for calling a structured query language code in a Java file in a first program is converted into a method corresponding to the method for calling the structured query language code in a data access object folder.
In operation S503, a Java file in the service folder is generated based on a method corresponding to a calling method of the structured query language code.
For example, generating a Java file in the programmatic interface folder corresponding to a Java file in the service folder includes: after at least one Java file is generated in the service folder, a Java file corresponding to the Java file in the service folder is generated in the program interface file.
In some embodiments, the method may further include: after the Java file in the service folder is generated, the Java file in the service folder is modified in response to a user operation. Therefore, the adjustment requirements of complex scenes and the like can be met.
Fig. 6 schematically illustrates a block diagram of a freemaker according to an embodiment of the disclosure.
As shown in fig. 6, freemaker is a template engine that is a general tool for generating output text (HTML web pages, emails, configuration files, source code, etc.) based on templates and data that needs to be changed. It is not end-user oriented, but a Java class library, a component that can be embedded into the programs they develop.
The Template is written as Freemarker Template Language (FTL), a simple, proprietary Language. This means that the data is prepared for display in a real programming language, such as database queries and business operations, after which the template displays the data that has been prepared.
This pattern is commonly referred to as the MVC (model view controller) pattern, and is a mature pattern for dynamic web pages.
The working principle of which can be shown as follows.
Suppose that an HTML page is needed in an application as follows:
Figure BDA0003199493680000161
Figure BDA0003199493680000171
the username in the page (i.e., "XXBC" above) is the name of the visitor who logged into the page, and the data should come from the database to be updated at any time."XXBC", "greenxxx" and links cannot be directly entered in the HTML page, and static HTML code cannot be used. This can be solved using a template that requires output, the template being the same as the static page, and the template will contain some instruction for Freemarker to change it to dynamic content. Such as:
Figure BDA0003199493680000172
the template file is stored on a network (Web) server, when someone accesses the page, Freemarker is intervened to execute, then the template is dynamically converted, the latest data content is used for replacing the part $. The Web browser of the visitor will receive content such as the first HTML example (i.e., HTML code without FreeMarker instructions) and the visitor will not be aware of the FreeMarker used on the server side. It should be noted that the template file stored on the Web server side is not modified. The replacement only occurs in the response of the Web server.
The entirety of the data prepared for the template is referred to as the data model. The data model is a tree structure (e.g., folders and files of a tree topology).
For example, these values may be selected from the data model using the user and latestproduct. By analogy with the tree structure, the data model is like a file system, and the "(root)" and "latestProduct correspond to directories (folders), and the user, url, and name are the files in these directories.
In general, as shown in fig. 6, the template and data model are the components necessary for freemaker to generate output: template + data model is output.
In a particular embodiment, reconstructing the Java code may include the operations shown below.
Firstly, traversing and analyzing Java files in the JSP program according to files.
Then, the SQL calling method for analyzing the Java file in the previous operation is changed into the corresponding method under the dao folder.
Then, the content parsed out in the last operation is generated into a Java file under the service folder by using Freemarker, and customized improvement can be performed if special cases exist.
Then, each time a Java file under a service folder is generated, a Java file under a controller folder is correspondingly generated.
Through the combined application of the XML analysis method and the template generation method, the basic reconstruction from the JSP program to the spring program can be completed, and then the reconstruction work is completed under the manual adjustment.
According to the method, the device and the electronic equipment for converting the codes, provided by the embodiment of the disclosure, aiming at the problems of high cost, high error possibility and the like of manual code conversion, an XML analysis method and a template method are introduced to reconstruct an XML file and a Java file, so that an operator can get rid of a large amount of repeated time-consuming work, the labor is saved, the efficiency is improved, and the problem occurrence possibility is reduced. And a large amount of cost is saved for enterprises.
For example, by designing a whole set of JSP reconstruction process, the reconstruction of different JSP projects can be solved in a multiplexing and rapid manner.
For example, the XML file and the Java file are reconstructed by using an XML parsing method and a template method, so that the working efficiency is greatly improved, and the reconstruction cost is reduced.
For example, customized reconstruction can be performed on a special file, the mechanism is flexible, and reconstruction work is convenient to develop.
Another aspect of the present disclosure provides an apparatus for transcoding. The apparatus is used for converting code supported by a first program into code supported by a second program, wherein the first program comprises a first extensible markup language file and a Java file, and the first extensible markup language file comprises structured query language code.
Fig. 7 schematically illustrates a block diagram of an apparatus for transcoding according to an embodiment of the present disclosure.
As shown in fig. 7, the apparatus 700 for transcoding may include: a file acquisition module 710 and a code reconstruction module 720.
The file obtaining module 710 is configured to obtain a first extensible markup language file and a Java file.
The code reconstructing module 720 is configured to reconstruct the structured query language code by using an extensible markup language parsing method, and reconstruct the Java code in the Java file by using a template generating method to obtain a folder of the second program, where the folder of the second program includes the reconstructed structured query language code and the reconstructed Java code.
It should be noted that the implementation, solved technical problems, implemented functions, and achieved technical effects of each module/unit and the like in the apparatus part embodiment are respectively the same as or similar to the implementation, solved technical problems, implemented functions, and achieved technical effects of each corresponding step in the method part embodiment, and are not described in detail herein.
Any of the modules, units, or at least part of the functionality of any of them according to embodiments of the present disclosure may be implemented in one module. Any one or more of the modules and units according to the embodiments of the present disclosure may be implemented by being split into a plurality of modules. Any one or more of the modules, units according to the embodiments of the present disclosure may be implemented at least partially as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented by any other reasonable means of hardware or firmware by integrating or packaging the circuits, or in any one of three implementations of software, hardware and firmware, or in any suitable combination of any of them. Alternatively, one or more of the modules, units according to embodiments of the present disclosure may be implemented at least partly as computer program modules, which, when executed, may perform the respective functions.
For example, any number of the file obtaining module 710 and the code reconstructing module 720 may be combined and implemented in one module, or any one of the modules may be split into a plurality of modules. Alternatively, at least part of the functionality of one or more of these modules may be combined with at least part of the functionality of the other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the file retrieving module 710 and the code reconstructing module 720 may be implemented at least partially as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented by any other reasonable manner of integrating or packaging a circuit, such as hardware or firmware, or implemented by any one of three implementations of software, hardware, and firmware, or any suitable combination of any of them. Alternatively, at least one of the file retrieving module 710 and the code reconstructing module 720 may be at least partially implemented as a computer program module, which when executed, may perform corresponding functions.
Another aspect of the present disclosure also provides an electronic device.
FIG. 8 schematically shows a block diagram of an electronic device according to an embodiment of the disclosure. The electronic device shown in fig. 8 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 8, an electronic device 800 according to an embodiment of the present disclosure includes a processor 801 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)802 or a program loaded from a storage section 808 into a Random Access Memory (RAM) 803. The processor 801 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 801 may also include onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flows according to embodiments of the present disclosure.
In the RAM 803, various programs and data necessary for the operation of the electronic apparatus 800 are stored. The processor 801, the ROM 802, and the RAM 803 are communicatively connected to each other by a bus 804. The processor 801 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 802 and/or RAM 803. Note that the programs may also be stored in one or more memories other than the ROM 802 and RAM 803. The processor 801 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
Electronic device 800 may also include input/output (I/O) interface 805, input/output (I/O) interface 805 also connected to bus 804, according to an embodiment of the present disclosure. Electronic device 800 may also include one or more of the following components connected to I/O interface 805: an input portion 806 including a keyboard, a mouse, and the like; an output section 807 including a signal such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 808 including a hard disk and the like; and a communication section 809 including a network interface card such as a LAN card, a modem, or the like. The communication section 809 performs communication processing via a network such as the internet. A drive 810 is also connected to the I/O interface 805 as necessary. A removable medium 811 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 810 as necessary, so that a computer program read out therefrom is mounted on the storage section 808 as necessary.
According to embodiments of the present disclosure, method flows according to embodiments of the present disclosure may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 809 and/or installed from the removable medium 811. The computer program, when executed by the processor 801, performs the above-described functions defined in the system of the embodiments of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example but is not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, a computer-readable storage medium may include the ROM 802 and/or RAM 803 described above and/or one or more memories other than the ROM 802 and RAM 803.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the method provided by the embodiments of the present disclosure, when the computer program product is run on an electronic device, the program code being configured to cause the electronic device to implement the image model training method or the image processing method provided by the embodiments of the present disclosure.
The computer program, when executed by the processor 801, performs the above-described functions defined in the system/apparatus of the embodiments of the present disclosure. The systems, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
In one embodiment, the computer program may be hosted on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted in the form of a signal on a network medium, distributed, downloaded and installed via communication section 809, and/or installed from removable media 811. The computer program containing program code may be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
In accordance with embodiments of the present disclosure, program code for executing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, these computer programs may be implemented using high level procedural and/or object oriented programming languages, and/or assembly/machine languages. The programming language includes, but is not limited to, programming languages such as Java, C + +, python, the "C" language, or the like. The program code may execute entirely on the user computing device, partly on the user device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. These examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.

Claims (12)

1. A method of converting code for converting code supported by a first program to code supported by a second program, wherein the first program comprises a first extensible markup language file and a Java file, the first extensible markup language file comprising structured query language code, the method comprising:
acquiring the first extensible markup language file and the Java file; and
reconstructing the structured query language code by an extensible markup language parsing method, and reconstructing the Java code in the Java file by a template generating method to obtain a folder of the second program, wherein the folder of the second program comprises the reconstructed structured query language code and the reconstructed Java code.
2. The method of claim 1, wherein the first extensible markup language file comprises business statements and template statements, the business statements and the template statements capable of generating the structured query language code;
the reconstructing the structured query language code by the extensible markup language parsing method comprises:
respectively analyzing the business statement and the template statement by using an extensible markup language file analyzer to obtain an analysis result; and
and generating a second extensible markup language file aiming at the analysis result according to the persistent format requirement, and generating a Java file corresponding to the second extensible markup language file under the data access object folder.
3. The method of claim 2, wherein the parsing the business statement and the template statement respectively using an extensible markup language file parser to obtain parsing results comprises:
analyzing the template sentence according to file traversal, wherein the template sentence is a sentence obtained by analyzing the first extensible markup language file; analyzing the business statement according to file traversal, wherein the template statement and the business statement are stored in a mapping set in a correlation manner; and
and jointly analyzing the service statement and the template statement to obtain a reconstructed structured query language code.
4. The method of claim 3, wherein the generating a second extensible markup language file for the parsing result according to the persistence requirement format comprises: and storing the reconstructed structured query language code as a second extensible markup language file meeting the requirement of a persistent format.
5. The method of claim 4, wherein the generating a Java file corresponding to the second extensible markup language file under a data access object folder comprises: and generating a Java file corresponding to each second extensible markup language file meeting the requirement of the persistent format under the data access object folder aiming at each second extensible markup language file meeting the requirement of the persistent format.
6. The method according to any one of claims 1 to 5, wherein the reconstructing the Java code in the Java file by the template generation method comprises:
the Java code is parsed to generate Java files in the service folder, and Java files corresponding to the Java files in the service folder are generated in the program interface folder.
7. The method of claim 6, wherein parsing the Java code to generate a Java file in a service folder comprises:
traversing and analyzing Java files in the first program according to files;
converting the calling method of the structured query language code in the Java file in the first program into a method corresponding to the calling method of the structured query language code under a data access object folder; and
and generating the Java file in the service folder based on a method corresponding to the calling method of the structured query language code.
8. The method of claim 7, wherein the generating, in a program interface folder, Java files corresponding to the Java files in the service folder comprises:
and after at least one Java file is generated in the service folder, generating a Java file corresponding to the Java file in the service folder in the program interface file.
9. The method of claim 7, further comprising: and after the Java files in the service folder are generated, responding to user operation and modifying the Java files in the service folder.
10. An apparatus for converting code to convert code supported by a first program to code supported by a second program, wherein the first program comprises a first extensible markup language file and a Java file, the first extensible markup language file comprising structured query language code, the apparatus comprising:
the file acquisition module is used for acquiring the first extensible markup language file and the Java file; and
and the code reconstruction module is used for reconstructing the structured query language codes through an extensible markup language analysis method and reconstructing the Java codes in the Java file through a template generation method to obtain a folder of the second program, wherein the folder of the second program comprises the reconstructed structured query language codes and the reconstructed Java codes.
11. An electronic device, comprising:
one or more processors;
a storage device for storing executable instructions which, when executed by the processor, implement the method of any one of claims 1 to 9.
12. A computer-readable storage medium storing computer-executable instructions which, when executed by a processor, implement the method of any one of claims 1 to 9.
CN202110900202.1A 2021-08-06 2021-08-06 Method and device for converting codes and electronic equipment Pending CN113568622A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110900202.1A CN113568622A (en) 2021-08-06 2021-08-06 Method and device for converting codes and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110900202.1A CN113568622A (en) 2021-08-06 2021-08-06 Method and device for converting codes and electronic equipment

Publications (1)

Publication Number Publication Date
CN113568622A true CN113568622A (en) 2021-10-29

Family

ID=78170623

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110900202.1A Pending CN113568622A (en) 2021-08-06 2021-08-06 Method and device for converting codes and electronic equipment

Country Status (1)

Country Link
CN (1) CN113568622A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117270838A (en) * 2023-11-22 2023-12-22 太平金融科技服务(上海)有限公司 Method, device, equipment and medium for generating universal formula script

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117270838A (en) * 2023-11-22 2023-12-22 太平金融科技服务(上海)有限公司 Method, device, equipment and medium for generating universal formula script
CN117270838B (en) * 2023-11-22 2024-02-13 太平金融科技服务(上海)有限公司 Method, device, equipment and medium for generating universal formula script

Similar Documents

Publication Publication Date Title
US9483260B1 (en) Documentation generation for web APIs based on byte code analysis
US7870482B2 (en) Web browser extension for simplified utilization of web services
Brown et al. Implementation patterns for microservices architectures
US9811402B2 (en) Generation of representational state transfer interface from application programming interfaces
US8161498B2 (en) Providing globalization functionalities for javascript applications
CN109522018B (en) Page processing method and device and storage medium
US8201153B2 (en) Configurable Java Server pages processing
US9460224B2 (en) Selection mapping between fetched files and source files
US20040268306A1 (en) Methods, systems and computer program products for language independent data communication and display
Smith et al. Performance Model Interchange Format (PMIF 2): A comprehensive approach to queueing network model interoperability
US8171451B2 (en) Providing reports as web services
US20090254881A1 (en) Code generation techniques for administrative tasks
US20050050021A1 (en) Information Messaging and Collaboration System
US20060230057A1 (en) Method and apparatus for mapping web services definition language files to application specific business objects in an integrated application environment
CN102566984B (en) Method and device for configuring parameters
US8914482B2 (en) Translation of technology-agnostic management commands into multiple management protocols
CN113568622A (en) Method and device for converting codes and electronic equipment
Niu et al. A design of cross-terminal web system based on JSON and REST
US9224010B2 (en) Secure document creation from potentially unsecure source templates
US20210056118A1 (en) Forwards and backwards compatibility for dynamically evolving information-based platforms
Hsu Visual modeling for web 2.0 applications using model driven architecture approach
US20070234200A1 (en) Model view controller modeling language
JP2006510955A (en) Context-independent framework system and method for managing and executing XML processing tasks
US8239419B2 (en) Generating service component definition language from metadata
CN118194844A (en) Character string analysis method and device, terminal equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination