← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6573: Centralized code

 

------------------------------------------------------------
revno: 6573
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-04-14 17:02:08 +0200
message:
  Centralized code
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java


--
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/controller/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java	2012-04-13 14:11:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java	2012-04-14 15:02:08 +0000
@@ -28,6 +28,7 @@
  */
 
 import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.metadata.*;
@@ -46,6 +47,8 @@
 import java.io.IOException;
 import java.util.zip.*;
 
+import static org.hisp.dhis.api.utils.ContextUtils.*;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -59,6 +62,9 @@
 
     @Autowired
     private ImportService importService;
+    
+    @Autowired
+    private ContextUtils contextUtils;
 
     //-------------------------------------------------------------------------------------------------------
     // Export
@@ -82,9 +88,8 @@
     {
         MetaData metaData = exportService.getMetaData( exportOptions );
 
-        response.setContentType( ContextUtils.CONTENT_TYPE_ZIP );
-        response.addHeader( "Content-Disposition", "attachment; filename=\"export.xml.zip\"" );
-        response.addHeader( "Content-Transfer-Encoding", "binary" );
+        contextUtils.configureResponse( response, CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "export.xml.zip", true );
+        response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
 
         ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
         zip.putNextEntry( new ZipEntry( "export.xml" ) );
@@ -98,9 +103,8 @@
     {
         MetaData metaData = exportService.getMetaData( exportOptions );
 
-        response.setContentType( ContextUtils.CONTENT_TYPE_ZIP );
-        response.addHeader( "Content-Disposition", "attachment; filename=\"export.json.zip\"" );
-        response.addHeader( "Content-Transfer-Encoding", "binary" );
+        contextUtils.configureResponse( response, CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "export.json.zip", true );
+        response.addHeader( HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
 
         ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
         zip.putNextEntry( new ZipEntry( "export.json" ) );
@@ -114,7 +118,7 @@
     {
         MetaData metaData = exportService.getMetaData( exportOptions );
 
-        response.setContentType( ContextUtils.CONTENT_TYPE_GZIP );
+        response.setContentType( CONTENT_TYPE_GZIP );
         GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
 
         JacksonUtils.toXmlWithView( gzip, metaData, ExportView.class );
@@ -126,7 +130,7 @@
     {
         MetaData metaData = exportService.getMetaData( exportOptions );
 
-        response.setContentType( ContextUtils.CONTENT_TYPE_GZIP );
+        response.setContentType( CONTENT_TYPE_GZIP );
         GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
 
         JacksonUtils.toJsonWithView( gzip, metaData, ExportView.class );
@@ -167,7 +171,7 @@
     public void importZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws JAXBException, IOException
     {
         ZipInputStream zip = new ZipInputStream( request.getInputStream() );
-        ZipEntry entry = zip.getNextEntry();
+        zip.getNextEntry();
 
         MetaData metaData = JacksonUtils.fromXml( zip, MetaData.class );
         System.err.println( metaData );
@@ -183,7 +187,7 @@
     public void importZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
     {
         ZipInputStream zip = new ZipInputStream( request.getInputStream() );
-        ZipEntry entry = zip.getNextEntry();
+        zip.getNextEntry();
 
         MetaData metaData = JacksonUtils.fromJson( zip, MetaData.class );
         System.err.println( metaData );
@@ -200,8 +204,8 @@
     public void importGZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws JAXBException, IOException
     {
         GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
+        
         MetaData metaData = JacksonUtils.fromXml( gzip, MetaData.class );
-
         System.err.println( metaData );
 
         ImportSummary summary = importService.importMetaData( metaData, importOptions );
@@ -217,7 +221,6 @@
         GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
 
         MetaData metaData = JacksonUtils.fromJson( gzip, MetaData.class );
-
         System.err.println( metaData );
 
         ImportSummary summary = importService.importMetaData( metaData, importOptions );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java	2012-04-08 18:10:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/ContextUtils.java	2012-04-14 15:02:08 +0000
@@ -64,6 +64,7 @@
     public static final String HEADER_CACHE_CONTROL = "Cache-Control";
     public static final String HEADER_EXPIRES = "Expires";
     public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition";
+    public static final String HEADER_CONTENT_TRANSFER_ENCODING = "Content-Transfer-Encoding";
 
     @Autowired
     private SystemSettingManager systemSettingManager;