Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 472cd4c15310afa8bf67530f330c69b9cb4f89b9 0 parents
@d6y authored
18 .gitignore
@@ -0,0 +1,18 @@
+.classpath
+.ensime*
+ensime_port
+.externalToolBuilders
+.project
+.settings
+target
+lift_proto.db*
+.scala_dependencies
+tasks.iml
+tasks.ipr
+tasks.iws
+lib_managed/
+src_managed/
+project/boot/
+project/plugins/project
+
+
28 README
@@ -0,0 +1,28 @@
+So you think you have a character encoding problem, eh?
+
+This Lift app attempts to insert UTF-8 data into a table it creates and then show
+you what comes back.
+
+By default the table is called foo, with a username and password of foo (see Boot.scala).
+We assume MySQL.
+
+When you run the app, visit http://127.0.0.1:8080 and see the data inserted and
+what is recovered when the table is queried.
+
+Instructions:
+
+1) Set up a MySQL database:
+
+$ mysql -u root -p --default-character-set=utf8
+MYSQL> CREATE DATABASE foo CHARACTER SET utf8 COLLATE utf8_bin;
+MYSQL> grant all privileges on foo.* to 'foo'@'localhost' identified by 'foo';
+MYSQL> flush privileges;
+
+2) Run the app:
+
+$ sbt jetty
+
+3) open http://127.0.0.1:8080/ and see the results.
+
+
+
8 project/build.properties
@@ -0,0 +1,8 @@
+#Project properties
+#Fri Nov 19 12:20:14 GMT 2010
+project.organization=charz
+project.name=Charset Test
+sbt.version=0.7.4
+project.version=1.0
+build.scala.versions=2.8.0
+project.initialize=false
23 project/build/Project.scala
@@ -0,0 +1,23 @@
+import sbt._
+import de.element34.sbteclipsify._
+
+class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) with Eclipsify {
+
+ val mavenLocal = "Local Maven Repository" at "file://"+Path.userHome+"/.m2/repository"
+ val scalatoolsSnapshot = "Scala Tools Snapshot" at "http://scala-tools.org/repo-snapshots/"
+ val scalatoolsRelease = "Scala Tools Snapshot" at "http://scala-tools.org/repo-releases/"
+
+ val liftVersion = "2.2-M1"
+
+ override def libraryDependencies = Set(
+ "net.liftweb" %% "lift-webkit" % liftVersion % "compile->default" withSources(),
+ "net.liftweb" %% "lift-testkit" % liftVersion % "compile->default",
+ "net.liftweb" %% "lift-wizard" % liftVersion % "compile->default" withSources(),
+ "net.liftweb" %% "lift-mapper" % liftVersion % "compile->default" withSources(),
+ "com.h2database" % "h2" % "1.2.138",
+ "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
+ "junit" % "junit" % "4.5" % "test->default",
+ "org.scala-tools.testing" % "specs" % "1.6.1" % "test->default",
+ "mysql" % "mysql-connector-java" % "5.1.6"
+ ) ++ super.libraryDependencies
+}
4 project/plugins/Plugins.scala
@@ -0,0 +1,4 @@
+import sbt._
+class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
+ lazy val eclipse = "de.element34" % "sbt-eclipsify" % "0.7.0"
+}
0  src/main/resources/props/default.props
No changes.
71 src/main/scala/bootstrap/liftweb/Boot.scala
@@ -0,0 +1,71 @@
+
+
+package bootstrap.liftweb
+
+import _root_.net.liftweb.http.{LiftRules, NotFoundAsTemplate, ParsePath}
+import _root_.net.liftweb.sitemap.{SiteMap, Menu, Loc}
+import _root_.net.liftweb.util.{ NamedPF }
+import _root_.net.liftweb.sitemap.Loc._
+import _root_.net.liftweb.mapper.{Schemifier, DB, StandardDBVendor, DefaultConnectionIdentifier}
+import _root_.net.liftweb.util.{Props}
+import _root_.net.liftweb.common.{Full}
+import _root_.net.liftweb.http.{S}
+import charz.model._
+
+
+/*
+
+CREATE DATABASE foo CHARACTER SET utf8 COLLATE utf8_bin;
+grant all privileges on foo.* to 'foo'@'localhost' identified by 'foo';
+flush privileges;
+
+ */
+
+class Boot {
+
+
+ val db = "foo"
+ val db_user = Full("foo")
+ val db_password = Full("foo")
+
+ def boot {
+
+
+ val vendor = new StandardDBVendor("com.mysql.jdbc.Driver",
+ "jdbc:mysql://localhost:3306/%s?useUnicode=true&characterEncoding=UTF-8".format(db),
+ db_user, db_password )
+
+ LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
+ DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
+
+
+ // Use Lift's Mapper ORM to populate the database
+ // you don't need to use Mapper to use Lift... use
+ // any ORM you want
+ Schemifier.schemify(true, Schemifier.infoF _, StringTable)
+
+
+ // where to search snippet
+ LiftRules.addToPackages("charz")
+
+ // build sitemap
+ val entries = List(Menu("Home") / "index") :::
+ List(Menu(Loc("Static", Link(List("static"), true, "/static/index"),
+ "Static Content"))) :::
+ Nil
+
+ LiftRules.uriNotFound.prepend(NamedPF("404handler"){
+ case (req,failure) => NotFoundAsTemplate(
+ ParsePath(List("exceptions","404"),"html",false,false))
+ })
+
+ LiftRules.setSiteMap(SiteMap(entries:_*))
+
+ // set character encoding
+ LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
+
+ // Make a transaction span the whole HTTP request
+ S.addAround(DB.buildLoanWrapper)
+
+ }
+}
15 src/main/scala/charz/model/StringTable.scala
@@ -0,0 +1,15 @@
+package charz.model
+
+import _root_.net.liftweb.mapper._
+import _root_.net.liftweb.util._
+import _root_.net.liftweb.common._
+
+class StringTable extends LongKeyedMapper[StringTable] with IdPK {
+
+ def getSingleton = StringTable
+
+ object content extends MappedString(this, 512)
+
+}
+
+object StringTable extends StringTable with LongKeyedMetaMapper[StringTable]
24 src/main/scala/charz/snippet/CharTest.scala
@@ -0,0 +1,24 @@
+package charz.snippet
+
+import charz.model._
+import scala.xml._
+
+// IMPORTANT: The character encoding of this file *must* be UTF-8
+// (or escape the test_data with native2ascii)
+
+class CharTest {
+
+ val test_data = "Mads ♥mann (@Mads_Hartmann)"
+
+ def go(in: NodeSeq) : NodeSeq = try {
+ val row = StringTable.create.content(test_data).saveMe
+ val row_recovered = StringTable.findByKey(row.id) map {_.content.is} openOr("FAIL!")
+ Text("Tried to store:") ++ Text(test_data) ++ Text(". Result: ") ++ Text(row_recovered)
+ } catch {
+ case e => Text(e.getMessage)
+ }
+
+
+
+
+}
1  src/main/webapp/404.html
@@ -0,0 +1 @@
+404
21 src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+"http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+<filter>
+ <filter-name>LiftFilter</filter-name>
+ <display-name>Lift Filter</display-name>
+ <description>The Filter that intercepts lift calls</description>
+ <filter-class>net.liftweb.http.LiftFilter</filter-class>
+</filter>
+
+
+<filter-mapping>
+ <filter-name>LiftFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+</filter-mapping>
+
+</web-app>
6 src/main/webapp/index.html
@@ -0,0 +1,6 @@
+<lift:surround with="default" at="content">
+
+ <p>Attempting to insert a row: <lift:CharTest.go /></p>
+
+</lift:surround>
+
5 src/main/webapp/static/index.html
@@ -0,0 +1,5 @@
+<lift:surround with="default" at="content">
+ Static content... everything you put in the /static
+ directory will be served without additions to SiteMap
+</lift:surround>
+
86 src/main/webapp/templates-hidden/default.html
@@ -0,0 +1,86 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <meta name="description" content="" />
+ <meta name="keywords" content="" />
+
+ <title>code:app:0.1-SNAPSHOT</title>
+ <lift:CSS.blueprint />
+ <lift:CSS.fancyType />
+ <script id="jquery" src="/classpath/jquery.js" type="text/javascript"/>
+ <script id="json" src="/classpath/json.js" type="text/javascript"/>
+ <style type="text/css">
+/* <![CDATA[ */
+.edit_error_class {
+ display: block;
+ color: red;
+}
+
+.sidebar ul {
+ margin:0;
+ padding:0;
+ border-bottom:1px solid #ccc;
+}
+
+
+.sidebar ul li {
+ margin:0;
+ padding:0;
+ list-style:none;
+ border:1px solid #ccc;
+ border-bottom:none;
+}
+
+.sidebar ul li a {
+ display:block;
+ padding:3px;
+ text-indent:30px;
+ text-decoration:none;
+}
+
+.sidebar ul li span {
+ display:block;
+ padding:3px;
+ text-indent:30px;
+ text-decoration:none;
+}
+
+.sidebar ul li a:hover {
+ background-color: #eee;
+}
+
+
+ /* ]]> */
+ </style>
+ </head>
+ <body>
+ <div class="container">
+ <div class="column span-12 last" style="text-align: right">
+ <h1 class="alt">app<img alt="" id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1>
+ </div>
+
+ <hr/>
+
+ <div class="column span-6 colborder sidebar">
+ <hr class="space" />
+ <lift:Menu.builder />
+ <div>
+ <lift:Msgs showAll="true"/>
+ <hr class="space" />
+ </div>
+ </div>
+
+ <div class="column span-17 last">
+ <lift:bind name="content" />
+ </div>
+
+ <hr />
+ <div class="column span-23 last" style="text-align: center">
+ <h4 class="alt">
+ <a href="http://www.liftweb.net"><i>Lift</i></a>
+ is Copyright 2007-2010 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4>
+ </div>
+
+ </div>
+ </body>
+</html>
23 src/main/webapp/templates-hidden/wizard-all.html
@@ -0,0 +1,23 @@
+<div>
+ <wizard:screen_info><div>Page <wizard:screen_number/> of <wizard:total_screens/></div></wizard:screen_info>
+ <wizard:wizard_top> <div> <wizard:bind/> </div> </wizard:wizard_top>
+ <wizard:screen_top> <div> <wizard:bind/> </div> </wizard:screen_top>
+ <wizard:errors> <div> <ul> <wizard:item> <li> <wizard:bind/> </li> </wizard:item> </ul> </div> </wizard:errors>
+ <div> <wizard:fields>
+ <table>
+ <wizard:line>
+ <tr>
+ <td>
+ <wizard:label><label wizard:for=""><wizard:bind/></label></wizard:label>
+ <wizard:help><span><wizard:bind/></span></wizard:help>
+ <wizard:field_errors> <ul> <wizard:error> <li> <wizard:bind/> </li> </wizard:error> </ul> </wizard:field_errors>
+ </td>
+ <td> <wizard:form/> </td>
+ </tr>
+ </wizard:line>
+ </table>
+ </wizard:fields> </div>
+ <div> <table> <tr> <td> <wizard:prev/> </td> <td> <wizard:cancel/> </td> <td> <wizard:next/> </td> </tr> </table> </div>
+ <wizard:screen_bottom> <div> <wizard:bind/> </div> </wizard:screen_bottom>
+ <wizard:wizard_bottom> <div> <wizard:bind/> </div> </wizard:wizard_bottom>
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.