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 / SLDFill1_0_0.java @ 40754
History | View | Annotate | Download (5.75 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.filterencoding.FilterTags; |
48 |
import org.gvsig.sldsupport.graphic.SLDFill; |
49 |
import org.gvsig.sldsupport.util.SLDTags; |
50 |
import org.gvsig.sldsupport.util.SLDUtils; |
51 |
import org.gvsig.sldsupport.util.XmlBuilder; |
52 |
import org.xmlpull.v1.XmlPullParser; |
53 |
import org.xmlpull.v1.XmlPullParserException; |
54 |
/**
|
55 |
* Implements the Fill element of an SLD implementation specification (version
|
56 |
* 1.0.0).<p>
|
57 |
* The Fill element specifies how the area of the geometry will be filled.
|
58 |
* There are two types of fills, solid-color and repeated GraphicFill. The repeated
|
59 |
* graphic fill is selected only if the GraphicFill element is present. If the Fill
|
60 |
* element is omitted from its parent element, then no fill will be rendered. The
|
61 |
* GraphicFill and CssParameter elements are discussed in conjunction with the
|
62 |
* Stroke element in Section 11.1.3. Here, the CssParameter names are �fill�
|
63 |
* instead of �stroke� and �fill-opacity� instead of �stroke-opacity�. None of the
|
64 |
* other CssParameters in Stroke are available for filling and the default value
|
65 |
* for the fill color in this context is 50% gray (value �#808080�).
|
66 |
*
|
67 |
* @see SLDFill1_0_0
|
68 |
* @see http://portal.opengeospatial.org/files/?artifact_id=1188
|
69 |
*
|
70 |
* @author pepe vidal salvador - jose.vidal.salvador@iver.es
|
71 |
*/
|
72 |
public class SLDFill1_0_0 extends SLDFill{ |
73 |
|
74 |
|
75 |
|
76 |
public void parse(XmlPullParser parser,int cuTag, String expressionType) |
77 |
throws IOException, XmlPullParserException, SLDReadException { |
78 |
int currentTag;
|
79 |
boolean end = false; |
80 |
currentTag = parser.next(); |
81 |
|
82 |
expressionColor.setLiteral("#808080");
|
83 |
|
84 |
|
85 |
while (!end)
|
86 |
{ |
87 |
switch(currentTag)
|
88 |
{ |
89 |
case XmlPullParser.START_TAG:
|
90 |
if (parser.getName().compareTo(SLDTags.GRAPHICFILL)==0 || |
91 |
parser.getName().compareTo(SLDTags.GRAPHICSTROKE)==0 ) {
|
92 |
SLDGraphic1_0_0 fillGraphic = new SLDGraphic1_0_0();
|
93 |
fillGraphic.parse(parser,currentTag,parser.getName()); |
94 |
setFillGraphic(fillGraphic); |
95 |
|
96 |
} |
97 |
else if (parser.getName().compareTo(SLDTags.CSSPARAMETER)==0) { |
98 |
if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.FILL_ATTR)==0) { |
99 |
FExpression expressionColor = new FExpression();
|
100 |
|
101 |
try {
|
102 |
expressionColor.parse(parser, parser.nextTag(),parser.getName()); |
103 |
} |
104 |
catch(XmlPullParserException e) {
|
105 |
String s = parser.getText().trim();
|
106 |
expressionColor.setLiteral(s); |
107 |
} |
108 |
|
109 |
if (!SLDUtils.isColor(expressionColor.getLiteral()))
|
110 |
throw new SLDReadException( new Exception( |
111 |
"Literal should be a color but it's not."));
|
112 |
setExpressionColor(expressionColor); |
113 |
|
114 |
} |
115 |
else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.FILLOPACITY_ATTR)==0) { |
116 |
|
117 |
FExpression expressionOpacity = new FExpression();
|
118 |
|
119 |
try {
|
120 |
expressionOpacity.parse(parser,parser.nextTag(), parser.getName()); |
121 |
} |
122 |
catch(XmlPullParserException e) {
|
123 |
String s = parser.getText().trim();
|
124 |
expressionOpacity.setLiteral(s); |
125 |
} |
126 |
|
127 |
if (!SLDUtils.isANumber(expressionOpacity.getLiteral()))
|
128 |
throw new SLDReadException( new Exception( |
129 |
"Literal should be numeric but it's not."));
|
130 |
|
131 |
setExpressionOpacity(expressionOpacity); |
132 |
} |
133 |
} |
134 |
break;
|
135 |
case XmlPullParser.END_TAG:
|
136 |
if (parser.getName().compareTo(SLDTags.FILL) == 0) |
137 |
end = true;
|
138 |
break;
|
139 |
case XmlPullParser.TEXT:
|
140 |
break;
|
141 |
} |
142 |
if (!end)
|
143 |
currentTag = parser.next(); |
144 |
} |
145 |
|
146 |
parser.require(XmlPullParser.END_TAG, null, SLDTags.FILL);
|
147 |
|
148 |
} |
149 |
|
150 |
|
151 |
|
152 |
public String toXML() { |
153 |
|
154 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
155 |
|
156 |
xmlBuilder.openTag(SLDTags.FILL); |
157 |
if (getFillGraphic() != null) |
158 |
xmlBuilder.writeRaw(getFillGraphic().toXML()); |
159 |
|
160 |
if(getExpressionColor().getLiteral() != null){ |
161 |
xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.FILL_ATTR); |
162 |
xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionColor().getLiteral()); |
163 |
xmlBuilder.closeTag(); |
164 |
|
165 |
} |
166 |
if(getExpressionOpacity().getLiteral() != null){ |
167 |
xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.FILLOPACITY_ATTR); |
168 |
xmlBuilder.writeTag(FilterTags.LITERAL,getExpressionOpacity().getLiteral()); |
169 |
xmlBuilder.closeTag(); |
170 |
|
171 |
} |
172 |
|
173 |
xmlBuilder.closeTag(); |
174 |
return xmlBuilder.getXML();
|
175 |
} |
176 |
|
177 |
} |