Description:

Groovy and Grails give you the power of the Java platform together with the flexibility and dynamism of a scripting language. Pick one of the many example projects in this book: at first you'll scratch your head and ask, "where's all the code?" Then you'll smile as you realize that Groovy allows you to write code the way you always thought you should. You will never look at Java the same way again. "Groovy Recipes" is targeted at the busy Java professional who needs quick solutions to everyday problems. Each recipe shows a concise code example right away. If you need more information, each recipe is explained in plain English. Nearly every aspect of the development process can be sped up using Groovy. Groovy makes mundane file management tasks like copying and renaming files trivial. Reading and writing XML has never been easier with XmlParsers and XmlBuilders. JDBC gets a fresh makeover. Breathe new life into Arrays, Maps, and Lists with a number of convenience methods. Even Ant gets turbo-charged. You can mix Groovy right into your build.xml, or replace it completely with code from an AntBuilder. As an added bonus, this book also covers Grails. You'll be amazed at how quickly you can have a first-class web application up and running from ground zero. Grails includes everything you need in a single zip file, a web server (Jetty), a database (HSQLDB), Spring, Hibernate, Sitemesh, even Ant. If you're looking for Ajax support, Grails ships with leading libraries like Prototype, script.aculo.us, Yahoo UI, and Dojo. We cover everything from getting a basic application up and running to advanced features such as deploying to other webservers and databases, adding a Captcha, integrating with legacy EJB applications, and even adding a Google Map.

Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., and an adjunct faculty at the University of Houston. He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly invited speaker at several international conferences. He's (co)author of multiple books, including the 2007 Jolt Productivity award winning book Practices of an Agile Developer.

Preface

Introduction

Groovy, the Way Java Should Be

Stripping Away the Verbosity

Groovy: The Blue Pill or the Red Pill?

Road Map

Acknowledgments

Getting Started

Installing Groovy

Running a Groovy Script (groovy)

Compiling Groovy (groovyc)

Running the Groovy Shell (groovysh)

Running the Groovy Console (groovyConsole)

Running Groovy on a Web Server (Groovlets)

Groovy + Eclipse

Groovy + IntelliJ IDEA

Groovy + TextMate

Groovy + [Insert Your IDE or Text Editor Here]

New to Groovy

Automatic Imports

Optional Semicolons

Optional Parentheses

Optional Return Statements

Optional Datatype Declaration (Duck Typing)

Optional Exception Handling

Operator Overloading

Safe Dereferencing (?)

Autoboxing

Groovy Truth

Embedded Quotes

Heredocs (Triple Quotes)

GStrings

List Shortcuts

Map Shortcuts

Ranges

Closures and Blocks

Java and Groovy Integration

GroovyBeans (aka POGOs)

Autogenerated Getters and Setters

getProperty and SetProperty

Making Attributes Read-Only

Constructor Shortcut Syntax

Optional Parameters/Default Values

Private Methods

Calling Groovy from Java

Calling Java from Groovy

Interfaces in Groovy and Java

The Groovy Joint Compiler

Compiling Your Project with Ant

Compiling Your Project with Maven

Groovy from the Command Line

Running Uncompiled Groovy Scripts

Shebanging Groovy

Accepting Command-Line Arguments

Running a Shell Command

Using Shell Wildcards in Groovy Scripts

Running Multiple Shell Commands at Once

Waiting for a Shell Command to Finish Before Continuing

Getting System Properties

Getting Environment Variables

Evaluating a String

Calling Another Groovy Script

Groovy on the Fly (groovy -e)

Including JARs at the Command Line

File Tricks

Listing All Files in a Directory

Reading the Contents of a File

Writing Text to a File

Copying Files

Using AntBuilder to Copy a File

Using AntBuilder to Copy a Directory

Moving/Renaming Files

Deleting Files

Creating a ZIP File/Tarball

Unzipping/Untarring Files

Parsing XML

The "I'm in a Hurry" Guide to Parsing XML

Understanding the Difference Between XmlParser and XmlSlurper

Parsing XML Documents

Dealing with XML Attributes

Getting the Body of an XML Element

Dealing with Mixed-Case Element Names

Dealing with Hyphenated Element Names

Navigating Deeply Nested XML

Parsing an XML Document with Namespaces

Populating a GroovyBean from XML

Writing XML

The "I'm in a Hurry" Guide to Creating an XML Document

Creating Mixed-Case Element Names

Creating Hyphenated Element Names

Creating Namespaced XML Using MarkupBuilder

Understanding the Difference Between MarkupBuilder and StreamingMarkupBuilder

Creating Parts of the XML Document Separately

Creating Namespaced XML Using StreamingMarkupBuilder

Printing Out the XML Declaration

Printing Out Processing Instructions

Printing Arbitrary Strings (Comments, CDATA)

Writing StreamingMarkupBuilder Output to a File

StreamingMarkupBuilder at a Glance

Creating HTML on the Fly

Converting CSV to XML

Converting JDBC ResultSets to XML

Web Services

Finding Your Local IP Address and Name

Finding a Remote IP Address and Domain Name

Making an HTTP GET Request

Working with Query Strings

Making an HTTP POST Request

Making an HTTP PUT Request

Making an HTTP DELETE Request

Making a RESTful Request

Making a CSV Request

Making a SOAP Request

Making an XML-RPC Request

Parsing Yahoo Search Results as XML

Parsing an Atom Feed

Parsing an RSS Feed

Metaprogramming

Discovering the Class

Discovering the Fields of a Class

Checking for the Existence of a Field

Discovering the Methods of a Class

Checking for the Existence of a Method

Creating a Field Pointer

Creating a Method Pointer

Calling Methods That Don't Exist (invokeMethod)

Creating an Expando

Adding Methods to a Class Dynamically (Categories)

Adding Methods to a Class Dynamically (ExpandoMetaClass)

Working with Grails

Installing Grails

Creating Your First Grails App

Understanding Grails Environments

Running Grails on a Different Port

Generating a WAR

Changing Databases

Changing the Home Page

Understanding Controllers and Views

Dynamic Scaffolding

Validating Your Data

Managing Table Relationships

Mapping Classes to Legacy Databases

Grails and Web Services

Returning XML

Returning JSON

Returning an Excel Spreadsheet

Setting Up an Atom Feed

Setting Up an RSS Feed for Podcasts

Installing Plug-Ins

Index

Free shipping

A minimum purchase of $35 is required. Shipping is provided via FedEx SmartPost® and FedEx Express Saver®. Average delivery time is 1 – 5 business days, but is not guaranteed in that timeframe. Also allow 1 - 2 days for processing. Free shipping is eligible only in the continental United States and excludes Hawaii, Alaska and Puerto Rico. FedEx service marks used by permission."Marketplace" orders are not eligible for free or discounted shipping.

Our guarantee

If an item you ordered from TextbookRush does not meet your expectations due to an error on our part, simply fill out a return request and then return it by mail within 30 days of ordering it for a full refund of item cost.