Permalink
Browse files

[Add] Guestbook Example & Rewrites

  • Loading branch information...
1 parent 5ae5853 commit 9094ba70ccdbf84fdf1a6e073c4c0ae96142b030 @micheee committed Jul 27, 2011
View
@@ -1,2 +1,7 @@
/src/main/.DS_Store
-/src/.DS_Store
+/src/.DS_Store
+/.DS_Store
+/.classpath
+/.project
+/.settings
+/target/
View
@@ -0,0 +1,18 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>DeepFS – Your files, your stuff </title>
+ <meta name="author" content="Michael Seiferle"/>
+ </head>
+ <body>
+ <div id="container">
+ <h1>Hello World.</h1>
+ <h2>Guestbook Demo Application</h2>
+ <div class="entries">
+ <div class="entry" id="entry-1">
+ <h4/>
+ <p/>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!DOCTYPE urlrewrite
+ PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN"
+ "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
+
+<urlrewrite>
+
+ <rule>
+ <note>
+ The rule means that requests to /test/status/ will be redirected to
+ /rewrite-status
+ the url will be rewritten.
+ </note>
+ <from>/test/status/</from>
+ <to type="redirect">%{context-path}/rewrite-status</to>
+ </rule>
+
+</urlrewrite>
+
@@ -4,6 +4,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
+ <filter>
+ <filter-name>UrlRewriteFilter</filter-name>
+ <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>UrlRewriteFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
<servlet>
<servlet-name>XQuery</servlet-name>
<servlet-class>org.basex.web.servlet.impl.XQuery</servlet-class>
@@ -0,0 +1,17 @@
+import module namespace gb = "http://basex.org/guests" at "src/main/webapp/lib/guestbook.xq";
+import module namespace web="http://basex.org/lib/web";
+declare option output:omit-xml-declaration "no";
+declare option output:method "xhtml";
+declare option output:include-content-type "yes";
+declare option output:doctype-public "-//W3C//DTD XHTML 1.1//EN";
+declare option output:doctype-system "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
+
+
+ if($POST('name') and $POST('message'))
+ then
+ let $red := web:redirect("/index.xq", "You Message has been saved")
+ return ($red,
+ gb:add($POST('name'), $POST('message')))
+
+ else
+ gb:err()
@@ -0,0 +1,5 @@
+<entries>
+<entry>
+<name>Michael</name>
+<text>Hello World</text>
+</entry></entries>
@@ -1,39 +1,28 @@
+<?xq
+import module namespace web="http://basex.org/lib/web";
+ web:redirect("/index.xq","")
+ ?>
<?xml version="1.0" encoding="UTF-8"?>
-
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
- <title>Hello World</title>
+ <!-- <meta http-equiv="refresh" content="0; url=index.xq"> -->
+
+ <title>Redirecting</title>
</head>
<body>
-<?xq
- <h1>Hello World.</h1>,
- <p>{1 to 10}</p> ?>
-<p>
- You can now start implementing your own webapp.
-</p>
- <hr />
-<h3>Source Code of the above example</h3>
-<pre>
- &lt;?xq
- &lt;h1&gt;Hello World&lt;/h1&gt;,
- &lt;p&gt;{1 to 10}&lt;/p&gt;
- ?&gt;
-</pre>
-<hr />
-<?xq
- <a href="index.xq">Purely functional example ></a>
-?><br />
-<?xq
- <a href="get.html">Reading <code>Request Parameters</code> ></a>
-?>
-<hr />
-<p>
- You will find these files in <code>src/main/webapp</code>
-</p>
</body>
</html>
+<form action="index.xq" method="post" accept-charset="utf-8">
+ <label for="name">Your Name</label><input type="text" name="name" value="" id="name" />
+ <label for="message">Your Message</label><input type="text" name="message" value="" id="message" />
+
+
+ <p><input type="submit" value="Continue →"></p>
+</form>
@@ -1,32 +1,40 @@
+import module namespace gb = "http://basex.org/guests" at "src/main/webapp/lib/guestbook.xq";
+import module namespace web="http://basex.org/lib/web";
+
declare option output:omit-xml-declaration "no";
declare option output:method "xhtml";
declare option output:include-content-type "yes";
declare option output:doctype-public "-//W3C//DTD XHTML 1.1//EN";
declare option output:doctype-system "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html>
<head>
- <title>DeepFS – Your files, your stuff </title>
+ <title>Guestbook Demo </title>
<meta name="author" content="Michael Seiferle" />
+ <style type="text/css">
+ small {{ float:left; padding-right:5px;}}
+ </style>
</head>
<body>
+ {web:flash()}
<div id="container">
+ <div class="form">
+ <h3>Add a new entry</h3>
+ <form action="add.xq" method="post" accept-charset="utf-8">
+ <label for="name">Your Name</label><br /><input type="text" name="name" value="" id="name" /> <br/>
+ <label for="message">Your Message</label><br />
+ <textarea name="message">Enter your message...</textarea>
+ <p><input type="submit" value="Continue →" /></p>
+ </form>
+ </div>
+
<h1>Hello World.</h1>
- {
- 1 to 10
- }
+ <h2>Guestbook Demo Application</h2>
+ <div class="entries">
+ {
+ gb:list()
+ }
+
+ </div>
</div>
- <hr />
- <h3>Source Code of the above example</h3>
- <pre>
- &lt;div id=&quot;container&quot;&gt;
- &lt;h1&gt;Hello World.&lt;/h1&gt;
- {{
- 1 to 10
- }}
- &lt;/div&gt;
-
- </pre>
- <hr />
- <a href="index.html">&lt; Back to the inline XQuery Example</a>
</body>
</html>
@@ -0,0 +1,24 @@
+module namespace gb = "http://basex.org/guests";
+import module namespace web="http://basex.org/lib/web";
+declare namespace p="java:System.out";
+declare function gb:list() as element(div)* {
+ for $entry at $pos in doc('guestbook')//entry
+ return
+ <div class="entry" id="entry-{$pos}">
+ <small>(#{$pos})</small> <h4>{$entry/name/text()}</h4>
+ <p>{$entry/text/text()}</p>
+ </div>
+};
+
+declare updating function gb:add($name, $message) {
+ insert node
+ <entry>
+ <name>{$name}</name>
+ <text>{$message}</text>
+ </entry>
+ as last into doc('guestbook')/entries
+};
+declare updating function gb:err(){
+ let $i := web:redirect("/index.xq","Your Message has not been saved")
+ return (insert node <r i="{$i}" /> as last into <a />, insert node <void a="{$i}"/> as last into <r />)
+};

0 comments on commit 9094ba7

Please sign in to comment.