Skip to content

Commit

Permalink
I finally figured out how to parse JSON files in Grails.
Browse files Browse the repository at this point in the history
Secondarily, I added some Gant Scripts.

I can use this to create a BootStrap class that won't be so unwieldy and
difficult to use.  The below files outline most of the changes.  I also
added some Gant scripts just to help out with future code migrations and
such
  • Loading branch information
klauern committed Feb 16, 2009
1 parent d7fa6aa commit aa8445b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
28 changes: 15 additions & 13 deletions docs/SomeBootStrapInfo.json
Expand Up @@ -13,20 +13,22 @@
*/

{
"Contacts" : [
"Contacts" : [
{
"full_name": "Nick Klauer",
"email":"NicholasKlauer@alliantenergy.com",
"work_phone":"1.608.458.3922",
"mobile_phone":"1.608.516.7615"
"full_name" :"Nick Klauer",
"email" :"NicholasKlauer@alliantenergy.com",
"work_phone" :"1.608.458.3922",
"mobile_phone" :"1.608.516.7615"
},
{ "full_name":"Allan Rosanes",
"email":"AllanRosanes@alliantenergy.com",
"work_phone":"?????",
"mobile_phone":"????"}
{
"full_name" :"Allan Rosanes",
"email" :"AllanRosanes@alliantenergy.com",
"work_phone" :"?????",
"mobile_phone" :"????"
}
],
"Zones" : [],
"Events": [],
"Ports" :[],
"Domains":[]
"Zones" : [],
"Events" : [],
"Ports" : [],
"Domains" : []
}
26 changes: 13 additions & 13 deletions grails-app/conf/Config.groovy
@@ -1,7 +1,7 @@
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// grails.config.locations = [ "classpath:${appName}-config.properties",
// grails.config.locations = [ "classpath:${appName}-config.properties",
// "classpath:${appName}-config.groovy",
// "file:${userHome}/.grails/${appName}-config.properties",
// "file:${userHome}/.grails/${appName}-config.groovy"]
Expand All @@ -11,18 +11,18 @@
// }
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
xml: ['text/xml', 'application/xml'],
text: 'text-plain',
js: 'text/javascript',
rss: 'application/rss+xml',
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
all: '*/*',
json: ['application/json','text/json'],
form: 'application/x-www-form-urlencoded',
multipartForm: 'multipart/form-data'
]
xml: ['text/xml', 'application/xml'],
text: 'text-plain',
js: 'text/javascript',
rss: 'application/rss+xml',
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
all: '*/*',
json: ['application/json','text/json'],
form: 'application/x-www-form-urlencoded',
multipartForm: 'multipart/form-data'
]
// The default codec used to encode data with ${}
grails.views.default.codec="none" // none, html, base64
grails.views.gsp.encoding="UTF-8"
Expand Down
14 changes: 14 additions & 0 deletions scripts/BootStrapDomains.groovy
@@ -0,0 +1,14 @@
/*
* The below lines show a simple way to get at a JSON file and parse it out.
* It's pretty easy. Look at the SomeBootStrapInfo.json file in the docs/directory
* and see for yourself how this is set up. I plan on making this into the
* BootStrap.groovy file, but I have some minor tweaking to do, as well as trying
* to find the way to create relationships.
*
*/

import grails.converters.*

def jsonArray = JSON.parse(new File("./docs/SomeBootStrapInfo.json").getText())
def contacts = jsonArray.get("Contacts")
contacts[1].toString()
14 changes: 14 additions & 0 deletions scripts/CreateViewsAndControllers.groovy
@@ -0,0 +1,14 @@
import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU

grailsHome = Ant.project.properties."environment.GRAILS_HOME"

includeTargets << grailsScript ( "Init" )
includeTool << gant.tools.Execute

target('default': "The description of the script goes here!") {
doStuff()
}

target(doStuff: "The implementation task") {

}

0 comments on commit aa8445b

Please sign in to comment.