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