Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / info / gui / VectorialXMLItem.java @ 33205

History | View | Annotate | Download (3.84 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 {Iver T.I.}   {Task}
26
*/
27
 
28
package org.gvsig.app.project.documents.view.info.gui;
29

    
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.exception.ReadException;
32
import org.gvsig.tools.dispose.DisposableIterator;
33
import org.gvsig.fmap.dal.feature.Feature;
34
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
35
import org.gvsig.fmap.dal.feature.FeatureSet;
36
import org.gvsig.fmap.dal.feature.FeatureType;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.tools.dispose.DisposeUtils;
40
import org.xml.sax.ContentHandler;
41
import org.xml.sax.SAXException;
42
import org.xml.sax.helpers.AttributesImpl;
43

    
44
/**
45
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
46
 */
47
public class VectorialXMLItem implements XMLItem {
48

    
49
        private FeatureSet selection;
50
        private FLayer layer;
51

    
52
        public VectorialXMLItem(FeatureSet selection, FLayer layer) {
53
                this.selection = selection;
54
                this.layer = layer;
55
        }
56

    
57
        public FLayer getLayer(){
58
                return layer;
59
        }
60
        /**
61
         * @see org.gvsig.app.project.documents.view.info.gui.iver.cit.gvsig.gui.toolListeners.InfoListener.XMLItem#parse(org.xml.sax.ContentHandler)
62
         */
63
        public void parse(ContentHandler handler) throws SAXException {
64
                AttributesImpl aii = new AttributesImpl();
65
                handler.startElement("", "", (layer).getName(), aii);
66
                DisposableIterator iterator = null;
67
                try {
68

    
69
//                        FeatureStore ds = ((FLyrVect) layer).getFeatureStore();
70
                        iterator = selection.iterator();
71
                        int j=0;
72
                        FeatureAttributeDescriptor attr;
73
                        Object value;
74
                        String strValue;
75
                        while (iterator.hasNext()) {
76
                                Feature feature = (Feature) iterator.next();
77
                                AttributesImpl ai = new AttributesImpl();
78
                                FeatureType featureType=((FLyrVect) layer).getFeatureStore().getDefaultFeatureType();
79
                                for (int k = 0; k < featureType.size(); k++) {
80
                                        attr = (FeatureAttributeDescriptor) featureType
81
                                                        .get(k);
82
                                        value = feature.get(k);
83
                                        if (value == null) {
84
                                                strValue = "{null}";
85
                                        } else {
86
                                                strValue = value.toString();
87
                                        }
88
                                        ai.addAttribute("", attr.getName(), attr.getName(),
89
                                        "xs:string",
90
                                                        strValue);
91
                                }
92
                                handler.startElement("", "", String.valueOf(j), ai);
93
                                handler.endElement("", "", String.valueOf(j));
94
                                j++;
95
                        }
96

    
97
                        //TODO
98
//                        ds.start();
99
//
100
//                        for (int j = bitset.nextSetBit(0); j >= 0; j = bitset
101
//                                        .nextSetBit(j + 1)) {
102
//                                AttributesImpl ai = new AttributesImpl();
103
//
104
//                                for (int k = 0; k < ds.getFieldCount(); k++) {
105
//                                        ai.addAttribute("", ds.getFieldName(k), "",
106
//                                                        "xs:string", ds.getFieldValue(j, k).toString());
107
//                                }
108
//                                handler.startElement("", "", String.valueOf(j), ai);
109
//                                handler.endElement("", "", String.valueOf(j));
110
//                        }
111
//
112
//                        ds.stop();
113

    
114
                } catch (ReadException e) {
115
                        throw new SAXException(e);
116
                } catch (DataException e) {
117
                        throw new SAXException(e);
118
                }
119
                finally {
120
                        DisposeUtils.dispose(iterator);
121
                }
122
                handler.endElement("", "", (layer).getName());
123
        }
124
}
125

    
126