groovy

In Grails, how can I get a ConfigObject of messages.properties for locale?

In Grails, I would like to get a ConfigObject reference to the loaded messages properties file for the current locale. Or some way to easily read in the messages properties (for the current locale) in it's entirety. I want to convert it to JSON and send it back to the client to be used to lookup strings via javascript. In essence I want...

Need help resolving a java.net.ConnectException using webtest-plugin for grails

I'm trying to setup a webtest plugin with an existing grails app that's already pretty far along... I'm using grails 1.2.2, groovy version 1.6.4, webtest-plugin 2.0.4 I have one functional web test, which has a single call to invoke("http://localhost:8080/myApp/") I've overridden the existing URLMappings.groovy file so that "/" map...

Groovy tcp readline

I recently created a tcp server in groovy and am wondering how to get it to behave similar to telnet. For example, I run my tcp server and pull up the cmd prompt to telnet the port of the script and send it commands that its looking for. Most of the commands send back one line/word of information. However there are a few that send back ...

A Java/Groovy API to generate Groovy source files

I'm looking for a Java or Groovy library to generate Groovy classes source files. I've CodeModel and this post but they are for Java. Basically, I'd like to generate a Groovy class programmatically knowing the class name, the class attributes and generate particular methods depending on the class attributes. I know Groovy templates, bu...

(Groovy/Grails) What to do about URLs in JavaScript module that need to change per environment (dev/prod/qa/etc)

I’ve punted on this before, and/or hacked around it, but I’d like to solve it properly once and for all. The question is what to do if I need a URL that changes per environment in a JavaScript module that's part of a Groovy/Grails project For example, I have a JavaScript module that contains this function: function init() { dojox....

Why groovy sql remove schema name from SQL queries?

I need to execute this query: Select * from my_schema.table_within_schema Unfortunately groogy.sql.SQL is removing my_schema and executing a query without schema information: Select * from table_within_schema I wonder if it is possible to force groovy.sql.Sql to keep a schema name in the query. Groovy: 1.7, Db: I use a jdbc dr...

Can I redefine String#length?

I'd like to re-implement a method of a Java class. For example, for "hi".length() to return 4. (How) Can I do that? I know using SomeClass.metaClass I can get a reference to an existing method and define new (or overriding) method, but I can't seem to be able to do that for existing Java methods. ...

Grails withCriteria exception when using One-to-many relationship

I have 2 domains : class JobProcess { static constraints = { scriptUser(blank:false) scriptType() scriptName() scriptPath() scriptArgs(size:0..1000,nullable:true) scriptDateCreated(nullable:true) scriptDateStarted(nullable:true) scriptDateFinished(nullable:true) script...

Sorting XML in Groovy

I have looked at the documentation on sorting XML with Groovy def records = new XmlParser().parseText(XmlExamples.CAR_RECORDS) assert ['Royale', 'P50', 'HSV Maloo'] == records.car.sort{ it.'@year'.toInteger() }.'@name' but what I am trying to do is sort the XML and then return the xml string sorted. I know I can completely rebuild the...

Opening a local file in Groovy

I want to use a File object to read a local file in the same directory as a groovlet. However, using a relative path to the file (either "example.txt" or "./example.txt") doesn't do the trick. If I give it an absolute path (e.g., "/example.txt"), then it works. Is there any way to get the working directory or context path of the groovle...

Which cross platform scripting language should we adopt for a group of DBAs?

Hi there, I wanted to get the community's feedback on a language choice our team is looking to make in the near future. We are a software developer, and I work in a team of Oracle and SQL Server DBAs supporting a cross platform Java application which runs on Oracle Application Server. We have SQL Server and Oracle code bases, and supp...

Unable to submit form programmatically using HtmlUnit

Hi, I'm using HtmlUnit in a Groovy script to get a csv file from the www.goodreads.com site. This script used to work until recently, where some strange SSL error appeared. Here is the used Groovy code WebClient client = new WebClient(com.gargoylesoftware.htmlunit.BrowserVersion.INTERNET_EXPLORER_6); client.setJavaScriptEnabled...

Generics with Grails

What I am trying to do is define a list which asks for a specific type (List<Integer>). During the initialization of the class I put in a list of String I expect it to throw some runtime casting error. But it doesn't - it runs fine. This is probably grails 101 stuff im sure but could someone explain why this works and also how I would ...

How to add a header to a Groovy SwingBuilder table?

How do I add a header to the table defined below? import groovy.swing.SwingBuilder data = [[first:'qwer', last:'asdf'], [first:'zxcv', last:'tyui'], [first:'ghjk', last:'bnm']] swing = new SwingBuilder() frame = swing.frame(title:'table test'){ table { tableModel( list : data ) { propertyColumn(...

Groovy / Java method for converting nested List String representation back to List

I need to convert a String representation of a nested List back to a nested List (of Strings) in Groovy / Java, e.g. String myString = "[[one, two], [three, four]]" List myList = isThereAnyMethodForThis(myString) I know that there's the Groovy .split method for splitting Strings by comma for example and that I could use regular expres...

How to replace existing Swing UI module with Griffon based one in a legacy Java application?

The application that I would like to revamp is pretty well organized. UI is separated into a module. UI controllers implement the interface PropertyChangeListener. When other modules want to have something happened in the UI they just fire PropertyChangeEvents on UI controllers not being aware what is behind them. Current implementations...

How do I update fields of documents in mongo db using the java driver?

References: http://www.mongodb.org/display/DOCS/Java+Tutorial Still pretty new to mongo db but I'm trying to update part of an existing document inside a collection... unfortunately, the link above doesn't have an update example. Essentially, i just want to be able to: Add new fields to a document Update existing fields of a docu...

Why does an RPC call fail in a C programm called from Groovy on Linux?

We have a program, written in C, that uses RPC to communicate with another program (also written in C) on the same Linux server (in some production setups, the second C program would on another machine, therefore RPC instead of IPC). When called from other C programs, CRON or the command line, it works as expected and has been doing so ...

Groovy methodMissing

Hi I have a closure within an object Foo and inside the closure i define a method called 'myStaticMethod' that I want to resolve once the closure is called outside the object Foo. I also happen to have 'on purpose' a static method within my object Foo with the same name. When I call the closure i set the 'resolve strategy' to DELEGATE...

How do I limit the number of results when using the Java driver for mongo db?

http://api.mongodb.org/java/2.1/com/mongodb/DBCollection.html#find(com.mongodb.DBObject,com.mongodb.DBObject,int,int) Using this with Grails and the mongo db plugin. Here's the code I'm using... not sure why but the cursor is returning the entire set of data. In this case, I'm just trying to return the first 20 matches (with is_proces...