Statistics
| Revision:

svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / temp / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld1_0_0 / parsing / ExternalGraphicElement.java @ 40799

History | View | Annotate | Download (2.2 KB)

1
package org.gvsig.sldsupport.impl.sld1_0_0.parsing;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.sldsupport.exception.SLDReadException;
6
import org.gvsig.sldsupport.impl.util.SLDUtils;
7
import org.gvsig.sldsupport.sld.SLDTags;
8
import org.gvsig.sldsupport.sld.graphic.SLDExternalGraphic;
9
import org.kxml2.io.KXmlParser;
10
import org.xmlpull.v1.XmlPullParser;
11
import org.xmlpull.v1.XmlPullParserException;
12

    
13
public class ExternalGraphicElement {
14

    
15
        public static SLDExternalGraphic parse(XmlPullParser parser , String version)
16
                        throws XmlPullParserException, IOException, SLDReadException {
17
                
18
                parser.require(KXmlParser.START_TAG, null, SLDTags.EXTERNALGRAPHIC);
19
                int tag = 0;
20
                
21
                SLDExternalGraphic resp = new SLDExternalGraphic();
22
                
23
                tag = parser.nextTag();
24
                String name = parser.getName();
25
                String txt = null;
26
                while (!(SLDUtils.isStr(name, SLDTags.EXTERNALGRAPHIC) && tag == KXmlParser.END_TAG)) {
27
                        
28
                        switch (tag) {
29
                        case KXmlParser.START_TAG:
30
                                if (SLDUtils.isStr(name, SLDTags.FORMAT)) {
31
                                        txt = parser.nextText();
32
                                        resp.setFormat(txt);
33
                                        parser.nextTag();
34
                                        break;
35
                                }
36
                                if (SLDUtils.isStr(name, SLDTags.ONLINE_RESOURCE)) {
37
                                        // xlink:href="http://somesite.com/something.xml"
38
                                        String res = parser.getAttributeValue(null, SLDTags.XLINK_HREF);
39
                                        if (res == null) {
40
                                                throw new SLDReadException("URL not found (xlink:href att is missing) in online resource entity");
41
                                        }
42
                                        resp.setIsOnline(true);
43
                                        resp.setOnlineResource(res);
44
                                        parser.nextTag();
45
                                        parser.nextTag();
46
                                        break;
47
                                }
48
                                if (SLDUtils.isStr(name, SLDTags.INLINE_CONTENT)) {
49
                                        /*
50
                                         * This is unlikely to work if content is binary
51
                                         */
52
                                        txt = parser.nextText();
53
                                        resp.setIsOnline(false);
54
                                        resp.setInlineContent(txt.getBytes());
55
                                        parser.nextTag();
56
                                        break;
57
                                }
58
                                /*
59
                                 * Any other entity causes parsing error
60
                                 */
61
                                throw new SLDReadException(
62
                                                "Bad SLD file. Unexpected entity in external graphic: " + name);
63
                        case KXmlParser.END_TAG:
64
                                break;
65
                        case KXmlParser.TEXT:
66
                                break;
67
                        }
68
                        tag = parser.getEventType();
69
                        name = parser.getName();
70
                }
71

    
72
                parser.nextTag();
73
                return resp;
74
        }        
75
        
76
}