The present invention relates to the field of Internet technologies, and in particular, to a method and an apparatus for generating a widget.
A widget is a practical tool which is based on a network and may be embedded into a Web page or independently run on a Personal Computer (PC) desktop or Internet terminals of other types, and definitely, the widget may also be referred to as Weiji in Chinese. For example, a clock widget may display current time on a desktop; a weather widget may display weather forecast of a customized region; a Central Processing Unit (CPU) widget may display an occupation ratio of a CPU; such widgets as a desktop search widget and a stock widget are further provided. Moreover, a widget may not only be used on the PC desktop, but also may be embedded into a Web page. For example, www.google.cn/ig is formed of a plurality of widgets. Additionally, a widget may also be run on such embedded devices as a mobile phone, a digital photo frame, and a digital television. A user may also make a particular widget of his/her own and share it with others, which thereby greatly enriches the widget world. With the enhancement of service capabilities of terminals and networks, the application range of a widget becomes wider and wider, and the number of widgets developed by users also becomes larger and larger.
However, in the implementation of the present invention, it is found that, currently it is universally accepted in the industry that a widget is only a small application capable of executing a simple logic and complementing a single task. When a widget is made, it needs to be achieved in a manner of writing a code, and a user needs to have knowledge of various aspects such as image processing, Hyper Text Markup Language (HTML)/Extensible Markup Language (XML), and java, so that the workload of developing a widget is heavy, which thereby greatly limits the application of a widget.
The present invention provides a method and an apparatus for generating a widget, a method for running a widget, a widget engine, and a client device, which generate a widget through combination and reuse of existing widgets, so as to reduce the workload of widget development.
In order to achieve the foregoing objectives, the present invention provides the following solutions:
A method for generating a widget is provided, which includes:
obtaining identification information of elements to be reused in a source widget;
generating a logical relation between the elements to be reused; and
generating a widget including the identification information of the elements to be reused and the logical relation according to the identification information of the elements to be reused and the logical relation.
An apparatus for generating a widget is provided, which includes:
an identification unit, configured to obtain identification information of elements to be reused in a source widget;
a logical relation generation unit, configured to generate a logical relation between the elements to be reused; and
a widget generation unit, configured to generate a widget carrying the identification information of the elements to be reused and the logical relation according to the identification information of the elements to be reused and the logical relation.
A method for running a widget is provided, which includes:
recognizing a widget including identification information and a logical relation of elements to be reused;
obtaining elements to be reused according to the identification information of the elements to be reused; and
parsing the logical relation, inserting the elements to be reused into the widget, and executing and rendering the widget.
A widget engine is provided, which includes:
a recognition unit, configured to recognize a widget including identification information and a logical relation of elements to be reused;
an obtaining unit, configured to obtain elements to be reused according to the identification information of the elements to be reused; and
a parsing unit, configured to parse the logical relation, insert the elements to be reused into the widget, and execute and render the widget.
A client device is provided, which includes:
an apparatus for generating a widget, configured to obtain identification information of elements to be reused in a source widget, generate a logical relation between the elements to be reused, and generate a widget carrying the identification information of the elements to be reused and the logical relation according to the identification information of the elements to be reused and the logical relation; and
a widget engine, configured to obtain elements to be reused according to the identification information of the elements to be reused, parse the logical relation, insert the elements to be reused into the widget, and execute and render the widget.
According to specific embodiments of the present invention, the present invention discloses the following technical effects.
The embodiments of the present invention are capable of: obtaining identification information of elements to be reused in a source widget; generating a logical relation between the elements to be reused; and generate a widget carrying the identification information of the elements to be reused and information of the logical relation according to the identification information of the elements to be reused and the logical relation. Therefore, a new widget may be generated through combination and reuse of existing widgets, so that it is unnecessary to write a code in a development procedure, which reduces the workload of widget development and is beneficial to the development of widget technologies.
To illustrate the technical solutions according to the embodiments of the present invention or in the prior art more clearly, the accompanying drawings for describing the embodiments are introduced briefly in the following. Apparently, the accompanying drawings in the following description are only some embodiments of the present invention, and persons skilled in the art may derive other drawings from the accompanying drawings without creative efforts.
The technical solutions of the present invention are clearly described in the following with reference to the accompanying drawings of the present invention. It is obvious that the embodiments to be described are only a part rather than all of the embodiments of the present invention. All other embodiments obtained by persons skilled in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
In order to make the foregoing objectives, features, and advantages of the present invention more comprehensible, the present invention is further described in detail in the following through specific embodiments with reference to the accompanying drawings.
Referring to
S101: Obtain identification information of elements to be reused in a source widget.
The source widget refers to an existing widget, and the existing widget may be generated according to a method in the prior art, and may also be generated according to the method in the embodiment of the present invention.
The elements to be reused refer to elements that need to be reused in a source widget, and the elements to be reused need to be used in a newly generated widget. An identification of an element to be reused is obtained, so that when a newly generated widget is run, the element to be reused may surely be found uniquely.
S102: Generate a logical relation between the elements to be reused.
The logical relation between the elements to be reused refers to a logical relation between elements to be reused in a new widget, and may include a simple combination relation, a precedence relation, or a complex collaboration relation. The combination relation means to simply combine elements to be reused to form a new widget; the precedence relation refers to a certain precedence relation between elements to be reused, for example, an output of a previous element to be reused is used as an input of a next element to be reused; the collaboration relation refers to a complex logical relation between elements to be reused, which may be specifically determined according to practical applications.
The generating the logical relation between the elements to be reused is to express each logical relation into a language recognizable to a widget running apparatus, so that when the newly generated widget is run, the logical relation may be normally parsed. Specifically, various generation methods are provided, for example, the logical relation may be written in a markup language of a widget, and the logical relation may be generated through a layout function of the markup language; also, the logical relation may be written in a configuration file, and the logical relation may be generated by using a tag; further, the logical relation may be written in a script language of a widget, and the logical relation may be generated by using the script language.
S103: Generate a widget including the identification information of the elements to be reused and the logical relation according to the identification information of the elements to be reused and the logical relation.
It should be noted that, in order to achieve the foregoing solution, an embodiment of the present invention provides a tool for generating a widget, and the subject performing steps S101 to S103 is the tool for generating a widget. Generally, the tool for generating a widget may have an operation area, a preview area and a code area. The operation area is used to operate elements to be reused, the preview area is used to present effects of a newly generated widget, and the code area is used to present a code corresponding to a newly generated widget.
Additionally, it should be noted that, when the identification information of the elements to be reused is obtained, and the logical relation between the elements to be reused is generated, a code recognizable to a widget may be automatically generated by the tool, so that in a procedure of generating a widget, no code needs to be manually written.
It may be seen that, according to the embodiment of the present invention, a new widget may be generated through combination and reuse of existing widgets, so that it is unnecessary to write a code in a development procedure, which reduces the workload of widget development and is beneficial to the development of widget technologies.
When the identification information of elements to be reused in the source widget is obtained, the elements to be reused may be obtained automatically by the tool according to a certain preset policy (for example, selecting core elements in a source widget), and then identification information of elements to be reused is obtained; in the embodiment of the present invention, elements to be reused may also be selected by a user, and the tool may provide a portal for selecting elements to be reused to the user. For example, the tool may recognize elements in a source widget, and prompt the user for selectable elements (for example, highlighting selectable elements with a prompt box) after recognizing elements in a source widget, and if the user intends to reuse a certain element, the user may click the element; at this time, the tool determines that the element clicked by the user is an element to be reused; at this time, identification information that is about the element selected by the user and is displayed in the instruction is the identification information of the elements to be reused. Similarly, a user may further select other elements in the source widget or elements in other source widgets.
Likewise, when the logical relation between the elements to be reused is generated, the logical relation may be generated automatically by the tool according to a certain preset policy (for example, presetting the logical relation as a simple combination relation); definitely, the logical relation may also be set by a user, and the tool provides a portal for setting a logical relation to a user, and then receives an instruction that a user sets logical relation information between elements to be reused through the portal, and at this time, the logical relation set by the user and displayed in the instruction is the logical relation among the information to be reused, and then the tool automatically generates a code of the logical relation set by the user. For example, if a user intends to set a combination relation, after selecting elements to be reused, the user may directly drag the elements to be reused to the preview area of a new widget. After detecting occurrence of the dragging event, the tool may determine that the logical relation is a combination relation, and meanwhile may generate a code of such a logical relation in the foregoing manners, thereby generating a corresponding code. For another example, if a user intends to set a precedence relation between two elements to be reused, the user may firstly click a first element to be reused, and then drag the first element to be reused onto a second element to be reused, and when detecting occurrence of such an event, the tool may judge that a user is to set a precedence relation, and then may automatically use output data of the first element to be reused as input data of the second element to be reused, and generate a corresponding code to express the precedence relation.
The elements to be reused may include the source widget the entire source widget), a node to be reused in a source widget, or a variable or an object to be reused in a source widget. That is, granularity of reused information may be refined into a node or even a variable or an object.
For a widget and a node in a widget, because the corresponding content may be intuitively demonstrated in front of a user as long as the widget is opened, the user may directly select the content corresponding to a widget to be reused or a node to be reused in the widget. However, a variable or an object (for example, a variable or an object created in a script language running procedure) in the widget is generally not directly displayed to the user, so the user may not directly know what variables or objects the widget has.
Therefore, the tool may also recognize the variable or the object in the widget and prompt the user, so that the user may select the variable or the object in the widget in the same manner as selecting other elements. Definitely, after being selected, the variable or the object may be dragged to a code area rather than a preview area, and the user may perform such operations as editing on the variable or the object in the code area.
Elements to be reused of different types need to be identified by adopting a corresponding method. For example, elements to be reused may be identified by adopting the following format: [widgetID, [NodeID, [ObjectID]]].
The widgetID is used to uniquely identify a source widget of elements to be reused. The identification information of the elements to be reused may be an identifier (ID) of a widget allocated by a system, and may also be a storage path of the widget; by utilizing the identification information, the source widget may be found when a new widget is run.
The NodeID is used to uniquely identify a node that needs to be reused in a widget. When such elements to be reused are marked up, identification information may be a node ID, and a path of the node in a Document Object Model (DOM) tree of a source widget may also be identified by using an XPath syntax. Sometimes, in order to obtain certain node content which may only be presented through user interaction, the NodeID further needs to contain information for user interaction.
The DOM is a set of nodes or information clips organized in a hierarchical structure. Such a hierarchical structure allows a developer to navigate and search for specific information in a tree. Because the hierarchical structure is based on an information level, the DOM is regarded as being based on a tree or based on an object.
The ObjectID is used to identify a variable or an object to be reused in a widget. Because no variable or object exists in the DOM tree of a source widget, in order to mark up a variable or an object, an extended DOM tree may be constructed for each source widget, a variable or an object in the DOM tree of a source widget associated with a certain node (the variable or the object herein is a variable or an object which may be provided for reuse) may be used as a leaf node of this node, and the leaf node may be stored at a path in the extended DOM tree. In this way, when a new widget is run, the source widget may be found through the path, and then the node associated with the variable or the object to be reused may be found, and thereby a variable or an object to be reused is found.
After identification information of elements to be reused is obtained, the identification information is further stored, and specifically, identification information may be stored at the following positions: in a script area of a widget source file; in a configuration file of a widget source file; and a layout file of a widget source file. Identification information may also be stored in various forms, for example, identification information may be stored as a string text, a script variable, a Uniform Resource Locator (URL) reference, a tag or tag attribute in a markup language (such as HTML and XML).
After identification information of elements to be reused is obtained, and a logical relation between elements to be reused is generated, a widget carrying the identification information of the elements to be reused and the logical relation information may be generated. In practical applications, before a widget is generated finally, adjustment may be further performed, for example, a node layout may be adjusted, and/or, new service logic may be added. The adjustment may be automatically completed by the tool, and the layout adjustment may also be completed by a user in a manner of writing a code.
In a case of user adjustment, the adjusting the node layout is specifically as follows: a user may change the position of each element to be reused in the preview area by dragging an element, the tool may correspondingly adjust the node in the DOM tree; the adding the new service logic is specifically as follows: a user may add new service logic in a code area by editing a code.
It should be noted that, in the procedure of adding new service logic, although a user still needs to write a certain code, the workload is greatly reduced as compared with the method for generating a widget completely in dependence on writing a code in the prior art.
In order to better understand the method for generating a widget according to the embodiment of the present invention, a user selecting elements to be reused and setting a logical relation are introduced as an example in detail in the following.
Referring to
S201: A user selects a source widget.
S202: A system daemon (that is, a tool for generating a widget) parses the source widget, and presents the source widget to the user through a Graphical User Interface (GUI).
S203: The user identifies each element to be reused.
S204: The tool for generating a widget judges a type of an element to be reused; if the element is a node, the process proceeds to step S206, and if the element is a variable or an object, the process proceeds to step S205.
S205: The user sets a logical relation among reused variables or objects, and the process proceeds to step S209.
S206: The tool for generating a widget judges the logical relation set by the user, and if the logical relation is a simple combination relation, the process proceeds to step S208; if the logical relation is a precedence relation, the process proceeds to step S207.
S207: The user arranges a work flow.
S208: The user lays out nodes in a new widget.
S209: The tool for generating a widget judges whether the user operation is ended, and if the user operation is ended, the process is ended; otherwise, the process returns to step S203.
After a new widget is generated according to the method in the embodiment of the present invention, the new widget may be run in a widget engine, and the running of the new widget needs to depend on a source widget, which is different from running an ordinary widget. In order to run the newly generated widget in the widget engine of a client, in an embodiment, the present invention further provides a method for running a widget. Referring to
S301: Recognize a widget carrying identification information and logical relation information of elements to be reused.
The widget carrying the identification information and the logical relation information of the elements to be reused is a widget generated according to the method in the embodiment of the present invention, and for convenience of description, is referred to as a new widget in the following.
S302: Obtain the elements to be reused according to the identification information of the elements to be reused.
Because the widget carries identification information of elements to be reused, and may uniquely identify elements to be reused, the source widget where elements to be reused are located may be located through the identification information, and elements needed to be reused may be found after the source widget is located. Therefore, step S302 may specifically include: locating a source widget according to the identification information of the elements to be reused; and running the source widget, and obtaining the elements to be reused from the source widget.
S303: Parse the logical relation, insert the elements to be reused into the widget, and execute and render the widget.
The logical relation may simply exist in a form of codes, and a widget engine may directly parse a code, and insert elements to be reused into a widget; additionally, the logical relation may also be embodied in a form of a DOM tree, and a widget engine may also parse a DOM tree, and then insert a node according to the DOM tree. After a new widget is rendered, content of the new widget may be demonstrated in front of a user.
Specifically, when the logical relation is parsed, various manners may be adopted, which for example may include the following manners. The logical relation may be parsed from a configuration file; or the logical relation may be used as a system function of a widget engine and provided to a new widget for a script language to invoke; or all the logical relations may be written into a script area of a new widget and executed by a script engine.
Referring to
S401: Start a new widget.
S402: Parse and recognize identification information of elements to be reused.
S403: Start and run a source widget.
S404: Parse an internal structure of a source widget.
S405: Judge a type of an element to be extracted, and if an element to be extracted is a node, the process proceeds to step S406; if an element to be extracted is a variable or an object, the process proceeds to step S407.
S406: Insert a node to be reused in the source widget into a new widget, and the process proceeds to step S408.
S407: Insert a variable or an object to be reused in the source widget into a new widget, and the process proceeds to step S408.
S408: Continues to execute and render a new widget.
The foregoing describes the method for generating a widget according to the embodiment of the present invention, and the method for running the widget generated according to the embodiment of the present invention. It should be noted that, the widget is generally formed of HTML and Java Script, and the parsing the widget may be achieved by constructing a DOM tree. For other widgets not conforming to World Wide Web Consortium (W3C) standards (such as a widget made by using a self-defined XML tag), the embodiments of the present invention are also applicable. As long as the tool for generating a widget is capable of acquiring a node to be reused or a variable and an object to be reused in the source widget by parsing, a new widget may be generated according to the method in the embodiment of the present invention; as long as a widget running apparatus (a widget engine) is capable of recognizing identification information of elements to be reused, extracting elements to be reused according to the identifications and inserting the elements into the new widget, combination and reuse of widgets may be achieved.
Corresponding to the method for generating a widget according to the embodiment of the present invention, in an embodiment, the present invention further provides an apparatus for generating a widget. Referring to
an identification unit U501, configured to obtain identification information of elements to be reused in a source widget;
a logical relation generation unit U502, configured to generate a logical relation between the elements to be reused; and
a widget generation unit U503, configured to generate a widget including the identification information of the elements to be reused and information of the logical relation according to the identification information of the elements to be reused and the logical relation.
The elements to be reused may be specified by a user, and at this time, the identification unit U501 may include the following sub-unit:
an element selection instruction receiving sub-unit U5011, configured to receive an instruction that a user sets an element in the source widget; at this time, identification information that is about the element selected by the user and is displayed in the instruction is the identification information of the elements to be reused.
The logical relation between the elements to be reused may be automatically preset by a tool, and may also be set by a user, and when the logical relation between the elements to be reused needs to be specified by the user, the apparatus may further include:
a logical relation instruction receiving unit U504, configured to receive an instruction that a user sets the logical relation between the elements to be reused; correspondingly, the logical relation set by the user and displayed in the instruction is the logical relation among the information to be reused.
Various types of the elements to be reused may be provided. When the element to be reused in the source widget is a variable or an object to be reused in the source widget, because no variable or object exists in a DOM tree of the source widget, referring to
an extended DOM tree construction sub-unit U5012, configured to construct an extended DOM tree for a DOM tree of the source widget, and use a variable or an object to be reused and associated with a certain node in the DOM tree of the source widget as a leaf node of the node; at this time, a path of the leaf node in the extended DOM tree is the identification information of the elements to be reused.
The identification information of elements to be reused is obtained, the identification information may be further stored, and the identification information of elements to be reused may be stored at a plurality of positions. Specifically, the apparatus may further include:
a first storage unit U505, configured to store the identification information of the elements to be reused in a script area of a widget source file;
or,
a second storage unit U506, configured to store the identification information of the elements to be reused in a configuration file of a widget source file;
or,
a third storage unit U507, configured to store the identification information of the elements to be reused in a layout file of a widget source file.
Additionally, the identification information may be further stored in various forms, as long as the forms may be recognized by a widget engine. Specifically, the apparatus may further include:
a storage form determination unit U508, configured to store the identification information of the elements to be reused as a string text, a script variable, a URL reference, or a tag or tag attribute in a markup language.
Various specific manners may also be provided for the logical relation generation unit U502 to express a logical relation. Specifically, the logical relation generation unit U502 may include:
a first generation sub-unit U5021, configured to write the logical relation in a markup language of the widget, and generate the logical relation through a layout function of the markup language;
or,
a second generation sub-unit U5022, configured to write the logical relation in a configuration file, and generate the logical relation by using a tag;
or,
a third generation sub-unit U5023, configured to write the logical relation in a script language of the widget, and generate the logical relation by using the script language.
Corresponding to the method for running a widget according to the embodiment of the present invention, in an embodiment, the present invention further provides a widget engine. Referring to
a recognition unit U701, configured to recognize a widget including identification information and logical relation information of elements to be reused;
an obtaining unit U702, configured to obtain elements to be reused according to the identification information of the elements to be reused; in this embodiment, the obtaining unit U702 may firstly locate the source widget according to the identification information of the elements to be reused, then run the source widget, and obtain the elements to be reused from the source widget, so as to finally obtain the elements to be reused; and
a parsing unit U703, configured to parse the logical relation, insert the elements to be reused into the widget, and execute and render the widget.
The parsing unit U703 may include the following sub-units:
a first parsing sub-unit U7031, configured to parse the logical relation from a configuration file;
or,
a second parsing sub-unit U7032, configured to invoke, through a script language, the logical relation used as a system function;
or,
a third parsing sub-unit U7033, configured to execute, through a script engine, the logical relation written in a script area of the widget.
Through the apparatus according to the embodiment of the present invention, a new widget may be generated through combination and reuse of existing widgets, so that it is unnecessary to write a code in the development procedure, which reduces the workload of widget development and is beneficial to the development of widget technologies.
Moreover, in an embodiment, the present invention further provides a client device, which includes:
an apparatus for generating a widget, configured to obtain identification information of elements to be reused in a source widget, generate a logical relation between the elements to be reused, and generate a widget carrying the identification information of the elements to be reused and the logical relation according to the identification information of the elements to be reused and the logical relation; and
a widget engine, configured to obtain the elements to be reused according to the identification information of the elements to be reused, parse the logical relation, insert the elements to be reused into the widget, and execute and render the widget.
In this embodiment, the apparatus for generating a widget and the widget engine may also form a client device, and developers or users jointly experience how to generate a widget through the client device.
Persons skilled in the art may understand that all or part of the steps of the method according to the embodiments of the present invention may be implemented by a program instructing relevant hardware. The program may be stored in a computer readable storage medium. When the program is executed, the following steps are performed: obtaining identification information of elements to be reused in a source widget; generating a logical relation between the elements to be reused; and generating a widget carrying the identification information of the elements to be reused and the logical relation according to the identification information of the elements to be reused and the logical relation. The storage medium may be a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
A method and an apparatus for generating a widget according to the present invention are introduced in detail in the foregoing. The principle and implementation ways of the present invention are described herein through specific examples. The foregoing description about the embodiments is merely provided for ease of understanding of the method and core ideas of the present invention. Persons skilled in the art may make variations and modifications to the present invention in terms of the specific implementations and application scopes according to the ideas of the present invention. Therefore, the specification shall not be construed as a limit to the present invention.
Number | Date | Country | Kind |
---|---|---|---|
200910161314.9 | Jul 2009 | CN | national |
This application is a continuation of International Application No. PCT/CN2010/075243, filed on Jul. 19, 2010, which claims priority to Chinese Patent Application No. 200910161314.9, filed on Jul. 20, 2009, both of which are hereby incorporated by reference in their entireties.
Number | Date | Country | |
---|---|---|---|
Parent | PCT/CN2010/075243 | Jul 2010 | US |
Child | 13341406 | US |