Vector Graphics Processing in Java

Most common computer images are stored as arrays of pixel data or raster graphics. Formats such as PNG, and JPEG are classic examples of this. Vector Graphics are stored as operations that are instead “code” for drawing the image on the fly.

In this article we will [...]

Lucene Query Syntax for SQL

Lucene provides a rich query syntax allowing users to easily create simple queries and scale up to complex ones. A number of search back-ends are built on top of Lucene nowadays such as ElasticSearch and Solr. In this article we will explore using Lucene’s query syntax against relational databases.

We used Groovy here, but it [...]

Handling Date Parameters in Grails

To configure Grails to handle a variety of date parameter formats, use a property editor similar to the following sample:

CustomPropertyEditorRegistrar.groovy [Download #80, 1.12units_k]

package util

import java.beans.PropertyEditorSupport
import java.text.ParseException
import org.apache.commons.lang.time.DateUtils
import org.springframework.beans.PropertyEditorRegistrar
import org.springframework.beans.PropertyEditorRegistry

class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
    def dateEditor

    void registerCustomEditors(PropertyEditorRegistry registry) {
        registry.registerCustomEditor(Date.class, dateEditor)
    }
}

class CustomDateEditor extends PropertyEditorSupport {
    boolean allowEmpty
    String[] formats

    /**
     * Parse the Date from the given text
     */

    void setAsText(String text) throws IllegalArgumentException {
        if (this.allowEmpty && !text) {
            // Treat empty String as null value.
            setValue(null)
        }
        else {
            try {
                setValue(DateUtils.parseDate(text, formats))
            }
            catch (ParseException ex) {
                throw new IllegalArgumentException("Could not parse date: " + ex.getMessage(), ex)
            }
        }
    }

    /**
     * Format the Date as String, using the first specified format
     */

    String getAsText() {
        def val = getValue()
        val?.respondsTo('format') ? val.format(formats[0]) : ''
    }
}