Statistics
| Revision:

root / trunk / extensions / extSymbology / src / org / gvsig / remoteClient / sld / sld1_0_0 / SLDProtocolHandler1_0_0.java @ 20768

History | View | Annotate | Download (4.39 KB)

1
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib��ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.remoteClient.sld.sld1_0_0;
42

    
43

    
44
import java.io.File;
45
import java.io.IOException;
46

    
47
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser;
48
import org.gvsig.remoteClient.sld.SLDProtocolHandler;
49
import org.gvsig.remoteClient.sld.SLDTags;
50
import org.gvsig.remoteClient.sld.sld1_0_0.layers.SLDNamedLayer1_0_0;
51
import org.gvsig.remoteClient.sld.sld1_0_0.layers.SLDUserLayer1_0_0;
52
import org.kxml2.io.KXmlParser;
53
import org.xmlpull.v1.XmlPullParser;
54
import org.xmlpull.v1.XmlPullParserException;
55

    
56
import com.iver.cit.gvsig.fmap.drivers.legend.LegendDriverException;
57

    
58
/**
59
 * Implements the main class for the SLD implementation specification (version 1.0.0)
60
 * which starts the parsing of the styled layer descriptor document in order to store
61
 * all the information that it has inside and transform it into objects.<p>
62
 * 
63
 * An SLD document is defined as a sequence of styled layers.<p>
64
 * The version attribute gives the SLD version an SLD document, to facilitate backward
65
 * compatibility with static documents stored in various different versions of an SLD
66
 * spec.<p>
67
 * 
68
 * The Styled layers can correspond to either named layers or user-defined layers,
69
 * which are described in subsequent sections. There may be any number of either type
70
 * of styled layer, including zero, mixed in any order.
71
 * 
72
 * @see http://portal.opengeospatial.org/files/?artifact_id=1188
73
 * 
74
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
75
 */
76
public class SLDProtocolHandler1_0_0 extends SLDProtocolHandler {
77

    
78
        public SLDProtocolHandler1_0_0(){
79
                setVersion("1.0.0");
80
        }
81

    
82
        public void parse(File f) throws XmlPullParserException, IOException, LegendDriverException {
83
                int tag;
84
                XMLSchemaParser xmlSchemaParser = null;
85
                xmlSchemaParser = new XMLSchemaParser();
86

    
87

    
88
                xmlSchemaParser.setInput(f);
89
                xmlSchemaParser.nextTag();
90
                if ( xmlSchemaParser.getEventType() != XmlPullParser.END_DOCUMENT ) {
91

    
92
                        String value = xmlSchemaParser.getAttributeValue("",SLDTags.VERSION_ATTR);
93
                        setVersion(value);
94

    
95
                        xmlSchemaParser.require(KXmlParser.START_TAG, null, SLDTags.SLD_ROOT);                            
96
                        tag = xmlSchemaParser.nextTag();
97

    
98
                        while(tag != KXmlParser.END_DOCUMENT){
99
                                switch(tag){
100
                                case KXmlParser.START_TAG:
101
                                        if (xmlSchemaParser.getName().compareTo(SLDTags.USERDEFINEDLAYER)==0)
102
                                        {
103
                                                SLDUserLayer1_0_0 lyr = new SLDUserLayer1_0_0();
104
                                                lyr.parse(xmlSchemaParser);
105
                                                if (lyr.getName()!= null && lyr.getName()!="")
106
                                                        layers.add(lyr);
107
                                                else throw new LegendDriverException (LegendDriverException.LAYER_NAME_NOT_SPECIFIED);
108
                                        }        
109
                                        else if(xmlSchemaParser.getName().compareTo(SLDTags.NAMEDLAYER)==0)
110
                                        {
111
                                                SLDNamedLayer1_0_0 lyr = new SLDNamedLayer1_0_0();
112
                                                lyr.parse(xmlSchemaParser);
113
                                                if (lyr.getName()!= null && lyr.getName()!="")
114
                                                        layers.add(lyr);
115
                                                else throw new LegendDriverException (LegendDriverException.LAYER_NAME_NOT_SPECIFIED);
116

    
117
                                        }        
118
                                        break;
119
                                case KXmlParser.END_TAG:                                                        
120
                                        break;
121
                                case KXmlParser.TEXT:
122
                                        break;
123
                                }        
124
                                tag = xmlSchemaParser.next();
125
                        }
126
                        xmlSchemaParser.require(KXmlParser.END_DOCUMENT, null, null);
127
                }
128

    
129
        }        
130
}