svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / using-sld-model / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld1_0_0 / handler / SLDProtocolHandler1_0_0.java @ 40758
History | View | Annotate | Download (4.32 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.sldsupport.impl.sld1_0_0.handler; |
42 |
|
43 |
|
44 |
import java.io.File; |
45 |
import java.io.FileReader; |
46 |
import java.io.IOException; |
47 |
|
48 |
import org.gvsig.sldsupport.exception.SLDReadException; |
49 |
import org.gvsig.sldsupport.handler.SLDProtocolHandler; |
50 |
import org.gvsig.sldsupport.impl.parser.ExtendedKXmlParser; |
51 |
import org.gvsig.sldsupport.impl.sld1_0_0.layers.SLDNamedLayer1_0_0; |
52 |
import org.gvsig.sldsupport.impl.sld1_0_0.layers.SLDUserLayer1_0_0; |
53 |
import org.gvsig.sldsupport.util.SLDTags; |
54 |
import org.kxml2.io.KXmlParser; |
55 |
import org.xmlpull.v1.XmlPullParser; |
56 |
import org.xmlpull.v1.XmlPullParserException; |
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) |
83 |
throws XmlPullParserException, IOException, SLDReadException { |
84 |
|
85 |
int tag;
|
86 |
XmlPullParser parser = new ExtendedKXmlParser();
|
87 |
|
88 |
FileReader fr = new FileReader(f); |
89 |
parser.setInput(fr); |
90 |
parser.nextTag(); |
91 |
if ( parser.getEventType() != XmlPullParser.END_DOCUMENT ) {
|
92 |
|
93 |
String value = parser.getAttributeValue("",SLDTags.VERSION_ATTR); |
94 |
setVersion(value); |
95 |
|
96 |
parser.require(KXmlParser.START_TAG, null, SLDTags.SLD_ROOT);
|
97 |
tag = parser.nextTag(); |
98 |
|
99 |
while(tag != KXmlParser.END_DOCUMENT){
|
100 |
switch(tag){
|
101 |
case KXmlParser.START_TAG:
|
102 |
if (parser.getName().compareTo(SLDTags.USERDEFINEDLAYER)==0) |
103 |
{ |
104 |
SLDUserLayer1_0_0 lyr = new SLDUserLayer1_0_0();
|
105 |
lyr.parse(parser); |
106 |
if (lyr.getName()!= null && lyr.getName()!="") |
107 |
layers.add(lyr); |
108 |
else throw new SLDReadException(new Exception( |
109 |
"Invalid or empty SLD layer user name"));
|
110 |
} |
111 |
else if(parser.getName().compareTo(SLDTags.NAMEDLAYER)==0) |
112 |
{ |
113 |
SLDNamedLayer1_0_0 lyr = new SLDNamedLayer1_0_0();
|
114 |
lyr.parse(parser); |
115 |
if (lyr.getName()!= null && lyr.getName()!="") |
116 |
layers.add(lyr); |
117 |
else throw new SLDReadException(new Exception( |
118 |
"Invalid or empty SLD layer name"));
|
119 |
|
120 |
} |
121 |
break;
|
122 |
case KXmlParser.END_TAG:
|
123 |
break;
|
124 |
case KXmlParser.TEXT:
|
125 |
break;
|
126 |
} |
127 |
tag = parser.next(); |
128 |
} |
129 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
130 |
} |
131 |
|
132 |
} |
133 |
} |