001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_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     *   &lt;xs:element name=&quot;CssParameter&quot; type=&quot;sld:ParameterValueType&quot;/&gt;
050     *      &lt;xs:complexType name=&quot;ParameterValueType&quot; mixed=&quot;true&quot;&gt;
051     *         &lt;xs:choice minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;&gt;
052     *              &lt;xs:element ref=&quot;wfs:expression&quot;/&gt;
053     *          &lt;/xs:choice&gt;
054     *   &lt;/xs:complexType&gt;
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. &lt;CssParameter name=&quot;stroke-width&quot;&gt;3&lt;/CssParameter&gt;
069     *  2. &lt;CssParameter name=&quot;stroke-width&quot;&gt;
070     *          &lt;wfs:Literal&gt;3&lt;/wfs:Literal&gt;
071     *     &lt;/CssParameter&gt;
072     *  3. &lt;CssParameter name=&quot;stroke-width&quot;&gt;
073     *          &lt;wfs:Add&gt;
074     *              &lt;wfs:PropertyName&gt;/A&lt;/wfs:PropertyName&gt;
075     *              &lt;wfs:Literal&gt;2&lt;/wfs:Literal&gt;
076     *          &lt;/wfs:Add&gt;
077     *     &lt;/CssParameter&gt;
078     *  4. &lt;Label&gt;This is city &quot;&lt;wfs:PropertyName&gt;/NAME&lt;/wfs:PropertyName&gt;&quot;
079     *  of state &lt;wfs:PropertyName&gt;/STATE&lt;/wfs:PropertyName&gt;&lt;/Label&gt;
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    }