-
Pages
-
Categories
-
Archives
Odd one out
While chatting with his brother and Dad about who was wearing what my six year old said
I’m the only one who isn’t an odd one out
Marvellous
Using GeoRss
I started using Marc’s GeoRss module as part of a webapp that needed to send geometries to an OpenLayers (JavaScript) client. Here are the steps I took to get GeoRss working.
* Read the documentation at http://georss.geonames.org/
* Used the following maven command to setup a basic project.
#!/bin/bash PROJECT=twotrack mvn archetype:generate \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-profiles \ -Dversion=1.0.0-SNAPSHOT \ -DartifactId=$PROJECT-georss \ -DgroupId=net.fnarg.$PROJECT
* Added GeoRss dependencies to the maven generated pom.xml
<dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.geonames</groupId>
<artifactId>georss-rome</artifactId>
<version>0.9.8</version>
</dependency>
* Grabbed the jars for Eclipse
mvn eclipse:eclipse
* Extended Marc’s examples by wrapping some setters and getters for Spring
package net.fnarg.twotrack;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import com.sun.syndication.io.XmlReader;
import com.sun.syndication.io.SyndFeedInput;
import com.sun.syndication.io.SyndFeedOutput;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndEntryImpl;
import com.sun.syndication.feed.synd.SyndFeed;
import com.sun.syndication.feed.synd.SyndFeedImpl;
import com.sun.syndication.feed.module.georss.GeoRSSUtils;
import com.sun.syndication.feed.module.georss.GeoRSSModule;
import com.sun.syndication.feed.module.georss.W3CGeoModuleImpl;
import com.sun.syndication.feed.module.georss.geometries.Position;
public class GeoRssFeed {
private SyndFeed feed;
public GeoRssFeed() {
feed = new SyndFeedImpl();
}
public GeoRssFeed(String url) throws Exception {
feed = new SyndFeedImpl();
this.setEntries(url);
}
public String getFeed() throws Exception {
return new SyndFeedOutput().outputString(feed);
}
public void setFeed() throws Exception {
feed.setFeedType("rss_2.0");
feed.setTitle("Two Track");
feed.setDescription("A tool for modelling toy train tracks");
feed.setLink("http://www.fnarg.net/twotrack/");
}
public void setEntries(String url) throws Exception {
SyndFeedInput input = new SyndFeedInput();
feed = input.build(new XmlReader(new URL(url)));
}
public List<SyndEntry> getEntries() {
return feed.getEntries();
}
public void setEntries(List<Position> positions) {
List<SyndEntry> entries = new ArrayList<SyndEntry>();
for (Position p : positions) {
SyndEntry entry = new SyndEntryImpl();
GeoRSSModule geoRSSModule = new W3CGeoModuleImpl();
geoRSSModule.setPosition(p);
entry.getModules().add(geoRSSModule);
entries.add(entry);
}
feed.setEntries(entries);
}
}
* Wrote a test class to verify inputs/outputs
package net.fnarg.twotrack;
import java.util.ArrayList;
import java.util.List;
import com.sun.syndication.feed.module.georss.GeoRSSModule;
import com.sun.syndication.feed.module.georss.GeoRSSUtils;
import com.sun.syndication.feed.module.georss.geometries.Position;
import com.sun.syndication.feed.synd.SyndEntry;
public class TestGeoRssReadWriter {
private static GeoRssFeed geoRssFeed;
/**
* Tester for the GeoRssFeed class
* @author gavin
*/
public static void main(String[] args) throws Exception {
// load XML file into memory
geoRssFeed = new GeoRssFeed("http://www.openlayers.org/dev/examples/xml/track1.xml");
// get and display the geometries
List<SyndEntry> entries = geoRssFeed.getEntries();
for (SyndEntry entry : entries) {
GeoRSSModule geoRSSModule = GeoRSSUtils.getGeoRSS(entry);
System.out.println(entry.getTitle() + " : lat="
+ geoRSSModule.getPosition().getLatitude() + ",lng="
+ geoRSSModule.getPosition().getLongitude() + ", desc="
+ entry.getDescription().getValue() + "; time="
+ entry.getPublishedDate());
}
// set mandatory XML fields with our Two Track headers
geoRssFeed.setFeed();
// output
System.out.println(geoRssFeed.getFeed());
// update the feed
Position p1 = new Position(54.2, 12.4);
Position p2 = new Position(55.2, 13.4);
List<Position> newEntries = new ArrayList<Position>();
newEntries.add(p1);
newEntries.add(p2);
// replace the geometries
geoRssFeed.setEntries(newEntries);
// check new output
System.out.println(geoRssFeed.getFeed());
}
}
Maven refusing to compile Spring project due to annotations
The fix for the following issue is here http://maven.40175.n5.nabble.com/Maven-refusing-to-compile-Spring-project-due-to-annotations-tp4309204p4309211.html. Duh!
I’m running Eclipse and Maven on a Mac. Here’s my version of Maven
$ mvn -version Apache Maven 2.2.1 (r801777; 2009-08-06 20:16:01+0100) Java version: 1.6.0_22 Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home Default locale: en_US, platform encoding: MacRoman OS name: "mac os x" version: "10.5.8" arch: "x86_64" Family: "mac"
What I’m trying to do is use Maven to compile my Spring project (it builds fine in Eclipse) so I can deploy the war to a Tomcat. I setup my pom.xml (see below) and asked mvn to create the package. The build failed with the following error:
Compilation failure /path/to/WelcomeController.java:[7,1] annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations) @Controller
Doing mvn compile gives the same error. Google showed me that this was a known problem with Maven with the fix explained here:
http://maven.apache.org/plugins/maven-compiler-plugin/howto.html
I can’t see why the fix isn’t working for me. In desparation I followed these instructions:
http://pwong-tipsandtricks.blogspot.com/2009/02/install-and-test-maven-on-centos-52.html and put a fresh maven on my Linux box. The build failed with the same error, so it seems that my pom.xml is the culprit. But how? Here’s the pom.
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.fnarg.twotrack</groupId>
<artifactId>twotrack-webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Twotrack Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<appName>twotrack</appName>
<tomcatPackageName>apache-tomcat-twotrack</tomcatPackageName>
<runas.username>twotrack</runas.username>
<runas.group>twotrack</runas.group>
</properties>
<repositories>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle
Releases</name>
<url>http://repository.springsource.com/maven/bundles/milestone</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle
Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>com.springsource.org.apache.taglibs.standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
<finalName>twotrack</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Install Apache and make a web page
To make a web page you need both a web server and a text editor. The webserver we’re going to use is Apache. There are lots of choices for a text editor but many web developers use Text Pad.
The full instructions are here, but they are fairly detailed.
http://httpd.apache.org/docs/2.1/platform/windows.html
http://webdesign.about.com/cs/apache/a/aainstapachewin.htm
We’re going to run Apache on localhost. This is a special name for a computer that let’s us access our own machine as if it were a server. On localhost Apache can only send pages to one computer, but that’s ok because it’s all we need for development.
http://localhost/ in your browser
Once our website is built the files will be transferred to another Apache that will serve the page onto the Internet.
Rayburns don’t burn (properly)
In response to the completely rubbish performance of the most single major investment I’ve made in the last ten years I did this.

