groovy

How to insert/move/delete nodes in xml with Groovy?

for example, I have the following xml document: def CAR_RECORDS = ''' <records> <car name='HSV Maloo' make='Holden' year='2006'/> <car name='P50' make='Peel' year='1962'/> <car name='Royale' make='Bugatti' year='1931'/> </records> ''' and I want to move the car "Royale" up to first one, and insert a new ca...

groovy inside ant: how to access refids from grooy that are defined by ant tags

I'm using a groovy code snippet in an ant build file. Inside the groovy code I'm trying to reference a fileset that has been defined outside of the groovy part, like this: <target name="listSourceFiles" > <fileset id="myfileset" dir="${my.dir}"> <patternset refid="mypatterns"/> </fileset> <groovy> def ant = ...

How do I print a groovy Node with namespace preserved?

When I use this code to output some XML I parsed (and modified) with XmlParser XmlParser parser = new XmlParser() def root = parser.parseText(feedUrl.toURL().text) def writer = new StringWriter() new XmlNodePrinter(new PrintWriter(writer)).print(root) println writer.toString() the namespace declarations on the roo...

How to read an Open Office spreadsheet?

How can I read an Open Office 3.0 spreadsheet (.ods) from Groovy? I'd like to select specific columns from a named worksheet. Ideally, it would be useful to add a 'where' clause, or other criteria clause. ...

Best way to pretty print XML response in grails.

given this in a grails action: def xml = { rss(version: '2.0') { ... } } render(contentType: 'application/rss+xml', xml) i see this: <rss><channel><title></title><description></description><link></link><item></item></channel></rss> is there an easy way to pretty print the xml? something built into the render method,...

Best IDE for Grails/Groovy?

I am starting a project with Grails since I already use Eclipse, it was my first choice. But I don´t think its good enough, had some problems and the plugging is poor in functionalities. Anyone uses/tested others IDEs(NetBeans, InteliJ(not free)...)? Which one is the best? thanks. ...

Groovlet in Grails apps

How do I drop a Groovlet into a Grails app? Say, for example, in web-app/groovlet.groovy import java.util.Date if (session == null) { session = request.getSession(true); } if (session.counter == null) { session.counter = 1 } println """ <html> <head> <title>Groovy Servlet</title> </head> <body> Hello, ${requ...

How to parse, persist and retrieve a string with tags separated by spaces?

My database consists of 3 tables (one for storing all items, one for the tags, and one for the relation between the two): Table: Post Columns: PostID, Name, Desc Table: Tag Columns: TagID, Name Table: PostTag Columns: PostID, TagID What is the best way to save a space separated string (e.g. "smart funny wonderful") into the 3 databas...

Best free resources to learn Groovy/Grails

What are the best free resources that I can give someone to learn Groovy/Grails? Blogs, tutorials, sample code, sample apps, or presentations would all be helpful. ...

How can I determine if a URL redirects?

If I have a URL (eg. http://www.foo.com/alink.pl?page=2), I want to determine if I am being redirected to another link. I'd also like to know the final URL (eg. http://www.foo.com/other_link.pl). Finally, I want to be able to do this in Perl and Groovy. ...

How do I auto load a database jar in Groovy without using the -cp switch?

I want to simplify my execution of a Groovy script that makes calls to an Oracle database. How do I add the ojdbc jar to the default classpath so that I can run groovy RunScript.groovy instead of groovy -cp ojdbc5.jar RunScript.groovy ...

Hibernate Criteria Question

I'm working on a Grails project using Hibernate (GORM). I have the following Domain Models ClientContact{ static hasMany = [owners: Person] static belongsTo = [Person] } Person{ static hasMany = [clientContacts:ClientContact] } When I try to retrieve all the ClientContacts with a specific owner (Person), I'm running into...

Python vs Groovy vs Ruby? (based on criteria listed in question)

Considering the criteria listed below, which of Python, Groovy or Ruby would you use? Criteria (Importance out of 10, 10 being most important) Richness of API/libraries available (eg. maths, plotting, networking) (9) Ability to embed in desktop (java/c++) applications (8) Ease of deployment (8) Ability to interface with DLLs/Shared Lib...

How to display image in grails GSP?

I'm still learning Grails and seem to have hit a stumbling block. Here are the 2 domain classes: class Photo { byte[] file static belongsTo = Profile } class Profile { String fullName Set photos static hasMany = [photos:Photo] } The relevant controller snippet: class PhotoController { ..... def vie...

How can I join lines in a CSV file when one of the fields has a newline?

If I have a comma separated file like the following: foo,bar,n ,a,bc,d one,two,three ,a,bc,d And I want to join the \n, to produce this: foo,bar,n,a,bc,d one,two,three,a,bc,d What is the regex trick? I thought that an if (/\n,/) would catch this. Also, will I need to do anything special for a UTF-8 encoded file? Finally, a sol...

How to access java-classes in the default-package?

I'm working now together with others in a grails project. I have to write some Java-classes. But I need access to an searchable object created with groovy. It seems, that this object has to be placed in the default-package. My question is: Exists a way to access this object in the default-package from a Java-class in a named package? ...

What is Groovy?

I have heard some things about Groovy from several different sources. One said Groovy is a great test harness for Java. Another said Groovy is Java's answer to Ruby. I am not sure what I've heard that is correct. What is Groovy and why should I learn more about it? Obviously I have a vague idea about groovy, but the emphasis is on the w...

Groovy advantages over Jython or Jruby?

Why would I choose to use Groovy when I could use Jython or Jruby? Does the language provide any inherent advantages to make up for the fact that Jython and Jruby skills are applicable to their parent languages outside of the JVM? Keep in mind that I purposely keeping this question generic, but if there are any advantages that exist in...

How to work around a potential performance issue when using a Grails hasMany relation?

Given the following domain classes: class Post { SortedSet tags static hasMany = [tags:Tag] } class Tag { static belongsTo = Post static hasMany = [posts:Post] } From my understanding so far, using a hasMany will result in hibernate SET mapping. However, in order to maintain uniqueness/order, Hibernate needs to load t...

Examples for creating stub data structures with dynamic JVM Languages ?

Over the years, I think I have seen and tried every conceivable way of generating stub data structures (fake data) for complex object graphs. It always gets hairy in java. * * * * A---B----C----D----E (Pardon cheap UML) The key issue is that there are certain relationships between the values, so a certain instance of C m...