Created
April 11, 2009 03:44
-
-
Save geelen/93446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package guestbook | |
import _root_.com.google.appengine.api.users.{UserService, User, UserServiceFactory} | |
import _root_.javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet} | |
import _root_.scala.collection.jcl.{Buffer, Conversions} | |
import _root_.scala.xml.Elem | |
import org.apache.taglibs.standard.functions.Functions | |
class GuestbookServlet extends HttpServlet { | |
override def doGet(req: HttpServletRequest, resp: HttpServletResponse) { | |
val userService = UserServiceFactory.getUserService | |
val user = userService.getCurrentUser | |
resp.setContentType("text/html") | |
val data: Elem = | |
<html> | |
<head> | |
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css"/> | |
</head> | |
<body> <div>{userLolz(user, userService, req)}</div> <div>{lols}</div> | |
<form action="/sign" method="post"> | |
<div> <textarea name="content" rows="3" cols="60"> </textarea> </div> | |
<div> <input type="submit" value="Post Greeting"/> </div> | |
</form> </body> | |
</html> | |
resp.getWriter().println(data.toString) | |
} | |
def lols = { | |
val pm = PMF.get.getPersistenceManager | |
//odd | |
val query = "select from guestbook.Greeting order by date desc"; | |
// val query = "select from " + Greeting.getName + " order by date desc"; | |
val subdata = casty(List.fromArray(StaticLolz.ffs(pm, query))) | |
// val subdata = List(Conversions.convertList(pm.newQuery(query).execute.asInstanceOf[java.util.List[Greeting]]).toString) | |
pm.close | |
subdata | |
} | |
def userLolz(user: User, userService: UserService, req: HttpServletRequest) = | |
<p>{if (user != null) { | |
<span>Hello, {user.getNickname()}! (You can <a href={'"' + userService.createLogoutURL(req.getRequestURI) + '"'}>sign out</a>.)</span> | |
} else { | |
<span>Hello!<a href={'"' + userService.createLoginURL(req.getRequestURI) + '"'}>Sign in</a>to include your name with greetings you post.</span> | |
}}</p> | |
def casty(greetings: List[Greeting]) = { | |
if (greetings.isEmpty) { | |
<p>The guestbook has no messages.</p> | |
} else { | |
<div>WAT</div> | |
for (val g <- greetings) { | |
if (g.getAuthor == null) { | |
<p>An anonymous person wrote:</p> | |
} else { | |
<p> <b>{g.getAuthor.getNickname}</b>wrote:</p> | |
} | |
<blockquote>{Functions.escapeXml(g.getContent)}</blockquote> | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment