Scala, XML and GAE

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    4 Favorites

    Scala, XML and GAE - Presentation Transcript

    1. scala, xml and gae mark@ryall.name
    2. xml literals
    3. val document = <root> <child> <grandchild an_attribute=\"value1\" /> <grandchild an_attribute=\"value2\" /> </child> </root>
    4. val document = scala.xml.Elem(null, \"root\", scala.xml.Null, scala.xml.TopScope, scala.xml.Elem(null, \"child\", scala.xml.Null, scala.xml.TopScope, scala.xml.Elem(null, \"grandchild\", new scala.xml.UnprefixedAttribute(\"an_attribute\",\"value1\", scala.xml.Null), scala.xml.TopScope, scala.xml.Text(\"content1\") ), scala.xml.Elem(null, \"grandchild\", new scala.xml.UnprefixedAttribute(\"an_attribute\",\"value2\", scala.xml.Null), scala.xml.TopScope, scala.xml.Text(\"content2\") ) ) )
    5. extraction operators
    6. // immediate descendant of document called 'child' document \\ \"child\" // any descendant of document called 'another_grandchild' document \\\\ \"another_grandchild\" // any descendant attribute called 'an_attribute' document \\\\ \"@an_attribute\"
    7. pattern matching
    8. • match single node with {variable} • match node sequence with {variable @ _*} • cannot match attribute directly
    9. val a = document match { case Elem(_, \"root\", _, _, _*) => true case _ => null }
    10. val a = document match { case <root>{ _* }</root> => true case _ => false }
    11. def process(node: scala.xml.Node): Unit = { println(node) node match { case <root>{contents @ _* }</root> => for (a <- contents) process(a) case <child>{contents @ _*}</child> => for (a <- contents) process(a) case <grandchild>{contents @ _*}</grandchild> => for (a <- contents) process(a) case _ => println(\"leaf\") } }
    12. Concatenation def add(p: Node, newEntry: Node ): Node = p match { case <div>{ ch @ _* }</div> => <div>{ ch }{ newEntry }</div> }
    13. Extracting attributes document match { case n @ <grandchild>{ _* }</grandchild> => println(n.attribute(\"an_attribute\")) }
    14. persisting and restoring
    15. scala.xml.XML.saveFull(\"filename.xml\", document, \"UTF-8\", true, null) val document2 = scala.xml.XML.loadFile(\"filename.xml\")
    16. stream parsing
    17. val src = scala.io.Source.fromString(\"<root><child></child></root>\") val er = new scala.xml.pull.XMLEventReader().initialize(src) er.next ...
    18. building xml
    19. var variable1 = \"value1\" val variable2 = <another_grandchild an_attribute=\"value2\" /> var document = <root> <child> <grandchild an_attribute={variable1} /> {variable2} </child> </root>
    20. google app engine
    21. • ‘cloud’ web hosting environment on google’s infrastructure • uses non relational ‘bigtable’ for data persistance • user authentication uses google accounts or openid • also has email (sending), memcache and image manipulation services
    22. • working example: • code: http://bitbucket.org/markryall/scalagae • live: http://pairs.appspot.com • use latest datanucleus enhancer from http:// www.datanucleus.org/downloads/maven2- nightly/org/datanucleus/datanucleus- enhancer/1.1.2/
    23. basics
    24. class Servlet extends HttpServlet { override def doGet(request: HttpServletRequest, response: HttpServletResponse): Unit = { val out = response.getWriter() ... out.println(<html>{head}<body>{body}</body></html>) } }
    25. authentication
    26. var userService = UserServiceFactory.getUserService(); var user = userService.getCurrentUser(); if (user == null) { response.sendRedirect(userService.createLoginURL(request.getRequestURI())) return }
    27. persistence
    28. @PersistenceCapable {val identityType = IdentityType.APPLICATION} class Person(@Persistent var firstName: String,@Persistent var lastName: String) { @PrimaryKey @Persistent {val valueStrategy = IdGeneratorStrategy.IDENTITY} var id: java.lang.Long = null }

    + markryallmarkryall, 7 months ago

    custom

    1165 views, 4 favs, 0 embeds more stats

    Presentation at first Melbourne Scala User Group 27 more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1165
      • 1165 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 4
    • Downloads 21
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags