SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
scala, xml and gae
     mark@ryall.name
xml literals
val document =
<root>
  <child>
    <grandchild an_attribute=quot;value1quot; />
    <grandchild an_attribute=quot;value2quot; />
  </child>
</root>
val document =
scala.xml.Elem(null, quot;rootquot;, scala.xml.Null, scala.xml.TopScope,
  scala.xml.Elem(null, quot;childquot;, scala.xml.Null, scala.xml.TopScope,
    scala.xml.Elem(null, quot;grandchildquot;,
       new scala.xml.UnprefixedAttribute(quot;an_attributequot;,quot;value1quot;, scala.xml.Null),
       scala.xml.TopScope,
       scala.xml.Text(quot;content1quot;)
    ),
    scala.xml.Elem(null, quot;grandchildquot;,
       new scala.xml.UnprefixedAttribute(quot;an_attributequot;,quot;value2quot;, scala.xml.Null),
       scala.xml.TopScope,
       scala.xml.Text(quot;content2quot;)
    )
  )
)
extraction operators
// immediate descendant of document called 'child'
document  quot;childquot;

// any descendant of document called 'another_grandchild'
document  quot;another_grandchildquot;

// any descendant attribute called 'an_attribute'
document  quot;@an_attributequot;
pattern matching
• match single node with {variable}
• match node sequence with {variable @ _*}
• cannot match attribute directly
val a = document match {
  case Elem(_, quot;rootquot;, _, _, _*) => true
  case _ => null
}
val a = document match {
  case <root>{ _* }</root> => true
  case _ => false
}
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(quot;leafquot;)
  }
}
Concatenation


def add(p: Node, newEntry: Node ): Node =
  p match {
  case <div>{ ch @ _* }</div> =>
    <div>{ ch }{ newEntry }</div>
  }
Extracting attributes



document match {
  case n @ <grandchild>{ _* }</grandchild> =>
    println(n.attribute(quot;an_attributequot;))
}
persisting and restoring
scala.xml.XML.saveFull(quot;filename.xmlquot;, document,
  quot;UTF-8quot;, true, null)

val document2 = scala.xml.XML.loadFile(quot;filename.xmlquot;)
stream parsing
val src =
  scala.io.Source.fromString(quot;<root><child></child></root>quot;)
val er = new scala.xml.pull.XMLEventReader().initialize(src)
er.next
...
building xml
var variable1 = quot;value1quot;

val variable2 = <another_grandchild an_attribute=quot;value2quot; />

var document =
  <root>
    <child>
      <grandchild an_attribute={variable1} />
      {variable2}
    </child>
  </root>
google app engine
• ‘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
• 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/
basics
class Servlet extends HttpServlet {
  override def doGet(request: HttpServletRequest, response: HttpServletResponse):
    Unit = {
        val out = response.getWriter()
...
        out.println(<html>{head}<body>{body}</body></html>)
    }
}
authentication
var userService = UserServiceFactory.getUserService();
var user = userService.getCurrentUser();

if (user == null) {
  response.sendRedirect(userService.createLoginURL(request.getRequestURI()))
  return
}
persistence
@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
}

Weitere ähnliche Inhalte

Was ist angesagt?

Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Roel Hartman
 

Was ist angesagt? (20)

React redux
React reduxReact redux
React redux
 
Using ReasonML For Your Next JavaScript Project
Using ReasonML For Your Next JavaScript ProjectUsing ReasonML For Your Next JavaScript Project
Using ReasonML For Your Next JavaScript Project
 
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...Developing A Real World Logistic Application With Oracle Application - UKOUG ...
Developing A Real World Logistic Application With Oracle Application - UKOUG ...
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API's
 
Managing state in asp.net
Managing state in asp.netManaging state in asp.net
Managing state in asp.net
 
RSpec
RSpecRSpec
RSpec
 
React&redux
React&reduxReact&redux
React&redux
 
7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task7\9 SSIS 2008R2_Training - Script Task
7\9 SSIS 2008R2_Training - Script Task
 
Api workshop
Api workshopApi workshop
Api workshop
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
 
React nocojs
React nocojsReact nocojs
React nocojs
 
Excellent
ExcellentExcellent
Excellent
 
React on Rails - RailsConf 2017 (Phoenix)
 React on Rails - RailsConf 2017 (Phoenix) React on Rails - RailsConf 2017 (Phoenix)
