Grails

GDSL Awesomeness – Contributing to classes which match a path/name pattern

hi,   If we want to contribute to classes which matches a particular path/name pattern, then we can use PSI Class patterns to do it.   the code is as follows: [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns //get the context of all files, and enable path matching. Note: Don’t change anything in context here. def ctx […]

Kushal Likhi
Kushal Likhi
Read

Grails

GDSL Awesomeness – contributing methods with current class return types or parameters

Hi,   Sometimes we need to contribute dynamically using current target class type.   Lets take the example of .get() and .list() methods of Grails domain class. The signature of each method is as follows: public <DomainClassType> get(Long id) , Example: DemoClass.get(1) will return an object of “DemoClass” public List<DomainClassType> list()   The GDSL Script […]

Kushal Likhi
Kushal Likhi
Read

Grails

GDSL Awesomeness – AutoComplete Script for grails-Mail-Plugin “sendMail” closure

Hi,   I have been using the Grails mail plugin for a while now, this plugin injects a method named “sendMail” to all controllers and services.   Our aim will be to provide auto-completes for this method and the closure inside.   The GDSL Script is as follows: [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns //Let Us […]

Kushal Likhi
Kushal Likhi
Read

Grails

GDSL Awesomeness – Getting Code of a method or Field in GDSL Script

Hi,   Here i will illustrate how you can get the code of a method within GDSL Script:   The script is as follows: [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns def mongoContext = context( ctype: PsiJavaPatterns.psiClass().withName(PlatformPatterns.string().matches(/.*/)) ) contributor(mongoContext) { def path = "" try { path = psiClass.containingFile.originalFile.virtualFile.path } catch (Exception e) { } if (path […]

Kushal Likhi
Kushal Likhi
Read

Grails

GDSL Awesomeness – Advanced Example showing domain properties implementation

Hi,   Here is an example which uses a lot of gdsl concepts. This example tries to simulate injecting properties to Domains.   The Example is as follows: (The code is self explanatory and can be used as a reference) [java] import com.intellij.patterns.PsiJavaPatterns import com.intellij.patterns.PlatformPatterns def mongoContext = context( ctype: PsiJavaPatterns.psiClass().withName(PlatformPatterns.string().matches(/.*/)) ) contributor(mongoContext) { def […]

Kushal Likhi
Kushal Likhi
Read

Grails

Posting status update on twitter using Twitter4j

Hi, In the previous post, we saw how to Retweet any user’s tweet from our application. In the same project, i needed to post a new tweet on behalf of the authenticating user from the application using Twitter API. Posting a new status update is quite easy using Twitter4j library. For making any twitter API […]

Vishal Sahu
Vishal Sahu
Read

Grails

MetaProgramming with MetaClass

As we all know that groovy is a dynamic programming language, so we can add any method to any class at runtime. First, let’s see a small and simple example of metaProgamming given below, in which we are adding a method (isEvent) into an Integer class. [groovy] Integer.metaClass.isEven = { -> // only (->) sign […]

Amit Kumar
Amit Kumar
Read

Grails

Parsing tweet for Hashtags, Usernames and URLs in Java

Hi, As i am working on Twitter integration in my current project, i needed to display the searched tweets from twitter API, on my view layer. When we query the Twitter API, it returns tweets text in the form of simple string which contains HashTags, Twitter usernames and links to external resources. While displaying them […]

Vishal Sahu
Vishal Sahu
Read

Grails

Grails pageProperty tag

In my current project, I tried to call a javascript function on onload event of body tag of gsp page: [html] … [/html] But this onload event was not fired, because Grails picks the body tag from layout and not from the view. So I added the following line in body tag of my layout […]

Amit Kumar
Amit Kumar
Read
Services