groovy

Documenting taglibs (or closures in general) in Groovy/Grails

I am writing my first taglib as part of a plugin and I would like to document it. Adding javadoc (is there any place that documents groovydoc or is it really the same thing?) doesn't seem to work for non-methods. Specifically, is it possible to document the def mytag in: /** * This doc shows up */ class MyTagLib { static namespace ...

How to count in Grails/Hibernate: Message.countBy

How do I count the number of messages where my body length is between 0 and 25 characters long? Message.countBy('from Message m where m.body.length <= 25') Unfortunately for me, countBy does not take a string parameter. ...

Groovy+ XML: handle Attributes with Namespace-Prefix

Hi, I'm working on a XML-document with Groovy and test a node for a certain attribute, which has a namespace prefix. How could it work: in groovy-script: ... Element.Subelement.each { if (it.'@type'=='ns2:xyType') ...do what ever... } in XML document: <Element> <Subelement xsi:type="ns2:xyType"> <!-- or another type...

Kill a process started with Groovy execute()

I'm able to run Groovy scripts from Groovy using proc = "cmd /c groovy BillingServer.groovy".execute(null, new File("C:\")) However, I can't find a way to then terminate/kill the process. waitForOrKill(1) and destroy() "act" like they've worked, but the external process continues to run. Calling exitValue() fails with java.lang.Ill...

Adding scripting security to an application

Let's say I have an existing application written in Java which I wish to add scripting support to. This is fairly trivial with Groovy (and just as trivial in .Net with any of the Iron range of dynamic languages). As trivial as adding the support is, it raises a whole host of questions about script execution and security - and how to imp...

Grails Error for using e-mail service

This is the controller class JavaMailerController { JavaMailerService javamailerservice def x = {javamailerservice.serviceMethod()} } This is the Service import javax.mail.; import javax.mail.internet.; import java.util.*; class JavaMailerService { boolean transactional = false def serviceMethod() { String d_ema...

How can I check for the existence of an element with Groovy's XmlSlurper?

I'm trying to determine whether an XML element exists with Groovy's XmlSlurper. Is there a way to do this? For example: <foo> <bar/> </foo> How do I check whether the bar element exists? ...

Media analysis java library

Hi, As a "learn Groovy" project, I'm developing a site to manage my media collection (MP3, MP4, AVI, OGG) and I wasn't able to find any open source library to retrieve meta data from this files. I was thinking of something like Linux's file command. I've found few libraries on Java that do one or the other (like mp3info), but not a tota...

Spreadsheet Parser in Java/Groovy

Hi I'm looking to parse spreadsheets (xls/ods) in Groovy. I have been using the Roo library for Ruby and was looking to try the same tasks in Groovy, as Java is already installed on a development server I use, and I would like to keep the number of technologies on the server to a simple core few. I am aware that the ods format is zipped...

Is it possible to work with GSP (groovy server pages) without the whole grails stuff?

I'd just like to play a little bit with groovy I was thinking about developing my own-tiny web framework, something very simple and manageable... So i'd like tou use GSP pages whtout having to install the whole grails stuff, with all its dependencies and behind-the-scenes frameworks... can anyone provide me detailed instructions on wh...

Specify order of fields in DDL generated from GORM classes?

I use GORM to generate my database's DDL from groovy classes. Which is great. However, the order of fields in the generated SQL is not the same as the order of fields in the class. For example, if I create the class class Person { String firstName String lastName String address String email } the following SQL is generated ...

How to render 'how long ago something happened' using Groovy or Grails?

I would like a method/closure which works like this println TimeDifference.format( System.currentMilliSeconds()-1000*60*60*24*7*6 ) and prints 1 month, 3 weeks, 2 days, 45 hours and 3 minutes ago. Is there an off the shelf solution for this? ...

Question about "&" in Groovy

like this: Groovy: map = ['a':1,'b':2] doubler = this.&doubleMethod map.each(doubler) println map What's the "&" semanteme used here? ...

Limiting no of outputs in Hibernate query

I have a hibernate query in grails Book.findAllByRating(4) In the above query i want only 5 number of outputs.How do I limit the output to 5? ...

Is there a Python equivalent of Groovy/Grails for Java

I'm thinking of something like Jython/Jango? Does this exist? Or does Jython allow you to do everything-Python in Java including Django (I'm not sure how Jython differs from Python)? ...

How popular is Groovy/Grails in the corporate world?

Are there any figures for its adoption in corporate environments? Does anyone know of large corporations that have adopted it for projects? ...

Why some method in Java modify the original value and some do not?

The method Concat() does not modify the original value. It returns a new value. like this: String str = "good"; str.concat("ness"); System.out.println(str); //"good" But some method modify the original value. Why? In Groovy: def languages = ["Java", "Groovy", "JRuby"] languages.reverse() ===> [JRuby, Groovy, Java] println language...

Security with Java Scripting (JRuby, Jython, Groovy, BeanShell, etc)

I'm looking to run some un-verified scripts (written in a yet-to-be-determined language, but needs to be Java-based, so JRuby, Groovy, Jython, BeanShell, etc are all candidates). I want these scripts to be able to do some things and restricted from doing other things. Normally, I'd just go use Java's SecurityManager and be done with it....

Default Value for Closure Parameters in Groovy

Is there some way to use default parameters values with closures in Groovy? This is what I tried so far: class Persona { String name Persona( String name ) { this.name = name } String salute( String salute = "Hola" ) { salute + ' ' + this.name } } Persona.metaClass.salute2 = { String salute ...

Groovy: Delegating metaclass for an Interface?

Using Groovy's package name convention, I can intercept Groovy method calls to a Java method like so: package groovy.runtime.metaclass.org.myGang.myPackage class FooMetaClass extends groovy.lang.DelegatingMetaClass { StringMetaClass(MetaClass delegate) { super(delegate); } public Object getProperty(Object a, St...