Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.68 KB | None | 0 0
  1.   private def renderTpl(response: HttpServletResponse, tplPath: String, transformer: Transformer) = {
  2.     val doc = transformer(loadTpl(tplPath))
  3.     response.setContentType("text/html; charset=utf-8")
  4.     response.getWriter.println("<!doctype html>")
  5.     response.getWriter.println(doc.map(Html5.toString).mkString)
  6.   }
  7.  
  8.   private def loadTpl(path: String) = {
  9.     val parserFactory = new org.ccil.cowan.tagsoup.jaxp.SAXFactoryImpl
  10.     val adapter = new scala.xml.parsing.NoBindingFactoryAdapter
  11.     val tpl = getClass.getResourceAsStream(path)
  12.     val source = new org.xml.sax.InputSource(tpl)
  13.     val parser = parserFactory.newSAXParser
  14.     adapter.loadXML(source, parser)
  15.   }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement