← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5148: (api) mostly test-code for generating json/xml

 

------------------------------------------------------------
revno: 5148
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-11-12 15:46:34 +0000
message:
  (api) mostly test-code for generating json/xml
removed:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/listener/
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/listener/IdentifiableObjectListener.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java
modified:
  dhis-2/dhis-web/dhis-web-api/pom.xml
  dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml
  dhis-2/pom.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/pom.xml'
--- dhis-2/dhis-web/dhis-web-api/pom.xml	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/pom.xml	2011-11-12 15:46:34 +0000
@@ -39,6 +39,10 @@
       <artifactId>jackson-mapper-asl</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-xc</artifactId>
+    </dependency>
+    <dependency>
       <groupId>javax.xml.bind</groupId>
       <artifactId>jaxb-api</artifactId>
     </dependency>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,68 @@
+package org.hisp.dhis.api.controller;
+
+import org.hisp.dhis.api.listener.IdentifiableObjectListener;
+import org.hisp.dhis.api.resources.XChart;
+import org.hisp.dhis.api.resources.XCharts;
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.chart.ChartService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+
+@Controller
+@RequestMapping( value = "/charts" )
+public class ChartController
+{
+    @Autowired
+    private ChartService chartService;
+
+    @RequestMapping( method = RequestMethod.GET )
+    public XCharts getCharts( HttpServletRequest request )
+    {
+        XCharts charts = new XCharts();
+
+        Collection<Chart> allCharts = chartService.getAllCharts();
+
+        for ( Chart chart : allCharts )
+        {
+            charts.getCharts().add( new XChart( chart ) );
+        }
+
+        new IdentifiableObjectListener( request ).beforeMarshal( charts );
+
+        return charts;
+    }
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
+    public XChart getChart( @PathVariable( "uid" ) Integer uid, HttpServletRequest request )
+    {
+        XChart chart = new XChart( chartService.getChart( uid ) );
+
+        new IdentifiableObjectListener( request ).beforeMarshal( chart );
+
+        return chart;
+    }
+
+    @RequestMapping( method = RequestMethod.POST )
+    @ResponseBody
+    public void postChart( XChart chart )
+    {
+
+    }
+
+    /*
+    @RequestMapping( method = RequestMethod.POST )
+    public void postChart( InputStream inputStream ) throws IOException
+    {
+        StringWriter writer = new StringWriter();
+        IOUtils.copy( inputStream, writer, "UTF-8" );
+        System.err.println( writer.toString() );
+    }
+    */
+}

