svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.api / src / main / java / org / gvsig / sldsupport / version / sld1_0_0 / SLDGraphic1_0_0.java @ 40754
History | View | Annotate | Download (7.61 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.version.sld1_0_0; |
42 |
|
43 |
import java.io.IOException; |
44 |
|
45 |
import org.gvsig.sldsupport.exception.SLDReadException; |
46 |
import org.gvsig.sldsupport.filterencoding.FExpression; |
47 |
import org.gvsig.sldsupport.graphic.SLDGraphic; |
48 |
import org.gvsig.sldsupport.util.SLDTags; |
49 |
import org.gvsig.sldsupport.util.SLDUtils; |
50 |
import org.gvsig.sldsupport.util.XmlBuilder; |
51 |
import org.xmlpull.v1.XmlPullParser; |
52 |
import org.xmlpull.v1.XmlPullParserException; |
53 |
/**
|
54 |
* Implements the Graphic element of an SLD implementation specification (version
|
55 |
* 1.0.0).<p>
|
56 |
* A Graphic is a �graphic symbol� with an inherent shape, color(s), and possibly size. A
|
57 |
* �graphic� can be very informally defined as �a little picture� and can be of either a raster
|
58 |
* or vector-graphic source type. The term �graphic� is used since the term �symbol� is
|
59 |
* similar to �symbolizer� which is used in a different context in SLD.<p>
|
60 |
* If the Graphic element is omitted from the parent element, then nothing will be plotted.<p>
|
61 |
* Graphics can either be referenced from an external URL in a common format (such as
|
62 |
* GIF or SVG) or may be derived from a Mark. Multiple external URLs and marks may be
|
63 |
* referenced with the semantic that they all provide the equivalent graphic in different
|
64 |
* formats. The �hot spot� to use for positioning the rendering at a point must either be
|
65 |
* inherent in the external format or is defined to be the �central point� of the graphic,
|
66 |
* where the exact definition �central point� is system-dependent.<p>
|
67 |
* The default if neither an ExternalGraphic nor a Mark is specified is to use the default
|
68 |
* mark of a �square� with a 50%-gray fill and a black outline, with a size of 6 pixels,
|
69 |
*
|
70 |
* @see SLDExternalGraphic1_0_0
|
71 |
* @see SLDMark1_0_0
|
72 |
*
|
73 |
* @see http://portal.opengeospatial.org/files/?artifact_id=1188
|
74 |
*
|
75 |
* @author pepe vidal salvador - jose.vidal.salvador@iver.es
|
76 |
*/
|
77 |
public class SLDGraphic1_0_0 extends SLDGraphic { |
78 |
|
79 |
|
80 |
public void parse(XmlPullParser parser,int cuTag,String tag) |
81 |
throws IOException, XmlPullParserException, SLDReadException { |
82 |
int currentTag;
|
83 |
boolean end = false; |
84 |
|
85 |
parser.require(XmlPullParser.START_TAG, null, tag);
|
86 |
currentTag = parser.next(); |
87 |
|
88 |
while (!end)
|
89 |
{ |
90 |
switch(currentTag)
|
91 |
{ |
92 |
case XmlPullParser.START_TAG:
|
93 |
if (parser.getName().compareTo(SLDTags.GRAPHIC)==0) { |
94 |
this.parseGraphic(parser,SLDTags.GRAPHIC );
|
95 |
} |
96 |
break;
|
97 |
case XmlPullParser.END_TAG:
|
98 |
if (parser.getName().compareTo(tag) == 0) |
99 |
end = true;
|
100 |
break;
|
101 |
case XmlPullParser.TEXT:
|
102 |
break;
|
103 |
} |
104 |
if (!end)
|
105 |
currentTag = parser.next(); |
106 |
} |
107 |
|
108 |
parser.require(XmlPullParser.END_TAG, null, tag);
|
109 |
} |
110 |
|
111 |
|
112 |
|
113 |
/**
|
114 |
* Parses the xml data retrieved from the SLD, it will parse the Graphic element</p>
|
115 |
* @throws SLDReadException
|
116 |
*/
|
117 |
public void parseGraphic(XmlPullParser parser,String tag)throws IOException, XmlPullParserException, SLDReadException { |
118 |
int currentTag;
|
119 |
boolean end = false; |
120 |
|
121 |
parser.require(XmlPullParser.START_TAG, null, tag);
|
122 |
currentTag = parser.next(); |
123 |
|
124 |
while (!end)
|
125 |
{ |
126 |
switch(currentTag)
|
127 |
{ |
128 |
case XmlPullParser.START_TAG:
|
129 |
if (parser.getName().compareTo(SLDTags.EXTERNALGRAPHIC)==0) { |
130 |
SLDExternalGraphic1_0_0 externalGraphic = new SLDExternalGraphic1_0_0();
|
131 |
externalGraphic.parse(parser,currentTag,null);
|
132 |
addExternalGraphic(externalGraphic); |
133 |
|
134 |
} |
135 |
else if (parser.getName().compareTo(SLDTags.MARK)==0) { |
136 |
SLDMark1_0_0 mark = new SLDMark1_0_0();
|
137 |
mark.parse(parser, currentTag, null);
|
138 |
addMark(mark); |
139 |
} |
140 |
else if (parser.getName().compareTo(SLDTags.OPACITY)==0) { |
141 |
FExpression expressionOpacity = new FExpression();
|
142 |
parser.next(); |
143 |
String s = parser.getText().trim();
|
144 |
|
145 |
if (s==null || "".equals(s)) { |
146 |
expressionOpacity.parse(parser, parser.nextTag(),parser.getName()); |
147 |
} else {
|
148 |
if(SLDUtils.isANumber(s))
|
149 |
expressionOpacity.setLiteral(s); |
150 |
else throw new SLDReadException(new Exception( |
151 |
"Opacity value is not numeric."));
|
152 |
} |
153 |
setExpressionOpacity(expressionOpacity); |
154 |
|
155 |
} |
156 |
else if (parser.getName().compareTo(SLDTags.SIZE)==0) { |
157 |
FExpression expressionSize = new FExpression();
|
158 |
parser.next(); |
159 |
String s = parser.getText().trim();
|
160 |
|
161 |
if (s==null || "".equals(s)) { |
162 |
expressionSize.parse(parser, parser.nextTag(),parser.getName()); |
163 |
} else {
|
164 |
if(SLDUtils.isANumber(s))
|
165 |
expressionSize.setLiteral(s); |
166 |
else throw new SLDReadException(new Exception( |
167 |
"Size value is not numeric."));
|
168 |
} |
169 |
setExpressionSize(expressionSize); |
170 |
} |
171 |
else if (parser.getName().compareTo(SLDTags.ROTATION)==0) { |
172 |
FExpression expressionRotation = new FExpression();
|
173 |
parser.next(); |
174 |
String s = parser.getText().trim();
|
175 |
|
176 |
if (s==null || "".equals(s)) { |
177 |
expressionRotation.parse(parser, parser.nextTag(),parser.getName()); |
178 |
} else {
|
179 |
if(SLDUtils.isANumber(s))
|
180 |
expressionRotation.setLiteral(s); |
181 |
else throw new SLDReadException(new Exception( |
182 |
"Rotation value is not numeric."));
|
183 |
|
184 |
} |
185 |
setExpressionRotation(expressionRotation); |
186 |
} |
187 |
break;
|
188 |
case XmlPullParser.END_TAG:
|
189 |
if (parser.getName().compareTo(tag) == 0) |
190 |
end = true;
|
191 |
break;
|
192 |
case XmlPullParser.TEXT:
|
193 |
break;
|
194 |
} |
195 |
if (!end)
|
196 |
currentTag = parser.next(); |
197 |
} |
198 |
|
199 |
parser.require(XmlPullParser.END_TAG, null, tag);
|
200 |
|
201 |
} |
202 |
|
203 |
|
204 |
|
205 |
public String toXML() { |
206 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
207 |
|
208 |
|
209 |
xmlBuilder.openTag(SLDTags.GRAPHICFILL); |
210 |
xmlBuilder.openTag(SLDTags.GRAPHIC); |
211 |
//PictureFill
|
212 |
for (int i = 0; i < getExternalGraphics().size(); i++) { |
213 |
xmlBuilder.writeRaw(getExternalGraphics().get(i).toXML()); |
214 |
} |
215 |
//MarkerFill
|
216 |
for (int i = 0; i < getMarks().size(); i++) { |
217 |
xmlBuilder.writeRaw(getMarks().get(i).toXML()); |
218 |
} |
219 |
if (getExpressionOpacity().getLiteral() != null) |
220 |
xmlBuilder.writeTag(SLDTags.OPACITY |
221 |
,this.getExpressionOpacity().getLiteral());
|
222 |
if (getExpressionSize().getLiteral()!= null) |
223 |
xmlBuilder.writeTag(SLDTags.SIZE |
224 |
,getExpressionSize().getLiteral()); |
225 |
if (getExpressionRotation().getLiteral() != null) |
226 |
xmlBuilder.writeTag(SLDTags.ROTATION |
227 |
,getExpressionRotation().getLiteral()); |
228 |
|
229 |
xmlBuilder.closeTag(); |
230 |
xmlBuilder.closeTag(); |
231 |
return xmlBuilder.getXML();
|
232 |
} |
233 |
|
234 |
|
235 |
|
236 |
|
237 |
} |