Statistics
| Revision:

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

History | View | Annotate | Download (5.78 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
import java.io.IOException;
44

    
45
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser;
46
import org.gvsig.remoteClient.sld.SLDFill;
47
import org.gvsig.remoteClient.sld.SLDTags;
48
import org.gvsig.remoteClient.sld.SLDUtils;
49
import org.gvsig.remoteClient.sld.filterEncoding.FExpression;
50
import org.gvsig.remoteClient.sld.filterEncoding.FilterTags;
51
import org.xmlpull.v1.XmlPullParserException;
52

    
53
import com.iver.cit.gvsig.fmap.drivers.legend.LegendDriverException;
54
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
55
/**
56
 * Implements the Fill element of an SLD implementation specification (version 
57
 * 1.0.0).<p>
58
 * The Fill element specifies how the area of the geometry will be filled.
59
 * There are two types of fills, solid-color and repeated GraphicFill. The repeated 
60
 * graphic fill is selected only if the GraphicFill element is present. If the Fill
61
 * element is omitted from its parent element, then no fill will be rendered. The 
62
 * GraphicFill and CssParameter elements are discussed in conjunction with the 
63
 * Stroke element in Section 11.1.3. Here, the CssParameter names are �fill� 
64
 * instead of �stroke� and �fill-opacity� instead of �stroke-opacity�. None of the
65
 * other CssParameters in Stroke are available for filling and the default value
66
 * for the fill color in this context is 50% gray (value �#808080�).
67
 * 
68
 * @see SLDFill1_0_0
69
 * @see http://portal.opengeospatial.org/files/?artifact_id=1188
70
 * 
71
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
72
 */
73
public class SLDFill1_0_0 extends SLDFill{
74

    
75

    
76

    
77
        public void parse(XMLSchemaParser parser,int cuTag, String expressionType)throws IOException, XmlPullParserException, LegendDriverException  {
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 XMLSchemaParser.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 LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
111
                                                setExpressionColor(expressionColor);
112

    
113
                                        }
114
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.FILLOPACITY_ATTR)==0) {
115
                                                
116
                                                FExpression expressionOpacity =  new FExpression();
117
                                                
118
                                                try {
119
                                                        expressionOpacity.parse(parser,parser.nextTag(), parser.getName());
120
                                                }
121
                                                catch(XmlPullParserException e) {
122
                                                        String s = parser.getText().trim();
123
                                                        expressionOpacity.setLiteral(s);
124
                                                }
125

    
126
                                                if (!SLDUtils.isANumber(expressionOpacity.getLiteral()))
127
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
128
                                                
129
                                                setExpressionOpacity(expressionOpacity);
130
                                        }
131
                                }
132
                                break;
133
                        case XMLSchemaParser.END_TAG:
134
                                if (parser.getName().compareTo(SLDTags.FILL) == 0)
135
                                        end = true;
136
                                break;
137
                        case XMLSchemaParser.TEXT:
138
                                break;
139
                        }
140
                        if (!end)
141
                                currentTag = parser.next();
142
                }
143

    
144
                parser.require(XMLSchemaParser.END_TAG, null, SLDTags.FILL);
145

    
146
        }
147

    
148
        
149

    
150
        public String toXML() {
151

    
152
                XmlBuilder xmlBuilder = new XmlBuilder();
153

    
154
                xmlBuilder.openTag(SLDTags.FILL);
155
                if (getFillGraphic() != null)
156
                        xmlBuilder.writeRaw(getFillGraphic().toXML());
157

    
158
                if(getExpressionColor().getLiteral() != null){
159
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.FILL_ATTR);
160
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionColor().getLiteral());
161
                        xmlBuilder.closeTag();
162

    
163
                }
164
                if(getExpressionOpacity().getLiteral() != null){
165
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.FILLOPACITY_ATTR);
166
                        xmlBuilder.writeTag(FilterTags.LITERAL,getExpressionOpacity().getLiteral());
167
                        xmlBuilder.closeTag();
168

    
169
                }
170

    
171
                xmlBuilder.closeTag();
172
                return xmlBuilder.getXML();
173
        }
174

    
175
}