← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5387: Added report html representation to web api

 

------------------------------------------------------------
revno: 5387
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-12-13 15:16:32 +0100
message:
  Added report html representation to web api
added:
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/TransformCacheImpl.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resource.java
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl
  dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl


--
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/src/main/java/org/hisp/dhis/api/view/TransformCacheImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/TransformCacheImpl.java	2011-12-07 13:44:45 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/TransformCacheImpl.java	2011-12-13 14:16:32 +0000
@@ -1,20 +1,5 @@
 package org.hisp.dhis.api.view;
 
-
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import javax.xml.transform.ErrorListener;
-import javax.xml.transform.Source;
-import javax.xml.transform.Templates;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamSource;
-import org.amplecode.staxwax.transformer.LoggingErrorListener;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.stereotype.Component;
-
 /*
  * Copyright (c) 2004-2005, University of Oslo
  * All rights reserved.
@@ -42,60 +27,75 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamSource;
+import org.amplecode.staxwax.transformer.LoggingErrorListener;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.stereotype.Component;
+
 /**
- *
+ * 
  * @author bobj
  * @version created 02-Dec-2011
  */
 @Component
-public class TransformCacheImpl implements TransformCache
+public class TransformCacheImpl
+    implements TransformCache
 {
-    static final String MODEL2HTML = "model2html.xsl"; 
+    static final String MODEL2HTML = "model2html.xsl";
 
-    static final String MODEL2FOP = "model2fop.xsl"; 
+    static final String MODEL2FOP = "model2fop.xsl";
 
     static final String HTMLXSLT_RESOURCE = "/templates/html/";
 
     static final String FOPXSLT_RESOURCE = "/templates/pdf/";
-    
+
     static private TransformCache instance;
-    
+
     private Templates htmlCachedTransform;
 
     private Templates fopCachedTransform;
-    
-    private TransformCacheImpl() throws IOException, TransformerConfigurationException
+
+    private TransformCacheImpl()
+        throws IOException, TransformerConfigurationException
     {
         ErrorListener errorListener = new LoggingErrorListener();
-        
+
         TransformerFactory factory = TransformerFactory.newInstance();
         factory.setErrorListener( errorListener );
 
-        Source model2html = 
-            new StreamSource(new ClassPathResource( HTMLXSLT_RESOURCE + MODEL2HTML ).getInputStream());
-        Source model2fop = 
-            new StreamSource(new ClassPathResource( FOPXSLT_RESOURCE + MODEL2FOP ).getInputStream());
+        Source model2html = new StreamSource( new ClassPathResource( HTMLXSLT_RESOURCE + MODEL2HTML ).getInputStream() );
+        Source model2fop = new StreamSource( new ClassPathResource( FOPXSLT_RESOURCE + MODEL2FOP ).getInputStream() );
 
-        factory.setURIResolver(  new ClassPathUriResolver(HTMLXSLT_RESOURCE));
+        factory.setURIResolver( new ClassPathUriResolver( HTMLXSLT_RESOURCE ) );
         htmlCachedTransform = factory.newTemplates( model2html );
-        factory.setURIResolver(  new ClassPathUriResolver(FOPXSLT_RESOURCE));
-        fopCachedTransform = factory.newTemplates( model2fop );   
+        factory.setURIResolver( new ClassPathUriResolver( FOPXSLT_RESOURCE ) );
+        fopCachedTransform = factory.newTemplates( model2fop );
     }
-    
-    static TransformCache instance() {
-        if (instance == null) {
+
+    protected static TransformCache instance()
+    {
+        if ( instance == null )
+        {
             try
             {
                 instance = new TransformCacheImpl();
-            } catch ( Exception ex )
+            }
+            catch ( Exception ex )
             {
                 Logger.getLogger( TransformCacheImpl.class.getName() ).log( Level.SEVERE, null, ex );
             }
         }
         return instance;
     }
-        
-    
 
     @Override
     public Transformer getHtmlTransformer()
@@ -110,5 +110,4 @@
     {
         return fopCachedTransform.newTransformer();
     }
-    
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java	2011-12-13 14:04:12 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java	2011-12-13 14:16:32 +0000
@@ -53,6 +53,7 @@
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response )
         throws Exception
     {
@@ -76,6 +77,7 @@
 
         // pass on any parameters set in xslt-params
         Map<String, String> params = (Map<String, String>) model.get( "xslt-params" );
+        
         if ( params != null )
         {
             for ( Map.Entry<String, String> entry : params.entrySet() )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resource.java	2011-12-07 08:41:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resource.java	2011-12-13 14:16:32 +0000
@@ -27,6 +27,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+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.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
 import org.codehaus.jackson.annotate.JsonProperty;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 import org.hisp.dhis.api.adapter.MediaTypeCollectionJsonSerializer;
@@ -38,11 +49,6 @@
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.RequestMethod;
 
-import javax.xml.bind.annotation.*;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * At some point this class will be extended to show all available options
  * for a current user for this resource. For now it is only used for index page.
@@ -55,7 +61,7 @@
 {
     private String name;
 
-    private Class clazz;
+    private Class<?> clazz;
 
     private List<RequestMethod> methods = new ArrayList<RequestMethod>();
 
@@ -66,7 +72,7 @@
 
     }
 
-    public Resource( String name, Class clazz, List<RequestMethod> methods, List<MediaType> mediaTypes )
+    public Resource( String name, Class<?> clazz, List<RequestMethod> methods, List<MediaType> mediaTypes )
     {
         this.name = name;
         this.clazz = clazz;
@@ -114,12 +120,12 @@
         this.mediaTypes = mediaTypes;
     }
 
-    public Class getClazz()
+    public Class<?> getClazz()
     {
         return clazz;
     }
 
-    public void setClazz( Class clazz )
+    public void setClazz( Class<?> clazz )
     {
         this.clazz = clazz;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl	2011-12-09 18:08:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl	2011-12-13 14:16:32 +0000
@@ -11,7 +11,7 @@
     d:categoryOptions|d:categoryOptionCombos|d:dataElements|d:indicators|
     d:organisationUnits|d:dataElementGroups|d:dataElementGroupSets|
     d:indicatorGroups|d:indicatorGroupSets|d:organisationUnitGroups|
-    d:organisationUnitGroupSets|d:indicatorTypes|d:attributeTypes">
+    d:organisationUnitGroupSets|d:indicatorTypes|d:attributeTypes|d:reports">
     <h3> <xsl:value-of select="local-name()"/> </h3>
 
     <table border="1">

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl	2011-12-09 18:08:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl	2011-12-13 14:16:32 +0000
@@ -35,6 +35,7 @@
     <xsl:include href="organisationUnitGroupSet.xsl"/>
     <xsl:include href="dataSet.xsl"/>
     <xsl:include href="attributeType.xsl"/>
+    <xsl:include href="report.xsl"/>
     <!-- etc ... -->
 
 </xsl:stylesheet>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl	2011-12-13 14:16:32 +0000
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"
+  xmlns="http://www.w3.org/1999/xhtml";
+  xmlns:d="http://dhis2.org/schema/dxf/2.0";
+  >
+
+  <xsl:template match="d:report">
+    <div class="report">
+      <h2>
+        <xsl:value-of select="@name" />
+      </h2>
+      <table border="1">
+        <tr>
+          <td>ID</td>
+          <td> <xsl:value-of select="@id" /> </td>
+        </tr>
+        <tr>
+          <td>Last Updated</td>
+          <td> <xsl:value-of select="@lastUpdated" /> </td>
+        </tr>
+      </table>
+    </div>
+  </xsl:template>
+
+</xsl:stylesheet>