Hi Chris,

We have a problem with the way FeatureTransformer leaves out fields that
are NULL in e.g. a PostGIS datastore.  The GML returns only the non-null
fields of a feature.  This makes it rather hard to edit a feature (from
within MapBuilder) for filling in fields that are null in the database.

Please find attached my proposed change in patch format (against 2.2-RC2).
[Note that I didn't do much about the indentation so my changes are clear.]

Kind regards,
-- 
-- Gertjan van Oosten, [EMAIL PROTECTED], West Consulting B.V., +31 15 2191 600
--- 
geotools-2.2-RC2/module/main/src/org/geotools/gml/producer/FeatureTransformer.java.distrib
  2006-04-06 17:29:58.000000000 +0200
+++ 
geotools-2.2-RC2/module/main/src/org/geotools/gml/producer/FeatureTransformer.java
  2006-05-02 13:17:19.000000000 +0200
@@ -28,6 +28,7 @@
 import org.geotools.xml.transform.TransformerBase;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
+import org.xml.sax.Attributes;
 import org.xml.sax.helpers.AttributesImpl;
 import org.xml.sax.helpers.NamespaceSupport;
 import java.io.IOException;
@@ -528,14 +529,20 @@
          */
         public void handleAttribute(AttributeType type, Object value) {
             try {
-                if (value != null) {
+                Attributes attrs = NULL_ATTS;
+                if (value == null) {
+                    attrs = new AttributesImpl();
+                    ((AttributesImpl) 
attrs).addAttribute("http://www.w3.org/2001/XMLSchema-instance";, "nil", 
"xsi:nil", "CDATA", "true");
+                }
+
                     String name = type.getName();
 
                     //HACK: this should be user configurable, along with the
 
                     //other gml substitutions I shall add.
 
-                    if (prefixGml //adding this in since the extra boundedBy
+                    if (value != null
+                            && prefixGml //adding this in since the extra 
boundedBy
                             //hacking should only need to be done for the weird
                         //cite tests, and having this check before the string
                         //equals should get us better performance.  Albeit
@@ -557,6 +564,7 @@
 
                         contentHandler.startElement("", "", name, NULL_ATTS);
 
+                        if (value != null) {
                         if (Geometry.class.isAssignableFrom(value.getClass())) 
{
                             geometryTranslator.encode((Geometry) value, 
srsName);
                         } else {
@@ -564,13 +572,10 @@
                             contentHandler.characters(text.toCharArray(), 0,
                                 text.length());
                         }
+                        }
 
                         contentHandler.endElement("", "", name);
                     }
-                }
-
-                //REVISIT: xsi:nillable is the proper xml way to handle nulls,
-                //but OGC people are fine with just leaving it out.       
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }

Reply via email to