See, it’s been cleaned. Completely and absolutely free of any carbon. If you see even a speck of carbon, login and comment. The cooker has brand new wicks and should now burn for twelve months without further ado .. let’s fold arms, stand back and wait.
How to set up a new Eclipse project in net.fnarg package
mvn -o archetype:generate -DartifactId=classes-objects -DgroupId=net.fnarg.javatut
I accepted the archetype defaults offered by generate
cd classes-objects/ mvn -o eclipse:clean eclipse:eclipse
Eclipse > New > Java Project
Use default location
Eclipse > Preferences > Java > Build Path > Classpath Variables
New > M2_REPO = $WORKSPACE/mvn/repo
Maven creates this structure.
src/main/java
net/fnarg/javatut
class-objects/*.java
src/test/java
net/fnarg/javatut
class-objects/*.java
This project has no dependencies other than JUnit.
Update the pom.xml JUnit is version 4.6
Eclipse > File > Import > File system
note in Eclipse on Mac using a minus like ‘this-that’ gives an error in the package name.
Telling Eclipse that a resources folder is a source folder
Bring up context menu on the resources folder
Build Path > Use as Source Folder
Although these are config files rather than Java code they need to treated as sources in order for Spring to find them. And Eclipse represent the folder as a nice block rather then nested folders.
