MVC web framework based on eXist application server and
XRX architecture ♣
© Yuri Gapanyuk Egor Lakomkin Sergey Ionkin Martin Davtyan
associate professor student student student
gapyu@yandex.ru egor.lakomkin@gmail.com sergey.ionkin@gmail.com martin.davtyan@gmail.com
Bauman Moscow State Technical University
Informatics and Control Systems Department
Abstract Any MVC web framework allows rapid
development of web application infrastructure.
This industrial paper discusses the creation of But most of these frameworks are based on classical
web framework based on XML technologies. tree tier web application architecture: database tier
In addition to using eXist application server (usually relational), web server tier (object-oriented or
and XRX architecture, lightweight XML-based procedural programming language) and web browser
data model is designed and XQuery generator tier (HTML, CSS, JavaScript).
for prototyping application infrastructure is
developed. 3 Why new XRX-based framework
1 Introduction The weak point of classical tree tier web application
architecture is data transfer between tiers because
Nowadays XML-based information systems become different tiers uses different data formats and different
widespread. XRX architecture allows creating web programming language type systems.
application very easily using XQuery and XForms XML community invented XRX web application
standards. architecture to solve this issue. XRX architecture is
Our work covers the creation of MVC web described in details in “Why XRX” section of this
framework based on native XML database and XRX paper.
architecture. XRX approach is very convenient for web
We have used: developer. And from some point of view XRX approach
1. XForms – REST – XQuery (XRX) web application by itself is very close to be a web framework.
architecture. But some features may be added to standard XRX
2. eXist application server that has embedded native approach e.g. XQuery-scripts code generation, explicit
XML database. model definition.
3. XSLTForms XForms-processor. Our goal is to develop MVC web framework to do
We have developed: XRX approach more convenient for developers.
1. Framework infrastructure.
2. Simple XML-based data model for storing 4 Why eXist
application data.
3. XQuery generator for prototyping application eXist [3] was created in 2001 as Native XML Database
infrastructure. (NXD). eXist could store XML documents in database
We named our framework “iu5 web framework” collections and query XML with XQuery in the first
(“iu5” is a brief name of our subdepartment). releases.
Now eXist’s developer team positions it as a Web
2 Related Work Application Server with embedded XML Database.
eXist allows users to use XQuery for creating server
There are dozens of MVC web framework exist for pages which is similar to JSP or ASP.NET, therefore it
many programming languages. Probably the most is very easy to create web application with XQuery and
known example is Ruby on Rails [6]. store application data in XML format.
Database can store not only XML documents, but
♣ binary files too (e.g. images, CSS-files and etc.) which
Proceedings of the Spring Young Researcher's
Colloquium On Database and Information Systems
SYRCoDIS, Moscow, Russia, 2011
means eXist has “built in” CMS (Content Management interpreter and Native XML Database (application tier
System). + data tier).
XQuery-scripts also may be stored in database and
eXist allows to run them. 5.2. Detailed architecture of XRX Web application
Thereby all components of web application may be Let’s examine detailed architecture of XRX Web
stored in database and none of them in file system. Or application on figure 2.
application data may be stored in database and scripts There are tree variants of detailed architecture.
(and other files) – in the file system. Variant I is example of “shallow XRX” architecture.
In view of the aforesaid eXist is a very comfortable This is the case where XRX stack is simplified, for
platform for creating XQuery-based web applications. example traditional HTML forms are used instead of
XForms.
5 Why XRX Variants II and III are examples of “deep XRX”
architecture where full XRX stack is used.
XRX stands for XForms – REST – XQuery [2]. XRX is
Variant II is the case when XForms-processor is a
example of “zero-translation architecture”. It means that
client solution. The most popular solutions are
there is no translation (data format conversion) between
XSLTForms [8] and Mozilla XForms [4].
server and client data format. XML is used both on
XSLTForms based on XSLT transformation. XSLT
server and client sides and for data transfer between
transformation may be processed in browser or in server
server and client. Thus XRX architecture is simple and
side XQuery-script if necessary. This XSLT transforms
friendly for developer.
XForms-document into HTML + CSS + JavaScript.
5.1 Generalized architecture of XRX Web Resulting HTML-document provides user input,
application composes XML-fragment from inputted values and
sends resulting XML-fragment back to Web-server.
XSLTForms technology is a very flexible solution
and it’s integrated into eXist.
Figure 1: Generalized architecture of XRX Web
application.
Figure 1 shows tree tier architecture of XRX Web
application.
Presentation tier is XForms-processor. XForms-
processor receives XForms-document from Web-server,
converts XForms-document to HTML+CSS+Javascript,
validates user input, makes XML-fragment from
inputted values and sends result XML-fragment back to
Web-server.
Application tier is XQuery script that runs on Web-
server and communicates with XForms-processor and
Native XML Database.
Data tier is a Native XML Database that stores data
in XML format.
Data transfer between Application tier and
Presentation tier is XML, because XQuery script sends
to XForms-processor XForms-documents (that’s which
is XML), default XML data and receives inputted XML
data.
Data transfer between Application tier and Data tier Figure 2: Detailed architecture of XRX Web
is XML too, because Native XML Database sends and application.
receives data in XML format.
On figure 1 eXist Web Application Server combines Mozilla XForms is a plugin for Firefox and other
functions of a web server, server side XQuery script Mozilla products. To our regret it is not as mature as
XSLTForms.
Because in variant II XForms-processor is a client-
side solution it is very easy to create XForms-
documents dynamically and transfer them to client side
XForms-processor. This is a great advantage of variant
II.
Variant III is the case when XForms-processor is a
web server application solution.
The most popular solutions are Orbeon Forms [5]
and betterFORM [1].
Orbeon Forms, being a Java web application, is the
most advanced XForms-processor. It is a complete
application development framework with embedded
eXist Native XML Database. But this solution is too
complicated.
betterFORM is a successor of Chiba XForms-
processor. It is also a Java web application.
betterFORM is good solution, but in current version it’s
difficult to work with dynamically created XForms-
documents.
Due to these reasons we choose variant II of
application architecture. And we choose XSLTForms
XForms-processor because of its flexibility and
simplicity to work with dynamically created XForms-
documents.
6 iu5 web framework infrastructure
6.1 File system framework infrastructure
Framework uses collections in eXist database for
storing data, and file system for storing XQuery-scripts.
For storing XQuery-scripts and other files in file
system we use infrastructure shown at figure 3 (folders
are shown with border, files are not).
Application folder contains “styles” subfolder for
CSS styles, “script” subfolder for JavaScript sources,
“modules” subfolder for our “data modules” and “lib”
subfolder for additional XQuery scripts and modules.
XQuery script is a file with “.xql” extension which
can be executed via HTTP request.
XQuery module is a file with “.xqm” extension. It
cannot be executed via HTTP request. It can only be Figure 3: File system framework infrastructure.
included in “.xql” file.
There is only one “executable” XQuery-script Please do not confuse our “data module” with
(controller) in application folder, and each module also XQuery-module file, which is XQuery library file.
has one “executable” controller. Other XQuery files are For web development clarity we implemented
non-executable. “classical” MVC pattern for data modules. Each module
We have minimized number of executable files for consists of model, views and controller.
web development convenience and for security reasons.
6.3 Data module model
6.2 Data module definition
Model consists of XML data stored in database, and file
The main concepts of our framework is “module” (or “model.xqm” which contains functions for working
“data module”) and data module element. with module data.
The informal definition of data module – it is These are functions for selecting, inserting,
something like relational table or class in object- updating, deleting and etc. Functions are called from
oriented language. Data module element – it is controller.
something like relational table data row or class object.
The formal definition of data module – it is a 6.4 Data module view
combination of XML data (data module elements) File “view.xqm” for module contains functions that
stored in database, and files “model.xqm”, “view.xqm” controller calls for generating views. In current version
and “control.xql”.
we implemented two views for data module: list and
edit.
List view generates table of data module elements
with buttons for editing and deleting. There is also a
button for adding new data module element.
Edit view generates XForms-form for editing one
data module element.
File “view.xqm” for application contains only one
view, than generate list of hyperlinks for application
modules.
6.5 Data module controller
File “control.xql” is controller XQuery-script.
Controller may generate tree kinds of documents:
1. Plain HTML or XHTML documents.
2. XHTML documents with embedded XForms-
forms.
3. XML-fragments with default values for XForms-
forms.
Controller can receive two kinds of parameters:
1. HTTP POST parameters from HTML-forms. Figure 4: Database framework infrastructure.
2. User inputted XML-fragments from XForms-
forms. 7 iu5 web framework data model
Depending on parameters controller may perform
the following: 7.1 Why new data model
1. Call “model.xqm” functions for selecting, inserting,
updating, deleting XML data. We consider our framework for not very complicated
2. Call “view.xqm” functions for generating views. data-centric information systems.
3. Redirect to other modules controllers or to According to our goal we consider following data
application controller. models for our framework:
For security reasons we use only HTTP POST 1. Relational-like model.
method. Therefore we do not use any URL rewriting 2. Postrelational-like model.
technique, because it requires HTTP GET method. 3. XML model based on XML Schema.
New versions of eXist has built in “URL Rewriting For “Relational-like model” we consider XML
and MVC Framework” feature. This framework utilizes structure that’s have something like “tables”, “records”,
“controller.xql” controller script and work with URL “fields” and “relations” described by XML tags.
rewriting. It allows using all kind of models and views. But this “classical” model has many restrictions. For
At first we have decided to use this framework and example, if we want to model repeated groups of fields
extend it with our model and views. But later we we have to create new table.
understood that URL rewriting is not a useful feature From our point of view “Postrelational-like model”
for our framework. is much more suitable for data-centric information
Therefore we use controller script name systems. We consider “Postrelational-like model” as
“control.xql” instead of “controller.xql” in order not to “Relational-like model” with 1NF violation. Therefore
conflict with built in eXist feature. we can use groups and repeated groups of “fields” in
one “record”.
6.6 Database framework infrastructure On the other hand XML model based on XML
Schema is too “free-form” for our framework, because
For storing XML data in database we use infrastructure our framework is data-oriented, not document-oriented.
shown at figure 4 (collections are shown with border, No doubts, with XML Schema we can describe very
files are not). complicated combinations of “sequences” and
Framework use separate collections for each “choices” but is not easy to generate XForms-form
application and for each application module. based on XML Schema. Some experimental converters
Data module elements stores as XML files in from XML Schema to XForms already developed (e.g.
application module collections. xsdTransformer [7]) but it is risky to use them for
XML file name is data module element unique ID, production.
generated by eXist. Therefore “Postrelational-like model” is a happy
Application module collection is analogue for medium between restrictive “Relational-like model”
relational table and XML file is analogue for relational which is inconvenient for developer and “XML model
table data row. based on XML Schema” which is difficult for
generating correct XForms-forms.
7.2 Data model overview
question
Our “Postrelational-like” data model is very simple. It List of
contains only three XML tags: questions
1. Simple value. Example: Question
value edit
2. Reference to value in current module or in other
module. Example: question_text
value
Attribute “module” not used in case of current question_text
module reference.
XPath expressions for selecting values not pointed
in “r” tag. These expressions pointed in application
generator data and then generator “built in” them into question_main_group
Question
3. Group element. Example: params
Nested elements “g”, “r” or “v”.
question_text
In XML file root element “g” corresponds to data Text
module element. It may have nested elements “g”, “r” xforms:string
or “v”. true()
There are three types of groups: This field is
required
1. Simple group. Used for encapsulation of “r” or “v”
elements. 333
2. Repeated group. Sequence of subgroups for 25
modelling list of values. Analogue of “sequence”
XML Schema construction.
3. Variant repeated group. Sequence of various
subgroups for modelling list of heterogeneous question_time
Time limit
values. Analogue of “sequence” of “choice” XML
00:00:00
Schema construction. xforms:time
Group type pointed in application generator data and
then generator consider it when generating XForms-
form.
answers
8 iu5 web framework application Answers
generation list
list_num
Application generator script generates XQuery web
application according to XML declaration.
There is an interesting fact that we use our data answer
model both for application data and for application Answer
declaration.
Let’s examine detailed example of application
generation. answer_text
Answer text
8.1 Application declaration xforms:string
true()
We define sample application as test constructor for This field is
simple testing system. The only type of question in this required
system is question with multiple choices.
333
We’ll declare data model for tests and questions and
25
framework will generate forms for list view and edit.
Of course our framework will help us only with test
constructor. The questioning module should be written
by hands with “traditional” XRX. answer_right
Text of application declaration is shown below: Right answer
xforms:boolean
false
test At least one answer
Test constructor should be marked as right
333
(count(//*[@n='answer_right' and boolean- 100
from-string(.)=true()]) > 0)
test
List of 8.2 Example of generated XML data model
tests
Test Example of generated question XML data file is shown
edit below:
test_name 9665302bc58e_2011_5_4_4_51_18F82"
n="question">
test_name
Select XML
technologies
00:00:00
test_main_group
Test params n="answers">
test_name n="answer">
Test name XForms
xforms:string true
true()
This field is n="answer">
HTML
333 false
25
n="answer">
XQuery
true
test_questions
Test
questions
list_num Example of generated test XML data file is shown
below:
test_question
1de0139c6706_2011_5_4_5_2_22F76"
Question
n="test">
04T01:02:32Z" n="test_main_group">
XML test
n="name">test_question_ref
true()
This field is
04T01:02:32Z" n="test_questions">
required
n="ref_formtype">select_list
true()
module="question">12956faf-9d4e-4b79-
question
bc5c-9665302bc58e_2011_5_4_4_51_18F82
n="pathlabel">question_text
question
minimal
8.3 Examples of XForms-forms
Examples of generated XForms-forms are shown
below.
Figure 5: List of application modules form.
Figure 9: Edit test form.
9 Conclusion and future work
In this paper we introduced the first version of our “iu5
web framework” based on XRX architecture and eXist
web application server.
We are going to improve our framework in the
following ways:
1. Add embedded security, which is the most critical
Figure 6: List of questions form. feature.
2. Improve views generation and user interface.
References
[1] betterFORM Web site, 2011.
http://www.betterform.de
[2] Cagle Kurt. Metaphorical Web and XRX, 2008.
http://broadcast.oreilly.com/2008/09/metaphorical-
web-and-xrx.html
[3] eXist Web site, 2011,
http://exist-db.org
[4] Mozilla XForms Web site, 2011.
http://www.mozilla.org/projects/xforms
[5] Orbeon Forms Web site, 2011.
http://www.orbeon.com
Figure 7: Edit question form. [6] Ruby on Rails Web site, 2011.
http://rubyonrails.org
[7] xsdTransformer Web site, 2011.
http://xsdtrans.sourceforge.net
[8] XSLTForms Web site, 2011.
http://www.agencexml.com/xsltforms
Figure 8: List of tests form.