Statistics
| Revision:

gvsig-sldtools / org.gvsig.sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld / parsing / LayerFeatureConstraintsElement.java @ 46

History | View | Annotate | Download (4.1 KB)

1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.sldsupport.impl.sld.parsing;
27

    
28
import java.io.IOException;
29
import java.util.List;
30

    
31
import org.xmlpull.v1.XmlPullParser;
32
import org.xmlpull.v1.XmlPullParserException;
33

    
34
import org.gvsig.sldsupport.exception.InvalidSLDObjectException;
35
import org.gvsig.sldsupport.exception.SLDReadException;
36
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException;
37
import org.gvsig.sldsupport.impl.util.SLDUtils;
38
import org.gvsig.sldsupport.impl.util.XmlBuilder;
39
import org.gvsig.sldsupport.sld.SLDTags;
40
import org.gvsig.sldsupport.sld.constraints.SLDFeatureTypeConstraint;
41
import org.gvsig.sldsupport.sld.constraints.SLDLayerFeatureConstraints;
42

    
43
public class LayerFeatureConstraintsElement {
44

    
45
    public static void append(SLDLayerFeatureConstraints obj, XmlBuilder xb,
46
        String version) throws InvalidSLDObjectException,
47
        UnsupportedSLDObjectException {
48

    
49
        List<SLDFeatureTypeConstraint> list = obj.getFeatureTypeConstraints();
50
        if ((list == null) || (list.size() == 0)) {
51
            throw new InvalidSLDObjectException(SLDTags.LAYER_FEATURE_CONST,
52
                "List of constraints is empty");
53
        }
54
        // =========================
55
        xb.openTag(SLDTags.LAYER_FEATURE_CONST);
56
        for (int i = 0; i < list.size(); i++) {
57
            FeatureTypeConstraintElement.append(list.get(i), xb, version);
58
        }
59
        // =========================
60
        xb.closeTag();
61
    }
62

    
63
    public static SLDLayerFeatureConstraints parse(XmlPullParser parser,
64
        String version) throws XmlPullParserException, IOException,
65
        SLDReadException {
66

    
67
        parser.require(XmlPullParser.START_TAG, null,
68
            SLDTags.LAYER_FEATURE_CONST);
69
        int tag = 0;
70

    
71
        SLDLayerFeatureConstraints resp = new SLDLayerFeatureConstraints();
72

    
73
        tag = parser.nextTag();
74
        String name = parser.getName();
75
        String txt = null;
76
        while (!(SLDUtils.isStr(name, SLDTags.LAYER_FEATURE_CONST) && (tag == XmlPullParser.END_TAG))) {
77

    
78
            switch (tag) {
79
            case XmlPullParser.START_TAG:
80
                if (SLDUtils.isStr(name, SLDTags.FEATURETYPECONSTRAINT)) {
81

    
82
                    SLDFeatureTypeConstraint co = null;
83
                    co = FeatureTypeConstraintElement.parse(parser, version);
84
                    resp.getFeatureTypeConstraints().add(co);
85
                    break;
86
                }
87
                /*
88
                 * Any other entity causes parsing error
89
                 */
90
                throw new SLDReadException(
91
                    "Bad SLD file. Unexpected entity in layer feature constraints: "
92
                        + name);
93
            case XmlPullParser.END_TAG:
94
                break;
95
            case XmlPullParser.TEXT:
96
                break;
97
            }
98
            tag = parser.getEventType();
99
            name = parser.getName();
100
        }
101

    
102
        parser.nextTag();
103
        return resp;
104
    }
105

    
106
}