Adventures with BaseX and web applications -...
Transcript of Adventures with BaseX and web applications -...
![Page 1: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/1.jpg)
AdventureswithBaseX and web applications
Andy Bunce @apb1704
Feb 2013
![Page 2: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/2.jpg)
BaseX and the Web
● GraphXQ – RESTXQ + Graphviz● ( Using a PaaS )● CellarXQ – Angular.js + OAuth● BaseX with Node.js + events
![Page 3: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/3.jpg)
RESTXQ http://docs.basex.org/wiki/RESTXQ
● introduced by Adam Retter, is an API that facilitates the use of XQuery as a Server Side processing language for the Web.
● inspired by Java’s JAX-RS API. ● a set of XQuery 3.0 annotations for mapping
HTTP requests to XQuery functions. ● the XQuery functions generate and return
HTTP responses.
![Page 4: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/4.jpg)
GraphXQ – RESTXQ + Graphviz
![Page 5: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/5.jpg)
Graphviz http://www.graphviz.org/
● Open source graph (network) visualization project from AT&T Research.
● directed and undirected graph layout
● i/p is string (dot syntax)● o/p is SVG
![Page 6: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/6.jpg)
DOTML http://martin-loetzsch.de/DOTML/
● DotML is a XML based syntax for the input language of the 'Dot' graph drawing tool
![Page 7: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/7.jpg)
Graphviz from BaseX
● Use proc:execute()● Sadly has no pipe in so use temp file
![Page 8: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/8.jpg)
GraphXQ
![Page 9: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/9.jpg)
Twitter bootstrap http://twitter.github.com/bootstrap/
![Page 10: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/10.jpg)
Web page structure
LayoutCommon menus
etc
Template
PartialRepeating items
![Page 11: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/11.jpg)
TXQ - Templating http://cubeb.blogspot.com/2012/11/xquery-templating-engines-and-txq.html
![Page 12: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/12.jpg)
Templating in use
Item1.xml
library.xml
ApplicationDefault values
![Page 13: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/13.jpg)
Using a PaaS
BaseX inthe Cloud
![Page 14: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/14.jpg)
Openshift https://openshift.redhat.com/app/
![Page 15: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/15.jpg)
Openshift features
● Has Java (and Node.js) pre-installed● Has a free option● Provides ssh terminal access
(:~
: There are other similar services
: E.g. https://www.appfog.com/
:)
![Page 16: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/16.jpg)
Openshift and BaseX
● Sign up, install tools● Create a project using “DIY” cartridge● This generates a git project with script stubs
● Add your code and deploy using git push
● Restrictions on usable ports # start basexcd ${OPENSHIFT_DATA_DIR}basexnohup bin/basexhttp -X -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP \-X -Dorg.basex.SERVERPORT=$OPENSHIFT_INTERNAL_PORT \-p 15005 -e 15006 -s 15007 -U admin -P admin &
![Page 17: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/17.jpg)
CellarXQ – Angular.js + OAuth
https://github.com/apb2006/basex-cellarBased on http://coenraets.org/blog/2012/02/sample-application-with-angular-js/
![Page 18: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/18.jpg)
angular.js http://angularjs.org/
● AngularJS is an open-source JavaScript framework from Google.
● Its goal is to augment browser-based applications with Model–View–Controller (MVC) capability.
● Declarative data binding● Same space as XFORMS
![Page 19: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/19.jpg)
Angular.js Hello world
![Page 20: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/20.jpg)
JSON
● Angular expects to send and receive JSON● The BaseX JSON serialization worked for me
But● I had full control of the XML● No namespaces etc...
![Page 21: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/21.jpg)
The XML database
![Page 23: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/23.jpg)
The user database● Users defined at the application level. ● Data in users.xml in the database
![Page 24: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/24.jpg)
Sign in and user session
![Page 25: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/25.jpg)
Register new user
![Page 26: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/26.jpg)
Permissions
● XQuery RESTXQ calls return status 404 if not permissioned.
● Page routing and login prompt is handled at the Angular level.
![Page 27: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/27.jpg)
Application Configuration
● Stored in an XML file in WEB-INF ● Includes OAuth secrets and tokens
![Page 28: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/28.jpg)
BaseX with Node.js + events
An XQuery chatbot in 50 lines...
![Page 29: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/29.jpg)
node.js http://nodejs.org/
● is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications.
● uses an event-driven, non-blocking I/O model that makes it lightweight and efficient
● perfect for data-intensive real-time applications that run across distributed devices.
![Page 30: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/30.jpg)
Basex-node https://github.com/apb2006/basex-node
● is a BaseX client for Node.js● Uses the BaseX API over a socket● Available on npm
![Page 31: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/31.jpg)
Basex-node sample
![Page 32: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/32.jpg)
Socket.io http://socket.io/
● Socket.IO is a JavaScript library for realtime web applications.
● a server-side library for node.js● a client-side library that runs in the browser● uses the WebSocket protocol, but can fall-back
on other methods, such as Adobe Flash sockets, JSONP polling, and AJAX long polling
![Page 33: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/33.jpg)
Chat server based on http://book.mixu.net/ch13.html
![Page 34: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/34.jpg)
db:event http://docs.basex.org/wiki/Database_Module#db:event
● Executes a $query and sends the resulting value to all clients watching the Event with the specified $name. The query may also perform updates; no event will be sent to the client that fired the event.
● db:event($name as xs:string, $query as item()) as empty-sequence()
![Page 35: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/35.jpg)
Add BaseX session
Code @ https://gist.github.com/4707605
EchoEvents
received
Pass messagesStarting “xquery “
for execution
![Page 36: Adventures with BaseX and web applications - …files.basex.org/publications/xmlprague2013/2013/Andy-Bunce-BaseX... · Adventures with BaseX and web applications ... -Dorg.basex.SERVERHOST=$OPENSHIFT_INTERNAL_IP](https://reader034.fdocuments.in/reader034/viewer/2022051523/5a791a877f8b9a00168d4298/html5/thumbnails/36.jpg)
the End
● http://open1-apb.rhcloud.com/restxq/graphxq
● http://open1-apb.rhcloud.com/cellar
● http://node2-apb.rhcloud.com/