dropcash and Java

If you’ve ever needed to raise a couple bucks for a project, a birthday or a fundraiser, you should check out dropcash (by Andre Torres). dropcash lets you set up a personal fundraising campaign using paypal and TypeKey. The campaign can be dropped into your site using a simple JavaScript include just like Flickr or Google Adsense, but you can programatically access the status of your campaign using the XML feed. There are a couple different implementations of the API (COM, MovableType, TextPattern and ColdFusion, more…), but no Java so I wrapped up a Java version and a JSP version. JSP is simpler of the two:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<c:import var="dropcash" url="http://www.dropcash.com/campaign/ajohnson1200/test/xml"/>
<x:parse var="dropcashxml" doc="${dropcash}"/>
campaignid: <x:out select="$dropcashxml//@id" />
typekey_user: <x:out select="$dropcashxml//typekey_user"/>
receiver: <x:out select="$dropcashxml//receiver"/>
title: <x:out select="$dropcashxml//title"/>
goal: <x:out select="$dropcashxml//goal"/>
total_collected: <x:out select="$dropcashxml//total_collected"/>
description: <x:out select="$dropcashxml//description"/>
percentage: <x:out select="$dropcashxml//percentage"/>

Java less straightforward:
URL url = new URL("http://www.dropcash.com/campaign/ajohnson1200/test/xml");
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
InputStream is = uc.getInputStream();
DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance();
InputStream inputXML = url.openStream();
DocumentBuilder docbuilder = docfactory.newDocumentBuilder();
Document document = docbuilder.parse(inputXML);
Element campaign = document.getDocumentElement();
System.out.println("campaignid = " + campaign.getAttribute("id"));
NodeList nodes = campaign.getChildNodes();
for (int i=0; i
Download the full JSP and Java source code.


Leave a Reply

Your email address will not be published. Required fields are marked *