dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06081
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1897: Retrieving namepace and version on DXF import
------------------------------------------------------------
revno: 1897
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Tue 2010-05-25 12:29:27 +0200
message:
Retrieving namepace and version on DXF import
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.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-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java 2010-05-25 09:51:42 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java 2010-05-25 10:29:27 +0000
@@ -41,6 +41,7 @@
public static final String ATTRIBUTE_MINOR_VERSION = "minorVersion";
public static final String ATTRIBUTE_EXPORTED = "exported";
public static final String NAMESPACE_10 = "http://dhis2.org/schema/dxf/1.0";
+ public static final String MINOR_VERSION_10 = "1.0";
public static final String MINOR_VERSION_11 = "1.1";
private ImportType type;
@@ -73,9 +74,9 @@
public boolean minorVersionGreaterOrEqual( String version )
{
- if ( version == null )
+ if ( version == null || minorVersion == null )
{
- return false; // Backwards compatible with DXF files without version
+ return false; // For legacy DXF files without version
}
if ( !MathUtils.isNumeric( version ) )
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java 2010-05-25 09:51:42 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/importer/DefaultXMLImportService.java 2010-05-25 10:29:27 +0000
@@ -36,6 +36,7 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.transform.Source;
@@ -63,6 +64,9 @@
import org.hisp.dhis.system.util.StreamUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import static org.hisp.dhis.importexport.ImportParams.*;
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+
/**
* @author bobj
*/
@@ -160,6 +164,17 @@
if ( rootName.getLocalPart().equals( DXF_ROOT ) )
{
dxfReader = XMLFactory.getXMLReader( streamReader ); // Native DXF stream - no transform required
+
+ // -----------------------------------------------------------------
+ // Retrieve namespace and version from root element and set on
+ // import params. Use default if not found.
+ // -----------------------------------------------------------------
+
+ params.setNamespace( defaultIfEmpty( rootName.getNamespaceURI(), NAMESPACE_10 ) );
+ Attribute versionAttribute = root.getAttributeByName( new QName( ATTRIBUTE_MINOR_VERSION ) );
+ params.setMinorVersion( versionAttribute != null ? versionAttribute.getValue() : MINOR_VERSION_10 );
+
+ log.info( "Using DXF namespace '" + params.getNamespace() + "' version '" + params.getMinorVersion() + "'" );
}
else
{
@@ -184,6 +199,9 @@
log.info( "Transform successful - Importing DXF" );
dxfReader = new DefaultXMLEventReader( (XMLEventReader2) pipeoutput ); // Set dxfReader to output of pipe
+
+ params.setNamespace( NAMESPACE_10 ); // Use latest namespace and version
+ params.setMinorVersion( MINOR_VERSION_11 );
}
// ---------------------------------------------------------------------