Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / operations / VectorialXMLItem.java @ 24504

History | View | Annotate | Download (2.64 KB)

1
package org.gvsig.fmap.mapcontext.layers.operations;
2

    
3
import java.util.Iterator;
4

    
5
import org.gvsig.fmap.dal.exception.ReadException;
6
import org.gvsig.fmap.dal.feature.Feature;
7
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
8
import org.gvsig.fmap.dal.feature.FeatureSet;
9
import org.gvsig.fmap.dal.feature.FeatureType;
10
import org.gvsig.fmap.geom.Geometry;
11
import org.gvsig.fmap.mapcontext.layers.FLayer;
12
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
13
import org.xml.sax.ContentHandler;
14
import org.xml.sax.SAXException;
15
import org.xml.sax.helpers.AttributesImpl;
16

    
17

    
18
public class VectorialXMLItem implements XMLItem {
19

    
20
        private FeatureSet selection;
21
        private FLayer layer;
22

    
23
        public VectorialXMLItem(FeatureSet selection, FLayer layer) {
24
                this.selection = selection;
25
                this.layer = layer;
26
        }
27

    
28
        public FLayer getLayer(){
29
                return layer;
30
        }
31
        /**
32
         * @see com.iver.cit.gvsig.gui.toolListeners.InfoListener.XMLItem#parse(org.xml.sax.ContentHandler)
33
         */
34
        public void parse(ContentHandler handler) throws SAXException {
35
                AttributesImpl aii = new AttributesImpl();
36
                handler.startElement("", "", (layer).getName(), aii);
37
                try {
38

    
39
//                        FeatureStore ds = ((FLyrVect) layer).getFeatureStore();
40
                        Iterator iterator=selection.iterator();
41
                        int j=0;
42
                        FeatureAttributeDescriptor attr;
43
                        Object value;
44
                        String strValue;
45
                        while (iterator.hasNext()) {
46
                                Feature feature = (Feature) iterator.next();
47
                                AttributesImpl ai = new AttributesImpl();
48
                                FeatureType featureType=((FLyrVect) layer).getFeatureStore().getDefaultFeatureType();
49
                                for (int k = 0; k < featureType.size(); k++) {
50
                                        attr = (FeatureAttributeDescriptor) featureType
51
                                                        .get(k);
52
                                        value = feature.get(k);
53
                                        if (value == null) {
54
                                                strValue = "{null}";
55
                                        } else {
56
                                                strValue = value.toString();
57
                                        }
58
                                        ai.addAttribute("", attr.getName(), "",
59
                                        "xs:string",
60
                                                        strValue);
61
                                }
62
                                handler.startElement("", "", String.valueOf(j), ai);
63
                                handler.endElement("", "", String.valueOf(j));
64
                                j++;
65
                        }
66

    
67
                        //TODO
68
//                        ds.start();
69
//
70
//                        for (int j = bitset.nextSetBit(0); j >= 0; j = bitset
71
//                                        .nextSetBit(j + 1)) {
72
//                                AttributesImpl ai = new AttributesImpl();
73
//
74
//                                for (int k = 0; k < ds.getFieldCount(); k++) {
75
//                                        ai.addAttribute("", ds.getFieldName(k), "",
76
//                                                        "xs:string", ds.getFieldValue(j, k).toString());
77
//                                }
78
//                                handler.startElement("", "", String.valueOf(j), ai);
79
//                                handler.endElement("", "", String.valueOf(j));
80
//                        }
81
//
82
//                        ds.stop();
83

    
84
                } catch (ReadException e) {
85
                        throw new SAXException(e);
86
                }
87
                handler.endElement("", "", (layer).getName());
88
        }
89
}
90