Permalink
Browse files

First revision of the Gaelyk project

  • Loading branch information...
0 parents commit 0ee2ca4e6edd086814b90d48084153af281147be Guillaume Laforge committed Jul 18, 2009
Showing with 2,143 additions and 0 deletions.
  1. +31 −0 core/build.groovy
  2. BIN core/lib/appengine-api-1.0-sdk-1.2.2.jar
  3. BIN core/lib/geronimo-servlet_2.5_spec-1.2.jar
  4. BIN core/lib/groovy-all-1.7-beta-1-SNAPSHOT.jar
  5. +53 −0 core/src/main/groovyx/gaelyk/servlet/GaelykBindingEnhancer.groovy
  6. +176 −0 core/src/main/groovyx/gaelyk/servlet/GaelykCategory.groovy
  7. +48 −0 core/src/main/groovyx/gaelyk/servlet/GaelykServlet.groovy
  8. +46 −0 core/src/main/groovyx/gaelyk/servlet/GaelykTemplateServlet.groovy
  9. BIN graphics/gaelyk-logo-hires-white-background.png
  10. BIN graphics/gaelyk-logo.psd
  11. BIN graphics/gaelyk-medium-transparent.png
  12. BIN graphics/gaelyk-small-favicon.png
  13. +16 −0 template-project/build.groovy
  14. +10 −0 template-project/war/WEB-INF/appengine-web.xml
  15. +3 −0 template-project/war/WEB-INF/groovy/datetime.groovy
  16. +3 −0 template-project/war/WEB-INF/includes/footer.gtpl
  17. +15 −0 template-project/war/WEB-INF/includes/header.gtpl
  18. BIN template-project/war/WEB-INF/lib/appengine-api-1.0-sdk-1.2.2.jar
  19. BIN template-project/war/WEB-INF/lib/gaelyk-0.1.jar
  20. BIN template-project/war/WEB-INF/lib/groovy-all-1.7-beta-1-SNAPSHOT.jar
  21. +23 −0 template-project/war/WEB-INF/web.xml
  22. +9 −0 template-project/war/css/main.css
  23. +10 −0 template-project/war/datetime.gtpl
  24. BIN template-project/war/images/gaelyk-small-favicon.png
  25. BIN template-project/war/images/gaelyk.png
  26. BIN template-project/war/images/google-app-engine-groovy.png
  27. +15 −0 template-project/war/index.gtpl
  28. +9 −0 website/war/WEB-INF/appengine-web.xml
  29. +8 −0 website/war/WEB-INF/includes/footer.gtpl
  30. +38 −0 website/war/WEB-INF/includes/header.gtpl
  31. BIN website/war/WEB-INF/lib/appengine-api-1.0-sdk-1.2.2.jar
  32. BIN website/war/WEB-INF/lib/gaelyk-0.1.jar
  33. BIN website/war/WEB-INF/lib/groovy-all-1.7-beta-1-SNAPSHOT.jar
  34. +23 −0 website/war/WEB-INF/web.xml
  35. BIN website/war/css/help.png
  36. BIN website/war/css/magnifier.png
  37. +142 −0 website/war/css/main.css
  38. BIN website/war/css/page_white_code.png
  39. BIN website/war/css/page_white_copy.png
  40. BIN website/war/css/printer.png
  41. +342 −0 website/war/css/shCore.css
  42. +196 −0 website/war/css/shThemeDefault.css
  43. BIN website/war/css/wrapping.png
  44. +13 −0 website/war/download/index.gtpl
  45. BIN website/war/flash/clipboard.swf
  46. BIN website/war/images/black-shade.png
  47. BIN website/war/images/gaelyk-small-favicon.png
  48. BIN website/war/images/gaelyk.png
  49. BIN website/war/images/google-app-engine-groovy.png
  50. BIN website/war/images/gray-shade-top-down.png
  51. BIN website/war/images/gray-shade.png
  52. BIN website/war/images/pink-shade.png
  53. +53 −0 website/war/index.gtpl
  54. +19 −0 website/war/js/jquery-1.3.2.min.js
  55. +69 −0 website/war/js/shBrushGroovy.js
  56. +71 −0 website/war/js/shBrushXml.js
  57. +30 −0 website/war/js/shCore.js
  58. +30 −0 website/war/js/shLegacy.js
  59. +642 −0 website/war/tutorial/index.gtpl
