From bb5e2de28e57b030dd5669e95041104117e985d2 Mon Sep 17 00:00:00 2001 From: buraq Date: Thu, 25 Mar 2004 11:19:13 +0000 Subject: test case for xml parsing --- test/files/run/xmlParsing_servlet.check | 19 ++++++++ test/files/run/xmlParsing_servlet.flags | 1 + test/files/run/xmlParsing_servlet.scala | 83 +++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 test/files/run/xmlParsing_servlet.check create mode 100644 test/files/run/xmlParsing_servlet.flags create mode 100644 test/files/run/xmlParsing_servlet.scala (limited to 'test/files/run') 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 @@ + + + ModularFormatting + + +

Welcome

+

+ What follows is an example of modular formatting. +

+

+ hallo
+

+
+

+ Complicated layout tasks can be encapsulated and outsourced. +

+

Bye!

+ + 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] ) = { + + + ModularFormatting + + +

Welcome

+

+ { headerMsg } +

+

+ { ns } +

+
+

+ { footerMsg } +

+

Bye!

+ + + } + + /** applies beautify to every element in a sequence + */ + def beautify( xs:Seq[Node] ):Seq[Node] = halloHwlt;//xs.toList.map { beautify } + + /** this is a recursive procedure that adds some attributes to the tree + */ + def beautify( n:Node ):Node = n match { + case { xs @ _* } => + { xs } + + case { xs @ _* }
=> + { beautify( xs ) }
+ + 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 = { + + + + +
{ msg }
+ } + + /** 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 ) +

This could be YOUR message !

+ else +

{ Text( x ) }

+ } + + /** the entry method + */ + def doGetXML() = { + beautify( page( List( format( getMessage( "message" ) )) )); + /* page( List( format( theMessage ))); */ + + } + + def main( args:Array[String] ) = { + Console.println( doGetXML() ); + } + +} -- cgit v1.2.3