001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/graphics/sld/CssParameter.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.graphics.sld;
037
038 import org.deegree.framework.xml.Marshallable;
039 import org.deegree.model.feature.Feature;
040 import org.deegree.model.filterencoding.FilterEvaluationException;
041 import org.deegree.model.filterencoding.PropertyName;
042
043 /**
044 * The simple SVG/CSS2 styling parameters are given with the CssParameter element, which is defined
045 * as follows:
046 *
047 * <pre>
048 *
049 * <xs:element name="CssParameter" type="sld:ParameterValueType"/>
050 * <xs:complexType name="ParameterValueType" mixed="true">
051 * <xs:choice minOccurs="0" maxOccurs="unbounded">
052 * <xs:element ref="wfs:expression"/>
053 * </xs:choice>
054 * </xs:complexType>
055 *
056 * </pre>
057 *
058 * The parameter values are allowed to be complex expressions for maximum flexibility. The
059 * mixed="true" definition means that regular text may be mixed in with various sub-expressions,
060 * implying a text-substitution model for parameter values. Numeric and character-string data types
061 * are not distinguished, which may cause some complications.
062 * <p>
063 * </p>
064 * Here are some usage examples:
065 *
066 * <pre>
067 *
068 * 1. <CssParameter name="stroke-width">3</CssParameter>
069 * 2. <CssParameter name="stroke-width">
070 * <wfs:Literal>3</wfs:Literal>
071 * </CssParameter>
072 * 3. <CssParameter name="stroke-width">
073 * <wfs:Add>
074 * <wfs:PropertyName>/A</wfs:PropertyName>
075 * <wfs:Literal>2</wfs:Literal>
076 * </wfs:Add>
077 * </CssParameter>
078 * 4. <Label>This is city "<wfs:PropertyName>/NAME</wfs:PropertyName>"
079 * of state <wfs:PropertyName>/STATE</wfs:PropertyName></Label>
080 *
081 * </pre>
082 *
083 * The allowed SVG/CSS styling parameters for a stroke are: stroke (color), stroke-opacity,
084 * stroke-width, stroke-linejoin, stroke-linecap, stroke-dasharray, and stroke-dashoffset. The
085 * chosen parameter is given by the name attribute of the CssParameter element.
086 * <p>
087 *
088 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth </a>
089 * @author <a href="mailto:mschneider@lat-lon.de">Markus Schneider </a>
090 * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
091 */
092
093 public class CssParameter implements Marshallable {
094
095 private ParameterValueType pvt = null;
096
097 private String name = null;
098
099 /**
100 * constructor initializing the class with the <CssParameter>
101 * @param name
102 * @param pvt
103 */
104 public CssParameter( String name, ParameterValueType pvt ) {
105 this.name = name;
106 this.pvt = pvt;
107 }
108
109 /**
110 * Returns the name attribute's value of the CssParameter.
111 * <p>
112 *
113 * @return the value of the name attribute of the CssParameter
114 */
115 String getName() {
116 return name;
117 }
118
119 /**
120 * Sets the name attribute's value of the CssParameter.
121 * <p>
122 *
123 * @param name
124 * the value of the name attribute of the CssParameter
125 */
126 void setName( String name ) {
127 this.name = name;
128 }
129
130 /**
131 * Returns the value of the CssParameter as an <tt>ParameterValueType</tt>.
132 * <p>
133 *
134 * @return the mixed content of the element
135 */
136 public ParameterValueType getValue() {
137 return pvt;
138 }
139
140 /**
141 * Sets the value of the CssParameter as an <tt>ParameterValueType</tt>.
142 * <p>
143 *
144 * @param value
145 * the mixed content of the element
146 */
147 void setValue( ParameterValueType value ) {
148 this.pvt = value;
149 }
150
151 /**
152 * Returns the (evaluated) value of the CssParameter as a simple <tt>String</tt>.
153 * <p>
154 *
155 * @param feature
156 * specifies the <tt>Feature</tt> to be used for evaluation of the underlying
157 * 'sld:ParameterValueType'
158 * @return the (evaluated) <tt>String</tt> value of the parameter
159 * @throws FilterEvaluationException
160 * if the evaluations fails
161 */
162 String getValue( Feature feature )
163 throws FilterEvaluationException {
164 return pvt.evaluate( feature );
165 }
166
167 /**
168 * Returns the value of the CssParameter as an <tt>PropertyName</tt>.
169 * <p>
170 *
171 * @return the value of the parameter as an <tt>PropertyName</tt>
172 */
173 public PropertyName getValueAsPropertyName() {
174 for ( int i = 0; i < pvt.getComponents().length; i++ ) {
175 if ( pvt.getComponents()[i] instanceof PropertyName ) {
176 return (PropertyName) pvt.getComponents()[i];
177 }
178 }
179 return null;
180 }
181
182 /**
183 * Sets the value of the CssParameter as a simple <tt>String</tt>.
184 * <p>
185 *
186 * @param value
187 * CssParameter-Value to be set
188 */
189 void setValue( String value ) {
190 ParameterValueType pvt = null;
191 pvt = StyleFactory.createParameterValueType( "" + value );
192 this.pvt = pvt;
193 }
194
195 /**
196 * exports the content of the CssParameter as XML formated String
197 *
198 * @return xml representation of the CssParameter
199 */
200 public String exportAsXML() {
201
202 StringBuffer sb = new StringBuffer( "<CssParameter name=" );
203 sb.append( "'" + name + "'>" );
204 sb.append( ( (Marshallable) pvt ).exportAsXML() );
205 sb.append( "</CssParameter>" );
206
207 return sb.toString();
208 }
209 }