summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorburaq <buraq@epfl.ch>2004-03-25 11:19:13 +0000
committerburaq <buraq@epfl.ch>2004-03-25 11:19:13 +0000
commitbb5e2de28e57b030dd5669e95041104117e985d2 (patch)
tree5fe616c103e7217f3fc6a7710accb1b7ef1e1273 /test/files/run
parent9c2488391850128d247da2f7707f98af63168132 (diff)
downloadscala-bb5e2de28e57b030dd5669e95041104117e985d2.tar.gz
scala-bb5e2de28e57b030dd5669e95041104117e985d2.tar.bz2
scala-bb5e2de28e57b030dd5669e95041104117e985d2.zip
test case for xml parsing
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/xmlParsing_servlet.check19
-rw-r--r--test/files/run/xmlParsing_servlet.flags1
-rw-r--r--test/files/run/xmlParsing_servlet.scala83
3 files changed, 103 insertions, 0 deletions
diff --git a/test/files/run/xmlParsing_servlet.check b/test/files/run/xmlParsing_servlet.check
new file mode 100644
index 0000000000..f716534829
--- /dev/null
+++ b/test/files/run/xmlParsing_servlet.check
@@ -0,0 +1,19 @@
+<html>
+ <head>
+ <title>ModularFormatting</title>
+ </head>
+ <body>
+ <h2>Welcome</h2>
+ <p>
+ What follows is an example of modular formatting.
+ </p>
+ <p>
+ <table align="center"><b>hallo</b></table>
+ </p>
+ <hr></hr>
+ <p>
+ Complicated layout tasks can be encapsulated and outsourced.
+ </p>
+ <h2>Bye!</h2>
+ </body>
+ </html>
diff --git a/test/files/run/xmlParsing_servlet.flags b/test/files/run/xmlParsing_servlet.flags
new file mode 100644
index 0000000000..49cf1af47f
--- /dev/null
+++ b/test/files/run/xmlParsing_servlet.flags
@@ -0,0 +1 @@
+-Xmarkup
diff --git a/test/files/run/xmlParsing_servlet.scala b/test/files/run/xmlParsing_servlet.scala
new file mode 100644
index 0000000000..50b641d394
--- /dev/null
+++ b/test/files/run/xmlParsing_servlet.scala
@@ -0,0 +1,83 @@
+import scala.xml._ ;
+
+object Test {
+
+ val headerMsg = Text("What follows is an example of modular formatting.");
+ val footerMsg = Text("Complicated layout tasks can be encapsulated and outsourced.");
+
+ /** helper function for the main page, provides header and a footer
+ */
+ def page( ns:Seq[Node] ) = {
+ <html>
+ <head>
+ <title>ModularFormatting</title>
+ </head>
+ <body>
+ <h2>Welcome</h2>
+ <p>
+ { headerMsg }
+ </p>
+ <p>
+ { ns }
+ </p>
+ <hr/>
+ <p>
+ { footerMsg }
+ </p>
+ <h2>Bye!</h2>
+ </body>
+ </html>
+ }
+
+ /** applies beautify to every element in a sequence
+ */
+ def beautify( xs:Seq[Node] ):Seq[Node] = <b>hallo</b><i>Hwlt</i>;//xs.toList.map { beautify }
+
+ /** this is a recursive procedure that adds some attributes to the tree
+ */
+ def beautify( n:Node ):Node = n match {
+ case <td>{ xs @ _* }</td> =>
+ <td bgcolor="#AAAAFF" color="#222255">{ xs }</td>
+
+ case <table>{ xs @ _* }</table> =>
+ <table align="center">{ beautify( xs ) }</table>
+
+ case Elem( label, xs @ _* ) =>
+ Elem( label, (xs.toList.map { beautify }):_*)
+
+ case _ => n
+ }
+
+ /** this function will take a node and put it in a table
+ */
+ def format( msg:Node ):Node = {
+ <table>
+ <tr>
+ <td>{ msg }</td>
+ </tr>
+ </table>
+ }
+
+ /** returns a highlighted text node with the string given as arguemnt. if it
+ * is null, supplies a default string.
+ */
+ def getMessage( x:String ) = {
+ if( x == null )
+ <h1> This could be YOUR message ! </h1>
+ else
+ <h1> { Text( x ) } </h1>
+ }
+
+ /** the entry method
+ */
+ def doGetXML() = {
+ beautify( page( List( format( getMessage( "message" ) )) ));
+ /* page( List( format( theMessage ))); */
+
+ }
+
+ def main( args:Array[String] ) = {
+ Console.println( doGetXML() );
+ }
+
+}