<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>MVC web framework based on eXist application server and ♣ XRX architecture</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Martin Davtyan</string-name>
          <email>martin.davtyan@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>3 Why new XRX-based framework</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>This industrial paper discusses the creation of web framework based on XML technologies. In addition to using eXist application server and XRX architecture, lightweight XML-based data model is designed and XQuery generator for prototyping application infrastructure is developed.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1 Introduction</title>
      <p>Nowadays XML-based information systems become
widespread. XRX architecture allows creating web
application very easily using XQuery and XForms
standards.</p>
      <p>Our work covers the creation of MVC web
framework based on native XML database and XRX
architecture.</p>
      <p>We have used:
1. XForms – REST – XQuery (XRX) web application
architecture.
2. eXist application server that has embedded native</p>
      <p>XML database.
3. XSLTForms XForms-processor.</p>
      <p>We have developed:
1. Framework infrastructure.
2. Simple XML-based data model for storing
application data.
3. XQuery generator for prototyping application
infrastructure.</p>
      <p>We named our framework “iu5 web framework”
(“iu5” is a brief name of our subdepartment).</p>
    </sec>
    <sec id="sec-2">
      <title>2 Related Work</title>
      <p>
        There are dozens of MVC web framework exist for
many programming languages. Probably the most
known example is Ruby on Rails [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
means eXist has “built in” CMS (Content Management
System).
      </p>
      <p>XQuery-scripts also may be stored in database and
eXist allows to run them.</p>
      <p>Thereby all components of web application may be
stored in database and none of them in file system. Or
application data may be stored in database and scripts
(and other files) – in the file system.</p>
      <p>
        In view of the aforesaid eXist is a very comfortable
platform for creating XQuery-based web applications.
5 Why XRX
XRX stands for XForms – REST – XQuery [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. XRX is
example of “zero-translation architecture”. It means that
there is no translation (data format conversion) between
server and client data format. XML is used both on
server and client sides and for data transfer between
server and client. Thus XRX architecture is simple and
friendly for developer.
5.1 Generalized architecture of XRX Web
application
5.2. Detailed architecture of XRX Web application
      </p>
      <p>Let’s examine detailed architecture of XRX Web
application on figure 2.</p>
      <p>There are tree variants of detailed architecture.</p>
      <p>Variant I is example of “shallow XRX” architecture.
This is the case where XRX stack is simplified, for
example traditional HTML forms are used instead of
XForms.</p>
      <p>Variants II and III are examples of “deep XRX”
architecture where full XRX stack is used.</p>
      <p>
        Variant II is the case when XForms-processor is a
client solution. The most popular solutions are
XSLTForms [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] and Mozilla XForms [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>XSLTForms based on XSLT transformation. XSLT
transformation may be processed in browser or in server
side XQuery-script if necessary. This XSLT transforms
XForms-document into HTML + CSS + JavaScript.
Resulting HTML-document provides user input,
composes XML-fragment from inputted values and
sends resulting XML-fragment back to Web-server.</p>
      <p>XSLTForms technology is a very flexible solution
and it’s integrated into eXist.</p>
      <p>Detailed architecture of</p>
      <p>Mozilla XForms is a plugin for Firefox and other
Mozilla products. To our regret it is not as mature as
XSLTForms.</p>
      <p>Because in variant II XForms-processor is a
clientside solution it is very easy to create
XFormsdocuments dynamically and transfer them to client side
XForms-processor. This is a great advantage of variant
II.</p>
      <p>Variant III is the case when XForms-processor is a
web server application solution.</p>
      <p>
        The most popular solutions are Orbeon Forms [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
and betterFORM [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
      <p>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.</p>
      <p>betterFORM is a successor of Chiba
XFormsprocessor. It is also a Java web application.
betterFORM is good solution, but in current version it’s
difficult to work with dynamically created
XFormsdocuments.</p>
      <p>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
XFormsdocuments.
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.</p>
      <p>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).</p>
      <p>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.</p>
      <p>XQuery script is a file with “.xql” extension which
can be executed via HTTP request.</p>
      <p>XQuery module is a file with “.xqm” extension. It
cannot be executed via HTTP request. It can only be
included in “.xql” file.</p>
      <p>There is only one “executable” XQuery-script
(controller) in application folder, and each module also
has one “executable” controller. Other XQuery files are
non-executable.</p>
      <p>We have minimized number of executable files for
web development convenience and for security reasons.</p>
      <sec id="sec-2-1">
        <title>6.2 Data module definition</title>
        <p>The main concepts of our framework is “module” (or
“data module”) and data module element.</p>
        <p>The informal definition of data module – it is
something like relational table or class in
objectoriented language. Data module element – it is
something like relational table data row or class object.</p>
        <p>The formal definition of data module – it is a
combination of XML data (data module elements)
stored in database, and files “model.xqm”, “view.xqm”
and “control.xql”.</p>
        <p>Please do not confuse our “data module” with
XQuery-module file, which is XQuery library file.</p>
        <p>For web development clarity we implemented
“classical” MVC pattern for data modules. Each module
consists of model, views and controller.</p>
      </sec>
      <sec id="sec-2-2">
        <title>6.3 Data module model</title>
        <p>Model consists of XML data stored in database, and file
“model.xqm” which contains functions for working
with module data.</p>
        <p>These are functions for selecting, inserting,
updating, deleting and etc. Functions are called from
controller.</p>
      </sec>
      <sec id="sec-2-3">
        <title>6.4 Data module view</title>
        <p>File “view.xqm” for module contains functions that
controller calls for generating views. In current version
we implemented two views for data module: list and
edit.</p>
        <p>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.</p>
        <p>Edit view generates XForms-form for editing one
data module element.</p>
        <p>File “view.xqm” for application contains only one
view, than generate list of hyperlinks for application
modules.</p>
      </sec>
      <sec id="sec-2-4">
        <title>6.5 Data module controller</title>
        <p>File “control.xql” is controller XQuery-script.</p>
        <p>Controller may generate tree kinds of documents:
1. Plain HTML or XHTML documents.
2. XHTML documents with embedded
XFormsforms.
3. XML-fragments with default values for
XFormsforms.</p>
        <p>Controller can receive two kinds of parameters:
1. HTTP POST parameters from HTML-forms.
2. User inputted XML-fragments from
XFormsforms.</p>
        <p>Depending on parameters controller may perform
the following:
1. Call “model.xqm” functions for selecting, inserting,
updating, deleting XML data.
2. Call “view.xqm” functions for generating views.
3. Redirect to other modules controllers or to
application controller.</p>
        <p>For security reasons we use only HTTP POST
method. Therefore we do not use any URL rewriting
technique, because it requires HTTP GET method.</p>
        <p>New versions of eXist has built in “URL Rewriting
and MVC Framework” feature. This framework utilizes
“controller.xql” controller script and work with URL
rewriting. It allows using all kind of models and views.</p>
        <p>At first we have decided to use this framework and
extend it with our model and views. But later we
understood that URL rewriting is not a useful feature
for our framework.</p>
        <p>Therefore we use controller script name
“control.xql” instead of “controller.xql” in order not to
conflict with built in eXist feature.
6.6 Database framework infrastructure
For storing XML data in database we use infrastructure
shown at figure 4 (collections are shown with border,
files are not).</p>
        <p>Framework use separate collections for each
application and for each application module.</p>
        <p>Data module elements stores as XML files in
application module collections.</p>
        <p>XML file name is data module element unique ID,
generated by eXist.</p>
        <p>Application module collection is analogue for
relational table and XML file is analogue for relational
table data row.
7 iu5 web framework data model</p>
      </sec>
      <sec id="sec-2-5">
        <title>7.1 Why new data model</title>
        <p>We consider our framework for not very complicated
data-centric information systems.</p>
        <p>According to our goal we consider following data
models for our framework:
1. Relational-like model.
2. Postrelational-like model.
3. XML model based on XML Schema.</p>
        <p>For “Relational-like model” we consider XML
structure that’s have something like “tables”, “records”,
“fields” and “relations” described by XML tags.</p>
        <p>But this “classical” model has many restrictions. For
example, if we want to model repeated groups of fields
we have to create new table.</p>
        <p>From our point of view “Postrelational-like model”
is much more suitable for data-centric information
systems. We consider “Postrelational-like model” as
“Relational-like model” with 1NF violation. Therefore
we can use groups and repeated groups of “fields” in
one “record”.</p>
        <p>On the other hand XML model based on XML
Schema is too “free-form” for our framework, because
our framework is data-oriented, not document-oriented.</p>
        <p>
          No doubts, with XML Schema we can describe very
complicated combinations of “sequences” and
“choices” but is not easy to generate XForms-form
based on XML Schema. Some experimental converters
from XML Schema to XForms already developed (e.g.
xsdTransformer [
          <xref ref-type="bibr" rid="ref7">7</xref>
          ]) but it is risky to use them for
production.
        </p>
        <p>Therefore “Postrelational-like model” is a happy
medium between restrictive “Relational-like model”
which is inconvenient for developer and “XML model
based on XML Schema” which is difficult for
generating correct XForms-forms.</p>
      </sec>
      <sec id="sec-2-6">
        <title>7.2 Data model overview</title>
        <p>8 iu5 web framework application
generation
Application generator script generates XQuery web
application according to XML declaration.</p>
        <p>There is an interesting fact that we use our data
model both for application data and for application
declaration.</p>
        <p>Let’s examine detailed example of application
generation.</p>
      </sec>
      <sec id="sec-2-7">
        <title>8.1 Application declaration</title>
        <p>We define sample application as test constructor for
simple testing system. The only type of question in this
system is question with multiple choices.</p>
        <p>We’ll declare data model for tests and questions and
framework will generate forms for list view and edit.</p>
        <p>Of course our framework will help us only with test
constructor. The questioning module should be written
by hands with “traditional” XRX.</p>
        <p>Text of application declaration is shown below:
&lt;g id="" n="application"&gt;
&lt;v n="app_name"&gt;test&lt;/v&gt;
&lt;v n="app_caption"&gt;Test constructor&lt;/v&gt;
&lt;g id="" n="modules"&gt;
&lt;g id="" n="module"&gt;
&lt;v n="module_name"&gt;question&lt;/v&gt;
&lt;v n="module_list_caption"&gt;List of
questions&lt;/v&gt;</p>
        <p>&lt;v n="module_edit_caption"&gt;Question
edit&lt;/v&gt;
&lt;g id="" n="list_data"&gt;
&lt;g id="" n="list_fields"&gt;</p>
        <p>&lt;v n="list_field"&gt;question_text&lt;/v&gt;
&lt;/g&gt;
&lt;v n="order_field"&gt;question_text&lt;/v&gt;
&lt;/g&gt;
&lt;g id="" n="fields"&gt;
&lt;g id="" n="group"&gt;</p>
        <p>&lt;v
n="group_name"&gt;question_main_group&lt;/v&gt;
&lt;v n="group_caption"&gt;Question
params&lt;/v&gt;
&lt;g id="" n="fields"&gt;
&lt;g id="" n="field"&gt;
&lt;v n="name"&gt;question_text&lt;/v&gt;
&lt;v n="caption"&gt;Text&lt;/v&gt;
&lt;v n="type"&gt;xforms:string&lt;/v&gt;
&lt;v n="required"&gt;true()&lt;/v&gt;
&lt;v n="alert"&gt;This field is
required&lt;/v&gt;
&lt;g id="" n="string_details"&gt;
&lt;v n="width"&gt;333&lt;/v&gt;
&lt;v n="height"&gt;25&lt;/v&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;g id="" n="field"&gt;
&lt;v n="name"&gt;question_time&lt;/v&gt;
&lt;v n="caption"&gt;Time limit&lt;/v&gt;
&lt;v n="default"&gt;00:00:00&lt;/v&gt;
&lt;v n="type"&gt;xforms:time&lt;/v&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;g id="" n="repeat_group"&gt;
&lt;v n="group_name"&gt;answers&lt;/v&gt;
&lt;v n="group_caption"&gt;Answers
list&lt;/v&gt;
&lt;v n="group_formtype"&gt;list_num&lt;/v&gt;
&lt;g id="" n="repeat_items_group"&gt;
&lt;g id="" n="repeat_item_group"&gt;
&lt;v n="group_name"&gt;answer&lt;/v&gt;
&lt;v n="group_caption"&gt;Answer&lt;/v&gt;
&lt;g id="" n="fields"&gt;
&lt;g id="" n="field"&gt;
&lt;v n="name"&gt;answer_text&lt;/v&gt;
&lt;v n="caption"&gt;Answer text&lt;/v&gt;
&lt;v n="type"&gt;xforms:string&lt;/v&gt;
&lt;v n="required"&gt;true()&lt;/v&gt;
&lt;v n="alert"&gt;This field is
required&lt;/v&gt;
&lt;g id="" n="string_details"&gt;
&lt;v n="width"&gt;333&lt;/v&gt;
&lt;v n="height"&gt;25&lt;/v&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;g id="" n="field"&gt;
&lt;v n="name"&gt;answer_right&lt;/v&gt;
&lt;v n="caption"&gt;Right answer&lt;/v&gt;
&lt;v n="type"&gt;xforms:boolean&lt;/v&gt;
&lt;v n="default"&gt;false&lt;/v&gt;
&lt;v n="alert"&gt;At least one answer
should be marked as right&lt;/v&gt;
&lt;v n="constraint"&gt;
(count(//*[@n='answer_right' and
booleanfrom-string(.)=true()]) &amp;gt; 0) &lt;/v&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
8.2 Example of generated XML data model
Example of generated question XML data file is shown
below:
&lt;g
id="12956faf-9d4e-4b79-bc5c9665302bc58e_2011_5_4_4_51_18F82"
n="question"&gt;</p>
        <p>&lt;g
id="question_main_group_1_2011-0504T00:51:25Z" n="question_main_group"&gt;
&lt;v n="question_text"&gt;Select XML
technologies&lt;/v&gt;</p>
        <p>&lt;v n="question_time"&gt;00:00:00&lt;/v&gt;
&lt;/g&gt;
&lt;g id="answers_1_2011-05-04T00:51:25Z"
n="answers"&gt;</p>
        <p>&lt;g id="answer_1_2011-05-04T00:51:25Z"
n="answer"&gt;
&lt;v n="answer_text"&gt;XForms&lt;/v&gt;
&lt;v n="answer_right"&gt;true&lt;/v&gt;
&lt;/g&gt;
&lt;g id="answer_2_2011-05-04T00:51:26Z"
n="answer"&gt;
&lt;v n="answer_text"&gt;HTML&lt;/v&gt;
&lt;v n="answer_right"&gt;false&lt;/v&gt;
&lt;/g&gt;
&lt;g id="answer_3_2011-05-04T00:51:31Z"
n="answer"&gt;
&lt;v n="answer_text"&gt;XQuery&lt;/v&gt;
&lt;v n="answer_right"&gt;true&lt;/v&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
Example of generated test XML data file is shown
below:
&lt;g
id="f8cac716-d965-4590-a1891de0139c6706_2011_5_4_5_2_22F76"
n="test"&gt;</p>
        <p>&lt;g
id="test_main_group_1_2011-0504T01:02:32Z" n="test_main_group"&gt;
&lt;v n="test_name"&gt;XML test&lt;/v&gt;
&lt;/g&gt;
&lt;g
id="test_questions_1_2011-0504T01:02:32Z" n="test_questions"&gt;</p>
        <p>&lt;g
id="test_question_1_2011-0504T01:02:32Z" n="test_question"&gt;</p>
        <p>&lt;r n="test_question_ref"
module="question"&gt;12956faf-9d4e-4b79bc5c-9665302bc58e_2011_5_4_4_51_18F82&lt;/r&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/g&gt;
Examples of generated XForms-forms are shown
below.
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.</p>
        <p>We are going to improve our framework in the
following ways:
1. Add embedded security, which is the most critical
feature.
2. Improve views generation and user interface.</p>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1] betterFORM Web site,
          <year>2011</year>
          . http://www.betterform.de
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Cagle</given-names>
            <surname>Kurt</surname>
          </string-name>
          .
          <source>Metaphorical Web and XRX</source>
          ,
          <year>2008</year>
          . http://broadcast.oreilly.com/
          <year>2008</year>
          /09/metaphoricalweb-and-xrx.html
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3] eXist Web site,
          <year>2011</year>
          , http://exist-db.org
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Mozilla</given-names>
            <surname>XForms Web site</surname>
          </string-name>
          ,
          <year>2011</year>
          . http://www.mozilla.org/projects/xforms
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Orbeon</given-names>
            <surname>Forms Web site</surname>
          </string-name>
          ,
          <year>2011</year>
          . http://www.orbeon.com
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          <source>[6] Ruby on Rails Web site</source>
          ,
          <year>2011</year>
          . http://rubyonrails.org
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7] xsdTransformer Web site,
          <year>2011</year>
          . http://xsdtrans.sourceforge.net
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>XSLTForms</given-names>
            <surname>Web site</surname>
          </string-name>
          ,
          <year>2011</year>
          . http://www.agencexml.com/xsltforms
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>