diff options
-rw-r--r-- | test/files/run/xmlParsing_servlet.check | 19 | ||||
-rw-r--r-- | test/files/run/xmlParsing_servlet.flags | 1 | ||||
-rw-r--r-- | test/files/run/xmlParsing_servlet.scala | 83 |
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() ); + } + +} |