=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java	1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-package org.hisp.dhis.api.controller;
-
-import org.hisp.dhis.api.resources.Element;
-import org.hisp.dhis.api.resources.Elements;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-@Controller
-@RequestMapping( value = "/elements" )
-public class ElementController
-{
-    private Elements elements = new Elements();
-
-    public ElementController()
-    {
-        elements.getElements().add( new Element( 1, "Element #1" ) );
-        elements.getElements().add( new Element( 2, "Element #2" ) );
-        elements.getElements().add( new Element( 3, "Element #3" ) );
-        elements.getElements().add( new Element( 4, "Element #4" ) );
-        elements.getElements().add( new Element( 5, "Element #5" ) );
-    }
-
-    @RequestMapping
-    public String getElements( Model model )
-    {
-        model.addAttribute( "elements", elements );
-
-        return "elements";
-    }
-
-    @RequestMapping( value = "/{uid}" )
-    public String getElement( @PathVariable( "uid" ) Integer uid, Model model )
-    {
-        model.addAttribute( "element", elements.getElement( uid ) );
-
-        return "element";
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java	2011-11-02 11:14:35 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java	1970-01-01 00:00:00 +0000
@@ -1,18 +0,0 @@
-package org.hisp.dhis.api.controller;
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-@Controller
-@RequestMapping( value = "/" )
-public class IndexController
-{
-    @RequestMapping( method = RequestMethod.GET )
-    @ResponseBody
-    public String index()
-    {
-        return "Nothing to see here yet.";
-    }
-}

=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,49 @@
+package org.hisp.dhis.api.converter;
+
+import org.hisp.dhis.api.resources.XIdentifiableObject;
+import org.springframework.http.HttpInputMessage;
+import org.springframework.http.HttpOutputMessage;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.http.converter.HttpMessageNotWritableException;
+
+import java.io.IOException;
+import java.util.List;
+
+public class Jaxb2HttpMessageConverter implements HttpMessageConverter<XIdentifiableObject>
+{
+    @Override
+    public boolean canRead( Class<?> clazz, MediaType mediaType )
+    {
+        System.err.println("canread");
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public boolean canWrite( Class<?> clazz, MediaType mediaType )
+    {
+        System.err.println("canwriter");
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public List<MediaType> getSupportedMediaTypes()
+    {
+        System.err.println("getsupportedmediatypes");
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public XIdentifiableObject read( Class<? extends XIdentifiableObject> clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException
+    {
+        System.err.println("read");
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    @Override
+    public void write( XIdentifiableObject identifiableObject, MediaType contentType, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException
+    {
+        System.err.println("write");
+    }
+}

=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/listener'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/listener/IdentifiableObjectListener.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/listener/IdentifiableObjectListener.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/listener/IdentifiableObjectListener.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,46 @@
+package org.hisp.dhis.api.listener;
+
+import org.hisp.dhis.api.resources.XChart;
+import org.hisp.dhis.api.resources.XCharts;
+import org.hisp.dhis.api.resources.XIdentifiableObject;
+import org.springframework.util.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.bind.Marshaller;
+
+public class IdentifiableObjectListener extends Marshaller.Listener {
+    private HttpServletRequest request;
+
+    public IdentifiableObjectListener(HttpServletRequest request) {
+        this.request = request;
+    }
+
+    @Override
+    public void beforeMarshal(Object source) {
+        if (source instanceof XCharts) {
+            XCharts charts = (XCharts) source;
+
+            for (XChart chart : charts.getCharts()) {
+                addHref(chart, request);
+            }
+        } else if (source instanceof XChart) {
+            XChart chart = (XChart) source;
+            addHref(chart, request);
+        }
+    }
+
+    public void addHref(XIdentifiableObject identifiableObject, HttpServletRequest request) {
+        String path = request.getRequestURL().toString();
+        path = StringUtils.stripFilenameExtension(path);
+
+        while (path.lastIndexOf("/") == path.length() - 1) {
+            path = path.substring(0, path.length() - 1);
+        }
+
+        identifiableObject.setHref(path + "/" + identifiableObject.getId());
+    }
+
+    @Override
+    public void afterMarshal(Object source) {
+    }
+}

=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java	1970-01-01 00:00:00 +0000
@@ -1,53 +0,0 @@
-package org.hisp.dhis.api.resources;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement
-@XmlAccessorType( XmlAccessType.FIELD )
-public class Element
-{
-    @XmlAttribute
-    private Integer uid;
-
-    @XmlAttribute
-    private String name;
-
-    public Element()
-    {
-    }
-
-    public Element( String name )
-    {
-        this();
-        this.name = name;
-    }
-
-    public Element( Integer uid, String name )
-    {
-        this.uid = uid;
-        this.name = name;
-    }
-
-    public Integer getUid()
-    {
-        return uid;
-    }
-
-    public void setUid( Integer uid )
-    {
-        this.uid = uid;
-    }
-
-    public String getName()
-    {
-        return name;
-    }
-
-    public void setName( String name )
-    {
-        this.name = name;
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java	1970-01-01 00:00:00 +0000
@@ -1,40 +0,0 @@
-package org.hisp.dhis.api.resources;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-@XmlRootElement
-@XmlAccessorType( XmlAccessType.FIELD )
-public class Elements
-{
-    @XmlElement( name = "element" )
-    private List<Element> elements = new ArrayList<Element>();
-
-    public List<Element> getElements()
-    {
-        return elements;
-    }
-
-    public void setElements( List<Element> elements )
-    {
-        this.elements = elements;
-    }
-
-    public Element getElement( Integer uid )
-    {
-        for ( Element el : elements )
-        {
-            if ( el.getUid().equals( uid ) )
-            {
-                return el;
-            }
-        }
-
-        return null;
-    }
-}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,23 @@
+package org.hisp.dhis.api.resources;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.hisp.dhis.chart.Chart;
+
+@XmlRootElement( name = "chart" )
+public class XChart
+    extends XIdentifiableObject
+{
+    private Chart chart;
+
+    public XChart()
+    {
+
+    }
+
+    public XChart( Chart chart )
+    {
+        super( chart );
+        this.chart = chart;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,24 @@
+package org.hisp.dhis.api.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement( name = "charts" )
+public class XCharts
+{
+    private List<XChart> charts = new ArrayList<XChart>();
+
+    public XCharts()
+    {
+
+    }
+
+    @XmlElement( name = "chart" )
+    public List<XChart> getCharts()
+    {
+        return charts;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,73 @@
+package org.hisp.dhis.api.resources;
+
+import org.hisp.dhis.common.IdentifiableObject;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.Date;
+
+@XmlRootElement
+public class XIdentifiableObject
+{
+    private IdentifiableObject identifiableObject;
+
+    private String href;
+
+    public XIdentifiableObject()
+    {
+
+    }
+
+    public XIdentifiableObject( IdentifiableObject identifiableObject )
+    {
+        this.identifiableObject = identifiableObject;
+    }
+
+    @XmlAttribute
+    public int getId()
+    {
+        return identifiableObject.getId();
+    }
+
+    @XmlAttribute
+    public String getUuid()
+    {
+        return identifiableObject.getUuid();
+    }
+
+    @XmlAttribute
+    public String getUid()
+    {
+        return identifiableObject.getUid();
+    }
+
+    @XmlAttribute
+    public String getName()
+    {
+        return identifiableObject.getName();
+    }
+
+    @XmlAttribute
+    public String getCode()
+    {
+        return identifiableObject.getCode();
+    }
+
+    @XmlAttribute
+    public Date getLastUpdated()
+    {
+        return identifiableObject.getLastUpdated();
+    }
+
+    @XmlAttribute
+    public String getHref()
+    {
+        return href;
+    }
+
+    public void setHref( String href )
+    {
+        this.href = href;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,43 @@
+package org.hisp.dhis.api.resources;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.hisp.dhis.common.NameableObject;
+
+@XmlRootElement
+public class XNameableObject
+    extends XIdentifiableObject
+{
+    private NameableObject nameableObject;
+
+    public XNameableObject()
+    {
+
+    }
+
+    public XNameableObject( NameableObject nameableObject )
+    {
+        super( nameableObject );
+        this.nameableObject = nameableObject;
+    }
+
+    @XmlElement
+    public String getAlternativeName()
+    {
+        return nameableObject.getAlternativeName();
+    }
+
+    @XmlElement
+    public String getShortName()
+    {
+        return nameableObject.getShortName();
+    }
+
+    @XmlElement
+    public String getDescription()
+    {
+        return nameableObject.getDescription();
+    }
+
+}

=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,97 @@
+package org.hisp.dhis.api.view;
+
+import org.codehaus.jackson.JsonEncoding;
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.util.JSONPObject;
+import org.springframework.web.servlet.view.json.MappingJacksonJsonView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
+
+/**
+ * @author mortenoh
+ */
+public class ExtendedMappingJacksonView extends MappingJacksonJsonView
+{
+
+    private boolean includeRootElement = false;
+
+    private boolean withPadding = false;
+
+    private String callbackParameter = "callback";
+
+    private String paddingFunction = "callback";
+
+    public ExtendedMappingJacksonView()
+    {
+
+    }
+
+    public ExtendedMappingJacksonView( boolean withPadding )
+    {
+        this.withPadding = withPadding;
+
+        if ( withPadding )
+        {
+            setContentType( "application/javascript" );
+        }
+    }
+
+    public void setIncludeRootElement( boolean includeRootElement )
+    {
+        this.includeRootElement = includeRootElement;
+    }
+
+    public void setWithPadding( boolean withPadding )
+    {
+        this.withPadding = withPadding;
+    }
+
+    public void setCallbackParameter( String callbackParameter )
+    {
+        this.callbackParameter = callbackParameter;
+    }
+
+    public void setPaddingFunction( String paddingFunction )
+    {
+        this.paddingFunction = paddingFunction;
+    }
+
+    @Override
+    protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response ) throws Exception
+    {
+        Object value = filterModel( model );
+        ObjectMapper objectMapper = new ObjectMapper();
+        JsonFactory jf = objectMapper.getJsonFactory();
+        JsonGenerator jg = jf.createJsonGenerator( response.getOutputStream(), JsonEncoding.UTF8 );
+
+        if ( !includeRootElement && value instanceof Map )
+        {
+            Map map = ( Map ) value;
+
+            if ( map.size() == 1 )
+            {
+                value = map.values().toArray()[0];
+            }
+        }
+
+        if ( withPadding )
+        {
+            String callback = request.getParameter( callbackParameter );
+
+            if ( callback == null || callback.length() == 0 )
+            {
+                callback = paddingFunction;
+            }
+
+            JSONPObject valueWithPadding = new JSONPObject( callback, value );
+            jg.writeObject( valueWithPadding );
+        } else
+        {
+            jg.writeObject( value );
+        }
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java	2011-11-12 15:46:34 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.api.view;
+
+import org.springframework.validation.BindingResult;
+import org.springframework.web.servlet.view.AbstractView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author mortenoh
+ */
+public class Jaxb2View extends AbstractView {
+    public static final String DEFAULT_CONTENT_TYPE = "application/xml";
+
+    public Jaxb2View() {
+        setContentType(DEFAULT_CONTENT_TYPE);
+    }
+
+    @Override
+    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        response.setContentType(getContentType());
+
+        Object value = filterModel(model);
+
+        if (value instanceof Map) {
+            Map map = (Map) value;
+
+            if (map.size() == 1) {
+                value = map.values().toArray()[0];
+            }
+        }
+
+        OutputStream outputStream = response.getOutputStream();
+        JAXBContext context = JAXBContext.newInstance(value.getClass());
+        Marshaller marshaller = context.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+
+//        Marshaller.Listener listener = new IdentifiableObjectListener(request);
+//        marshaller.setListener(listener);
+
+        /* TODO This will only work on JAXB RI (and crash on others!) please fixme.. */
+
+        /*
+        marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders",
+                "\n<?xml-stylesheet type=\"text/xsl\" href=\"dhis-web-api/xslt/chart.xslt\"?>\n");
+        */
+
+        marshaller.marshal(value, outputStream);
+    }
+
+    protected Object filterModel(Map<String, Object> model) {
+        Map<String, Object> result = new HashMap<String, Object>(model.size());
+
+        for (Map.Entry<String, Object> entry : model.entrySet()) {
+            if (!(entry.getValue() instanceof BindingResult)) {
+                result.put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        return result;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml	2011-11-12 15:46:34 +0000
@@ -1,61 +1,42 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:beans="http://www.springframework.org/schema/beans";
-  xmlns:context="http://www.springframework.org/schema/context"; xmlns:mvc="http://www.springframework.org/schema/mvc";
-  xmlns:p="http://www.springframework.org/schema/p";
-  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
+<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+             xmlns:beans="http://www.springframework.org/schema/beans";
+             xmlns:context="http://www.springframework.org/schema/context";
+             xmlns:mvc="http://www.springframework.org/schema/mvc";
+             xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd";>
 
   <mvc:annotation-driven />
-  <mvc:resources mapping="/resources/**" location="/resources/" />
 
   <context:component-scan base-package="org.hisp.dhis.api" />
 
-  <beans:bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
-    <beans:property name="classesToBeBound">
-      <beans:list>
-        <beans:value>org.hisp.dhis.api.resources.Elements</beans:value>
-        <beans:value>org.hisp.dhis.api.resources.Element</beans:value>
-      </beans:list>
-    </beans:property>
-  </beans:bean>
-
   <beans:bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
+    <beans:property name="order" value="1" />
     <beans:property name="mediaTypes">
       <beans:map>
-        <beans:entry key="html" value="text/html" />
+        <beans:entry key="json" value="application/json" />
+        <beans:entry key="jsonp" value="application/javascript" />
         <beans:entry key="xml" value="application/xml" />
-        <beans:entry key="json" value="application/json" />
       </beans:map>
     </beans:property>
 
     <beans:property name="defaultViews">
       <beans:list>
-        <beans:bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
-        <beans:bean class="org.springframework.web.servlet.view.xml.MarshallingView">
-          <beans:constructor-arg ref="jaxb2Marshaller" />
+        <beans:bean class="org.hisp.dhis.api.view.ExtendedMappingJacksonView" />
+
+        <beans:bean class="org.hisp.dhis.api.view.ExtendedMappingJacksonView">
+          <beans:constructor-arg name="withPadding" value="true" />
         </beans:bean>
+
+        <beans:bean class="org.hisp.dhis.api.view.Jaxb2View" />
       </beans:list>
     </beans:property>
 
-    <beans:property name="defaultContentType" value="text/html" />
-  </beans:bean>
-
-  <beans:bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
-    <beans:property name="resourceLoaderPath" value="/WEB-INF/views/" />
-  </beans:bean>
-
-  <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
-    <beans:property name="cache" value="true" />
-    <beans:property name="prefix" value="" />
-    <beans:property name="suffix" value=".vm" />
-  </beans:bean>
-
-
-  <!-- <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> -->
-  <!-- <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> -->
-  <!-- <beans:property name="prefix" value="/WEB-INF/views/" /> -->
-  <!-- <beans:property name="suffix" value=".jsp" /> -->
-  <!-- </beans:bean> -->
+    <beans:property name="defaultContentType" value="application/xml" />
+    <beans:property name="favorParameter" value="true" />
+  </beans:bean>
+
+  <beans:bean class="org.hisp.dhis.api.converter.Jaxb2HttpMessageConverter" />
 
 </beans:beans>

=== removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views'
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm'
--- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-
-<a href="../elements">All elements</a>
-
-<p>
-$element.name
-</p>

=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm'
--- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm	2011-11-03 16:43:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm	1970-01-01 00:00:00 +0000
@@ -1,10 +0,0 @@
-
-<p>
-Elements [<a href="elements.json">JSON</a>, <a href="elements.xml">XML</a>]</li>
-</p>
-
-<ul>
-#foreach( $element in $elements.elements )
-	<li><a href="elements/$element.uid">$element.name</a> [<a href="elements/${element.uid}.json">JSON</a>, <a href="elements/${element.uid}.xml">XML</a>]</li>	
-#end
-</ul>

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2011-11-10 23:04:32 +0000
+++ dhis-2/pom.xml	2011-11-12 15:46:34 +0000
@@ -1,5 +1,5 @@
 <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";>
+         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>org.hisp.dhis</groupId>
   <artifactId>dhis</artifactId>
@@ -753,7 +753,13 @@
       <dependency>
         <groupId>org.codehaus.jackson</groupId>
         <artifactId>jackson-mapper-asl</artifactId>
-        <version>1.6.4</version>
+        <version>1.7.1</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.codehaus.jackson</groupId>
+        <artifactId>jackson-xc</artifactId>
+        <version>1.7.1</version>
       </dependency>
 
       <dependency>