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 / ExtentElement.java @ 46

History | View | Annotate | Download (3.63 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

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

    
33
import org.gvsig.sldsupport.exception.InvalidSLDObjectException;
34
import org.gvsig.sldsupport.exception.SLDReadException;
35
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException;
36
import org.gvsig.sldsupport.impl.util.SLDUtils;
37
import org.gvsig.sldsupport.impl.util.XmlBuilder;
38
import org.gvsig.sldsupport.sld.SLDTags;
39
import org.gvsig.sldsupport.sld.extent.SLDExtent;
40

    
41
public class ExtentElement {
42

    
43
    public static void append(SLDExtent obj, XmlBuilder xb, String version)
44
        throws InvalidSLDObjectException, UnsupportedSLDObjectException {
45

    
46
        xb.openTag(SLDTags.EXTENT);
47
        // =========================
48
        xb.writeTag(SLDTags.NAME, obj.getName());
49
        xb.writeTag(SLDTags.VALUE, obj.getValue());
50
        // =========================
51
        xb.closeTag();
52
    }
53

    
54
    public static SLDExtent parse(XmlPullParser parser, String version)
55
        throws XmlPullParserException, IOException, SLDReadException {
56

    
57
        parser.require(XmlPullParser.START_TAG, null, SLDTags.EXTENT);
58
        int tag = 0;
59

    
60
        SLDExtent resp = new SLDExtent();
61

    
62
        tag = parser.nextTag();
63
        String name = parser.getName();
64
        String txt = null;
65
        while (!(SLDUtils.isStr(name, SLDTags.EXTENT) && (tag == XmlPullParser.END_TAG))) {
66

    
67
            switch (tag) {
68
            case XmlPullParser.START_TAG:
69
                if (SLDUtils.isStr(name, SLDTags.NAME)) {
70
                    txt = parser.nextText();
71
                    resp.setName(txt);
72
                    parser.nextTag();
73
                    break;
74
                }
75
                if (SLDUtils.isStr(name, SLDTags.VALUE)) {
76
                    txt = parser.nextText();
77
                    resp.setValue(txt);
78
                    parser.nextTag();
79
                    break;
80
                }
81
                /*
82
                 * Any other entity causes parsing error
83
                 */
84
                throw new SLDReadException(
85
                    "Bad SLD file. Unexpected entity in extent: " + name);
86
            case XmlPullParser.END_TAG:
87
                break;
88
            case XmlPullParser.TEXT:
89
                break;
90
            }
91
            tag = parser.getEventType();
92
            name = parser.getName();
93
        }
94

    
95
        parser.nextTag();
96
        return resp;
97
    }
98
}