Grails Goodness: Add Extra Valid Domains and Authorities for URL Validation

Grails has a built-in URL constraint to check if a String value is a valid URL. We can use the constraint in our code to check for example that the user input is valid and http://www.invalid.url is not. The basic URL validation checks the value according to standards RFC1034 and RFC1123. If want to allow other domain names, for example server names found in our internal network, we can add an extra parameter to the URL constraint. We can pass a regular expressions or a list of regular expressions for patterns that we want to allow to pass the validation. This way we can add IP addresses, domain names and even port values that are all considered valid. The regular expression is matched against the so called authority part of the URL. The authority part is a hostname, colon (:) and port number.

Continue reading

Grails Goodness: Setting Property Values through Configuration

In Grails we can define properties for services, controller, taglibs, Spring components and other components in the Spring application context through configuration. This is called property overriding in Spring terminology. This feature is very useful to define or override property values on components in the application context. We can define the property values in a beans{} block in Config.groovy. We can also load external configuration files, like property files and define property values in those.

With property overriding we don’t have to look for property values via an injected GrailsApplication object and the config property of GrailsApplication. The code using the property value is now much cleaner and easier to test.

Continue reading

Creating a superelipse with canvas

Today a colleague asked a group of front-end developers how he would create a superelipse.

A superelipse

His current solution was to use a svg mask to remove all non essential visual information. This solution however had a setback, because we used a mask to shield the edges we had no real transparency. Thus we were unable to effectively use it on more graphic backgrounds.

I however thought it should be able to use canvas to provide the solution. The code below is my solution.  Continue reading

Detect Maven Dependency Mediation

As of Maven 2.0.9 a new feature was added to Maven called dependency mediation.
Dependency mediation is the technique used by Maven to resolve your project dependencies in the specific case when a dependency occurs multiple times in your dependency tree.
Usually this occurs on transitive dependencies linked through the dependencies of your project.
In these cases mediation will be performed using the nearest win-strategy.
In short this strategy means that Maven will use the version declared in the pom.xml that is closest to your project pom.xml.
Hence, no in-depth intelligence is used to resolve the dependency conflict.
Actually, I can’t really think of a conflict resolve strategy that would really solve this problem.

Any strategy I can think of has the hazard of linking incompatible dependencies in to your project.
Using Maven version ranges can ofcourse resolve compatibility between artifacts, but this also requires you to establish a compatibility matrix of your dependencies. A pretty tedious task if you ask me.

Now this whole mediation feature might sound like a very undesirable feature, but it’s not!
With this feature you can now at least be made aware of any dependency conflicts in your project dependencies.
When you build your project using the -X switch, Maven will output all mediations (and a lot more) that have been performed.

Now, wouldn’t it be cool if there was a maven-plugin to detect mediation?
JDriven took the liberty of extending Apache’s dependency plugin with such a feature and share it with you.
Continue reading