React on Rails - RailsConf 2017 (Phoenix)
 
Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attribute
 
BDD in iOS with Cedar
BDD in iOS with CedarBDD in iOS with Cedar
BDD in iOS with Cedar
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react application
 
Ajax Introduction
Ajax IntroductionAjax Introduction
Ajax Introduction
 
Ajax for dummies, and not only.
Ajax for dummies, and not only.Ajax for dummies, and not only.
Ajax for dummies, and not only.
 
Higher-Order Components — Ilya Gelman
Higher-Order Components — Ilya GelmanHigher-Order Components — Ilya Gelman
Higher-Order Components — Ilya Gelman
 

Ähnlich wie Scala, XML and GAE

Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentals
rspaike
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
Solr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJsSolr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJs
Wildan Maulana
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
tonvanbart
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 

Ähnlich wie Scala, XML and GAE (20)

Seam Glassfish Slidecast
Seam Glassfish SlidecastSeam Glassfish Slidecast
Seam Glassfish Slidecast
 
jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuff
 
Java Script Best Practices
Java Script Best PracticesJava Script Best Practices
Java Script Best Practices
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentals
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Solr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJsSolr and symfony in Harmony with SolrJs
Solr and symfony in Harmony with SolrJs
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
Javascript Experiment
Javascript ExperimentJavascript Experiment
Javascript Experiment
 
Struts2
Struts2Struts2
Struts2
 
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
Introduction to CodeIgniter (RefreshAugusta, 20 May 2009)
 
Introduction to JQuery
Introduction to JQueryIntroduction to JQuery
Introduction to JQuery
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
PHP
PHP PHP
PHP
 
displaytag
displaytagdisplaytag
displaytag
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with Jasmine
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
 
Merb jQuery
Merb jQueryMerb jQuery
Merb jQuery
 
สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1สปริงเฟรมเวิร์ค4.1
สปริงเฟรมเวิร์ค4.1
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Scala, XML and GAE

  • 1. scala, xml and gae mark@ryall.name
  • 3. val document = <root> <child> <grandchild an_attribute=quot;value1quot; /> <grandchild an_attribute=quot;value2quot; /> </child> </root>
  • 4. val document = scala.xml.Elem(null, quot;rootquot;, scala.xml.Null, scala.xml.TopScope, scala.xml.Elem(null, quot;childquot;, scala.xml.Null, scala.xml.TopScope, scala.xml.Elem(null, quot;grandchildquot;, new scala.xml.UnprefixedAttribute(quot;an_attributequot;,quot;value1quot;, scala.xml.Null), scala.xml.TopScope, scala.xml.Text(quot;content1quot;) ), scala.xml.Elem(null, quot;grandchildquot;, new scala.xml.UnprefixedAttribute(quot;an_attributequot;,quot;value2quot;, scala.xml.Null), scala.xml.TopScope, scala.xml.Text(quot;content2quot;) ) ) )
  • 6. // immediate descendant of document called 'child' document quot;childquot; // any descendant of document called 'another_grandchild' document quot;another_grandchildquot; // any descendant attribute called 'an_attribute' document quot;@an_attributequot;
  • 8. • match single node with {variable} • match node sequence with {variable @ _*} • cannot match attribute directly
  • 9. val a = document match { case Elem(_, quot;rootquot;, _, _, _*) => 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(quot;leafquot;) } }
  • 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(quot;an_attributequot;)) }
  • 15. scala.xml.XML.saveFull(quot;filename.xmlquot;, document, quot;UTF-8quot;, true, null) val document2 = scala.xml.XML.loadFile(quot;filename.xmlquot;)
  • 17. val src = scala.io.Source.fromString(quot;<root><child></child></root>quot;) val er = new scala.xml.pull.XMLEventReader().initialize(src) er.next ...
  • 19. var variable1 = quot;value1quot; val variable2 = <another_grandchild an_attribute=quot;value2quot; /> var document = <root> <child> <grandchild an_attribute={variable1} /> {variable2} </child> </root>
  • 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/
  • 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>) } }
  • 26. var userService = UserServiceFactory.getUserService(); var user = userService.getCurrentUser(); if (user == null) { response.sendRedirect(userService.createLoginURL(request.getRequestURI())) return }
  • 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 }