SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
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
}

Contenu connexe

Tendances

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 ProjectRoy Derks
 
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
 
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'sRoel Hartman
 
Managing state in asp.net
Managing state in asp.netManaging state in asp.net
Managing state in asp.netSireesh K
 
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 TaskPramod Singla
 
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 APIsMihail Gaberov
 
React on Rails - RailsConf 2017 (Phoenix)
 React on Rails - RailsConf 2017 (Phoenix) React on Rails - RailsConf 2017 (Phoenix)
React on Rails - RailsConf 2017 (Phoenix)Jo Cranford
 
Utilising the data attribute
Utilising the data attributeUtilising the data attribute
Utilising the data attributeRichard Martens
 
Recompacting your react application
Recompacting your react applicationRecompacting your react application
Recompacting your react applicationGreg Bergé
 
Ajax for dummies, and not only.
Ajax for dummies, and not only.Ajax for dummies, and not only.
Ajax for dummies, and not only.Nerd Tzanetopoulos
 
Higher-Order Components — Ilya Gelman
Higher-Order Components — Ilya GelmanHigher-Order Components — Ilya Gelman
Higher-Order Components — Ilya Gelman500Tech
 

Tendances (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
 

Similaire à Scala, XML and GAE

jQuery Internals + Cool Stuff
jQuery Internals + Cool StuffjQuery Internals + Cool Stuff
jQuery Internals + Cool Stuffjeresig
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On RailsWen-Tien Chang
 
Jscript Fundamentals
Jscript FundamentalsJscript Fundamentals
Jscript Fundamentalsrspaike
 
[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 SolrJsWildan Maulana
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2tonvanbart
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в MagentoMagecom Ukraine
 
Javascript Experiment
Javascript ExperimentJavascript Experiment
Javascript Experimentwgamboa
 
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)Michael Wales
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
Testing Javascript with Jasmine
Testing Javascript with JasmineTesting Javascript with Jasmine
Testing Javascript with JasmineTim Tyrrell
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorMark Leith
 

Similaire à 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
 

Dernier

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Dernier (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

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 }