I have a list (table) of airport locations, but missing the timezone information (as used in Java, eg. ‘America/Los_Angeles’ which is the timezone Id in java.util.Timezone). We could use the geonames dump to retrieve the timezone from the cityname, but the cityname for some airports might not be unique or distinct, so I rather use the geographical location which I have for each airport and use a webservice to get the timzone for a specific location. We can use the geonames webservice (commercial usage allowed, but you should give credit) or the Google Timezone API (which is experimental and restricted to 2500 calls a day) .
We use Groovy to retrieve this information, using the browser you get this JSON reply for :
We put this into a Groovy Script to read the timeZoneId:
import static groovyx.net.http.ContentType.*
def timezone = new RESTClient('https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&sensor=false')
def resp = timezone.get( contentType : JSON)
println resp.data.timeZoneName + " - " + resp.data.timeZoneId
We need the HTTP Builder library.
Please note the httpbuilder library has some dependencise ! Put all into your .groovy/lib folder.
Pacific Standard Time - America/Los_Angeles
Now we can iterate through our locations and complete the data.
Alternative with geonames:
import static groovyx.net.http.ContentType.*
def timezone2 = new RESTClient('http://api.geonames.org/timezoneJSON?lat=47.01&lng=10.2&username=xxxxx')
def resp2 = timezone2.get( contentType : JSON)
println resp2.data.countryName + " - " + resp2.data.timezoneId
SECURITY WARNING: Please take note of the warning at the end of the tutorial !
UPDATE 2011-07-08: A good article on the security concern I recommend http://www.jroller.com/melix/entry/customizing_groovy_compilation_process
We use the Groovy Script Engine to run small Groovy scripts to prepare incoming interface messages for further processing. Here I share with you how to embed the engine into a ZK page. Very basic, though it shows you the concept and it is wasy to expand to your needs.
ZK Groovy Console
A little sunday afternoon project, mixing Java and Groovy into a Swing application that reads your favorite code snippets from snipplr.com. The website has an XML-RPC based API, so a good exercise with this rather old API technology. I am storing both sourcecode and jar file on bitBucket (which is now under Atlassian). Learning the Mercurial way.
Download the tool from: http://bitbucket.org/javadude/snipplrscout/downloads
More information before we start with the implementation:
- Display all wikipages as nodes
- Show direction (links are uni-directional)
- Highlight direct connected wikipages
- Display content (in separate browser window)
The XML for prefuse graphs look like this sample (our groovy script needs to produce this):
<?xml version="1.0" encoding="UTF-8"?><graphml xmlns="http://graphml.graphdrawing.org/xmlns">
<key id="wname" for="node" attr.name="wname" attr.type="string"/>
<edge source="1" target="3"/>
<edge source="1" target="4"/>
<edge source="1" target="5"/>
<edge source="1" target="6"/>
<edge source="1" target="7"/>
<edge source="1" target="13"/>
<edge source="3" target="4"/>
The prefuse xml file contains the metadata for the nodes, all nodes and all edges linking the nodes.
Using the backup function of Trac we need to process input like this sample:
INSERT INTO "wiki" VALUES('wikiPage1',2,1246948793,'user','220.127.116.11',' * MySQL on Server xyz * Evaluate Firebird and Oracle. (schema and timestamp issue)','',0);
The SQL file contains the complete wiki content. Following the sample we need to filter with
- type: INSERT INTO ‘wiki’ (filter out all others)
- page title: ‘wikiPage1‘
- version: ‘2‘ (search for the highest version)
- wiki user: ‘user‘ (filter out all ‘trac’ entries)
- content: ‘* MySQL on Server xyz * Evaluate Firebird and Oracle. (schema and timestamp issue)‘
We are using Trac as Wiki and after a couple of months using it as main know-how repository, we tend to loose the overview of the myriad of pages and how they are linked to each other. A graph representing the relation between the pages would be very useful.
I could not find any plugin or tool, so it would be a good exercise to create a tool that convert a trac wiki into a graph.
- Use Java or Groovy. I choose Groovy because less boilerplate for standard tasks, such as creating xml, reading text files, etc.
- XML-RPC to access the wiki directly. I tried to create a mockup in Java, but failed due to the cryptic error messages and hard to debug.
- Trac backup to retrieve wiki data: You can create a backup in form of an INSERT sql file containing the complete structure of the wiki (inclusive of non-user content and all revisions of the wiki. I choose this as a starting point until I get the XML-RPC problem solved (maybe in Groovy).
- Visualization in JGraph, InfoVis, Prefuse or other toolkits. I decide for Prefuse because it is feature complete, powerful and I created simple applications previously.
- A simple Groovy script that works in 2 stages, a) reading and processing the sql backup file and b) creating a xml file that my prefuse viewer can display.
- Create a standalone SwingXBuilder application
- Create a Netbeans Plugin
Over the Christmas break I decided to spend some time on in-deep groovy’ing some stuff. Time to start another blog on nothing but Groovy and Grails topics and all the snippets and tutorials I am collecting.
If you keen on Groovy, tune-in here: groovy.bighugesystems.com
(running on an own server, in order to make use of some cool worpress plugins which are not available on worpress.com