@@ -0,0 +1,31 @@
+def ant = new AntBuilder().sequential {
+
+ // current Gaelyk version
+ version = '0.1'
+
+ // various directory places and file names
+ src = "src/main"
+ lib = "lib"
+ target = "target"
+ classes = "${target}/classes"
+ jarname = "${target}/gaelyk-${version}.jar"
+
+ // create the target and classes directories
+ mkdir dir: classes
+
+ // compile all the source code with the joint compiler
+ taskdef name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc"
+ groovyc srcdir: src, destdir: classes, {
+ classpath {
+ fileset dir: lib, {
+ include name: "*.jar"
+ }
+ pathelement path: classes
+ }
+ javac source: "1.5", target: "1.5", debug: "on"
+ }
+
+ // create the Gaelyk JAR
+ jar basedir: classes, destfile: jarname
+}
+
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package groovyx.gaelyk.servlet
+
+import groovy.lang.Binding;
+
+import com.google.appengine.api.datastore.DatastoreServiceFactory
+import com.google.appengine.api.images.ImagesServiceFactory
+import com.google.appengine.api.mail.MailServiceFactory
+import com.google.appengine.api.memcache.MemcacheServiceFactory
+import com.google.appengine.api.urlfetch.URLFetchServiceFactory
+import com.google.appengine.api.users.UserService
+import com.google.appengine.api.users.UserServiceFactory
+
+/**
+ * @author Marcel Overdijk
+ * @author Guillaume Laforge
+ */
+class GaelykBindingEnhancer {
+
+ private Binding binding
+
+ GaelykBindingEnhancer(Binding binding) {
+ this.binding = binding
+ }
+
+ void bind() {
+ // bind google app engine services
+ binding.setVariable("datastoreService", DatastoreServiceFactory.datastoreService)
+ binding.setVariable("memcacheService", MemcacheServiceFactory.memcacheService)
+ binding.setVariable("urlFetchService", URLFetchServiceFactory.URLFetchService)
+ binding.setVariable("mailService", MailServiceFactory.mailService)
+ binding.setVariable("imagesService", ImagesServiceFactory.imagesService)
+
+ // bind user service and current user
+ UserService userService = UserServiceFactory.userService
+ binding.setVariable("userService", userService)
+ binding.setVariable("user", userService.getCurrentUser())
+ }
+}
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package groovyx.gaelyk.servlet
+
+import com.google.appengine.api.mail.MailService.Message
+import com.google.appengine.api.mail.MailService
+import com.google.appengine.api.datastore.Entity
+import com.google.appengine.api.datastore.Transaction
+import com.google.appengine.api.datastore.DatastoreService
+import com.google.appengine.api.datastore.DatastoreServiceImpl
+import com.google.appengine.api.datastore.DatastoreServiceFactory
+
+/**
+ * Category methods decorating the Google App Engine SDK classes
+ * adding new shortcut methods to simplify the usage of the SDK
+ * from within Groovy servlets and templates.
+ *
+ * @author Guillaume Laforge
+ */
+class GaelykCategory {
+
+ // ----------------------------------------------------------------
+ // Category methods dedicated to the Mail service
+ // ----------------------------------------------------------------
+
+ /**
+ * Create a <code>MailService.Message</code> out of Map parameters.
+ * Each map key must correspond to a valid property on the message object.
+ */
+
+ private static Message createMessageFromMap(Map m) {
+ def msg = new Message()
+ m.each {k, v ->
+ if (v instanceof String) v = [v]
+ msg[k] = v
+ }
+ return msg
+ }
+
+ /**
+ * Additional <code>send()</code> method taking a map as parameter.
+ * The map can contain the normal properties of the
+ * <code>MailService.Message</code> class.
+ *
+ * @throws groovy.lang.MissingPropertyException when the key doesn't correspond
+ * to a property of the <code>MailService.Message</code> class.
+ */
+ static void send(MailService mailService, Map m) {
+ Message msg = createMessageFromMap(m)
+ mailService.send msg
+ }
+
+
+ /**
+ * Additional <code>sendToAdmins()</code> method for sending emails to the application admins.
+ * This method is taking a map as parameter.
+ * The map can contain the normal properties of the
+ * <code>MailService.Message</code> class.
+ *
+ * @param
+ *
+ * @throws groovy.lang.MissingPropertyException when the key doesn't correspond
+ * to a property of the <code>MailService.Message</code> class.
+ */
+ static void sendToAdmins(MailService mailService, Map m) {
+ Message msg = createMessageFromMap(m)
+ mailService.sendToAdmins msg
+ }
+
+ // ----------------------------------------------------------------
+ // Category methods dedicated to the low-level DataStore service
+ // ----------------------------------------------------------------
+
+ /**
+ * Provides a shortcut notation to get a property of an entity.
+ * Instead of writing
+ * <code>entity.getProperty('propertyName')</code>
+ * You can use the shortcut
+ * <code>entity['propertyName']</code>
+ */
+ static Object getAt(Entity entity, String name) {
+ entity.getProperty(name)
+ }
+
+ /**
+ * Provides a shortcut notation to get a property of an entity.
+ * Instead of writing
+ * <code>entity.getProperty('propertyName')</code>
+ * You can use the shortcut
+ * <code>entity.propertyName</code>
+ */
+ static Object get(Entity entity, String name) {
+ entity.getProperty(name)
+ }
+
+ /**
+ * Provides a shortcut notation to set a property of an entity.
+ * Instead of writing
+ * <code>entity.setProperty('propertyName', value)</code>
+ * You can use the shortcut
+ * <code>entity.propertyName = value</code>
+ * Or
+ * <code>entity['propertyName'] = value</code>
+ */
+ static Object setAt(Entity entity, String name, Object value) {
+ entity.setProperty(name, value)
+ }
+
+ /**
+ * Provides a shortcut notation to set a property of an entity.
+ * Instead of writing
+ * <code>entity.setProperty('propertyName', value)</code>
+ * You can use the shortcut
+ * <code>entity.propertyName = value</code>
+ * Or
+ * <code>entity['propertyName'] = value</code>
+ */
+ static Object set(Entity entity, String name, Object value) {
+ entity.setProperty(name, value)
+ }
+
+ /**
+ * Save this entity in the data store.
+ * Usage: <code>entity.save()</code>
+ */
+ static Object save(Entity entity) {
+ DatastoreServiceFactory.datastoreService.put(entity)
+ }
+
+ /**
+ * Delete this entity from the data store.
+ * Usage: <code>entity.delete()</code>
+ */
+ static Object delete(Entity entity) {
+ DatastoreServiceFactory.datastoreService.delete(entity.key)
+ }
+
+ /**
+ * With this method, transaction handling is done transparently.
+ * The transaction is committed if the closure executed properly.
+ * The transaction is rollbacked if anything went wrong.
+ * You can use this method as follows:
+ * <code>
+ * datastoreService.withTransaction { transaction ->
+ * // do something in that transaction
+ * }
+ * </code>
+ */
+ static Transaction withTransaction(DatastoreService service, Closure c) {
+ Transaction transaction = service.beginTransaction()
+ try {
+ // pass the transaction as single parameter of the closure
+ c(transaction)
+ // commit the transaction if the closure executed without throwing an exception
+ transaction.commit()
+ } catch (e) {
+ // rollback on error
+ transaction.rollback()
+ // rethrow the exception
+ throw e
+ }
+ }
+}
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package groovyx.gaelyk.servlet
+
+import groovy.servlet.GroovyServlet
+import groovy.servlet.ServletBinding
+
+import javax.servlet.http.HttpServletRequest
+import javax.servlet.http.HttpServletResponse
+import java.io.IOException
+
+/**
+ * The Gaelyk servlet extends Groovy's own Groovy servlet
+ * to inject Google App Engine dedicated services in the binding of the Groolets.
+ *
+ * @author Marcel Overdijk
+ * @author Guillaume Laforge
+ *
+ * @see groovy.servlet.GroovyServlet
+ */
+class GaelykServlet extends GroovyServlet {
+
+ @Override
+ protected void setVariables(ServletBinding binding) {
+ GaelykBindingEnhancer enhancer = new GaelykBindingEnhancer(binding)
+ enhancer.bind()
+ }
+
+ @Override
+ void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ use (GaelykCategory) {
+ super.service(request, response)
+ }
+ }
+}
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2009 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package groovyx.gaelyk.servlet
+
+import groovy.servlet.ServletBinding
+import groovy.servlet.TemplateServlet
+import javax.servlet.http.HttpServletRequest
+import javax.servlet.http.HttpServletResponse
+
+/**
+ * The Gaelyk template servlet extends Groovy's own template servlet
+ * to inject Google App Engine dedicated services in the binding of the Groolets.
+ *
+ * @author Marcel Overdijk
+ * @author Guillaume Laforge
+ *
+ * @see groovy.servlet.TemplateServlet
+ */
+class GaelykTemplateServlet extends TemplateServlet {
+
+ @Override
+ protected void setVariables(ServletBinding binding) {
+ GaelykBindingEnhancer enhancer = new GaelykBindingEnhancer(binding)
+ enhancer.bind()
+ }
+
+ @Override
+ void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ use (GaelykCategory) {
+ super.service(request, response)
+ }
+ }
+}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,16 @@
+def ant = new AntBuilder().sequential {
+ webinf = "war/WEB-INF"
+
+ taskdef name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc"
+
+ groovyc srcdir: "src", destdir: "${webinf}/classes", {
+ classpath {
+ fileset dir: "${webinf}/lib", {
+ include name: "*.jar"
+ }
+ pathelement path: "${webinf}/classes"
+ }
+ javac source: "1.5", target: "1.5", debug: "on"
+ }
+}
+
@@ -0,0 +1,10 @@
+<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
+ <application>myappid</application>
+
+ <version>1</version>
+
+ <static-files>
+ <exclude path="/WEB-INF/**.groovy" />
+ <exclude path="**.gtpl" />
+ </static-files>
+</appengine-web-app>
@@ -0,0 +1,3 @@
+request.setAttribute 'datetime', new Date().toString()
+
+forward '/datetime.gtpl'
@@ -0,0 +1,3 @@
+ </div>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 0ee2ca4

Please sign in to comment.