Statistics
| Revision:

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

History | View | Annotate | Download (2.67 KB)

1 21200 vcaballero
package org.gvsig.fmap.mapcontext.layers.operations;
2
3 22237 vcaballero
import java.util.Iterator;
4
5 23750 jjdelcerro
import org.gvsig.fmap.data.exceptions.ReadException;
6 22360 jmvivo
import org.gvsig.fmap.data.feature.Feature;
7
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
8
import org.gvsig.fmap.data.feature.FeatureCollection;
9
import org.gvsig.fmap.data.feature.FeatureType;
10 22592 jmvivo
import org.gvsig.fmap.geom.Geometry;
11 21200 vcaballero
import org.gvsig.fmap.mapcontext.layers.FLayer;
12 21887 vcaballero
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
13 21200 vcaballero
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 21298 vcaballero
        private FeatureCollection selection;
21 21200 vcaballero
        private FLayer layer;
22
23 21298 vcaballero
        public VectorialXMLItem(FeatureCollection selection, FLayer layer) {
24
                this.selection = selection;
25 21200 vcaballero
                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 22592 jmvivo
                handler.startElement("", "", (layer).getName(), aii);
37 21200 vcaballero
                try {
38
39 22237 vcaballero
//                        FeatureStore ds = ((FLyrVect) layer).getFeatureStore();
40
                        Iterator iterator=selection.iterator();
41
                        int j=0;
42 22592 jmvivo
                        FeatureAttributeDescriptor attr;
43 22600 jmvivo
                        Object value;
44
                        String strValue;
45 22237 vcaballero
                        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 22592 jmvivo
                                        attr = (FeatureAttributeDescriptor) featureType
51
                                                        .get(k);
52 22600 jmvivo
                                        value = feature.get(k);
53
                                        if (value == null) {
54
                                                strValue = "{null}";
55 22592 jmvivo
                                        } else {
56 22600 jmvivo
                                                strValue = value.toString();
57 22592 jmvivo
                                        }
58
                                        ai.addAttribute("", attr.getName(), "",
59 22600 jmvivo
                                        "xs:string",
60
                                                        strValue);
61 22237 vcaballero
                                }
62
                                handler.startElement("", "", String.valueOf(j), ai);
63
                                handler.endElement("", "", String.valueOf(j));
64
                                j++;
65
                        }
66
67 21200 vcaballero
                        //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 22592 jmvivo
                handler.endElement("", "", (layer).getName());
88 21200 vcaballero
        }
89
}