dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27252
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13532: more robust mediatype handling in meta-data controller
------------------------------------------------------------
revno: 13532
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-01-02 12:23:53 +0100
message:
more robust mediatype handling in meta-data controller
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.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 2014-01-02 11:16:43 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2014-01-02 11:23:53 +0000
@@ -30,7 +30,6 @@
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.metadata.ExportService;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
import org.hisp.dhis.dxf2.metadata.ImportService;
@@ -43,6 +42,7 @@
import org.hisp.dhis.system.scheduling.Scheduler;
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -133,7 +133,7 @@
{
String accept = request.getHeader( "Accept" );
- if ( accept != null && accept.equalsIgnoreCase( "application/json" ) )
+ if ( isJson( accept ) )
{
exportZippedJSON( parameters, response );
}
@@ -183,7 +183,7 @@
{
String accept = request.getHeader( "Accept" );
- if ( accept != null && accept.equalsIgnoreCase( "application/json" ) )
+ if ( isJson( accept ) )
{
exportGZippedJSON( parameters, response );
}
@@ -368,4 +368,18 @@
response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
response.setStatus( HttpServletResponse.SC_NO_CONTENT );
}
+
+ //--------------------------------------------------------------------------
+ // Supportive Methods
+ //--------------------------------------------------------------------------
+
+ public boolean isJson( String accept )
+ {
+ return accept != null && MediaType.parseMediaType( accept ).isCompatibleWith( MediaType.APPLICATION_JSON );
+ }
+
+ public boolean isXml( String accept )
+ {
+ return accept != null && MediaType.parseMediaType( accept ).isCompatibleWith( MediaType.APPLICATION_XML );
+ }
}