001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/graphics/sld/FeatureTypeStyle.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 static org.deegree.framework.xml.XMLTools.escape;
039    
040    import java.util.ArrayList;
041    import java.util.List;
042    
043    import org.deegree.framework.xml.Marshallable;
044    
045    /**
046     * The FeatureTypeStyle defines the styling that is to be applied to a single feature type of a
047     * layer). This element may also be externally re-used outside of the scope of WMSes and layers.
048     * <p>
049     * </p>
050     * The FeatureTypeStyle element identifies that explicit separation in SLD between the handling of
051     * layers and the handling of features of specific feature types. The layer concept is unique to WMS
052     * and SLD, but features are used more generally, such as in WFS and GML, so this explicit
053     * separation is important.
054     * <p>
055     * ----------------------------------------------------------------------
056     * </p>
057     *
058     * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
059     * @version $Revision: 18195 $ $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
060     */
061    public class FeatureTypeStyle implements Marshallable {
062        private List<Rule> rules = null;
063    
064        private List<String> semanticTypeIdentifier = null;
065    
066        private String abstract_ = null;
067    
068        private String featureTypeName = null;
069    
070        private String name = null;
071    
072        private String title = null;
073    
074        /**
075         * default constructor
076         */
077        FeatureTypeStyle() {
078            semanticTypeIdentifier = new ArrayList<String>();
079            rules = new ArrayList<Rule>();
080        }
081    
082        /**
083         * constructor initializing the class with the <FeatureTypeStyle>
084         * @param name
085         * @param title
086         * @param abstract_
087         * @param featureTypeName
088         * @param semanticTypeIdentifier
089         * @param rules
090         */
091        FeatureTypeStyle( String name, String title, String abstract_, String featureTypeName,
092                          String[] semanticTypeIdentifier, Rule[] rules ) {
093            this();
094            setName( name );
095            setTitle( title );
096            setAbstract( abstract_ );
097            setFeatureTypeName( featureTypeName );
098            setSemanticTypeIdentifier( semanticTypeIdentifier );
099            setRules( rules );
100        }
101    
102        /**
103         * The Name element does not have an explicit use at present, though it conceivably might be
104         * used to reference a feature style in some feature-style library.
105         *
106         * @return name
107         *
108         */
109        public String getName() {
110            return name;
111        }
112    
113        /**
114         * The Name element does not have an explicit use at present, though it conceivably might be
115         * used to reference a feature style in some feature-style library. Sets the <Name> o
116         *
117         * @param name
118         *            the name
119         *
120         */
121        public void setName( String name ) {
122            this.name = name;
123        }
124    
125        /**
126         * human-readable information about the style
127         *
128         * @return the title of the FeatureTypeStyle
129         *
130         */
131        public String getTitle() {
132            return title;
133        }
134    
135        /**
136         * sets the &lt;Title&gt;
137         *
138         * @param title
139         *            the title of the FeatureTypeStyle
140         *
141         */
142        public void setTitle( String title ) {
143            this.title = title;
144        }
145    
146        /**
147         * human-readable information about the style
148         *
149         * @return an abstract of the FeatureTypeStyle
150         */
151        public String getAbstract() {
152            return abstract_;
153        }
154    
155        /**
156         * sets &lt;Abstract&gt;
157         *
158         * @param abstract_
159         *            an abstract of the FeatureTypeStyle
160         */
161        public void setAbstract( String abstract_ ) {
162            this.abstract_ = abstract_;
163        }
164    
165        /**
166         * returns the name of the affected feature type
167         *
168         * @return the name of the FeatureTypeStyle as String
169         *
170         */
171        public String getFeatureTypeName() {
172            return featureTypeName;
173        }
174    
175        /**
176         * sets the name of the affected feature type
177         *
178         * @param featureTypeName
179         *            the name of the FeatureTypeStyle
180         *
181         */
182        public void setFeatureTypeName( String featureTypeName ) {
183            this.featureTypeName = featureTypeName;
184        }
185    
186        /**
187         * The SemanticTypeIdentifier is experimental and is intended to be used to identify what the
188         * feature style is suitable to be used for using community- controlled name(s). For example, a
189         * single style may be suitable to use with many different feature types. The syntax of the
190         * SemanticTypeIdentifier string is undefined, but the strings generic:line, generic:polygon,
191         * generic:point, generic:text, generic:raster, and generic:any are reserved to indicate that a
192         * FeatureTypeStyle may be used with any feature type with the corresponding default geometry
193         * type (i.e., no feature properties are referenced in the feature-type style).
194         *
195         * @return the SemanticTypeIdentifiers from the FeatureTypeStyle as String-Array
196         *
197         */
198        public String[] getSemanticTypeIdentifier() {
199            return semanticTypeIdentifier.toArray( new String[semanticTypeIdentifier.size()] );
200        }
201    
202        /**
203         * Sets the SemanticTypeIdentifiers.
204         *
205         * @param semanticTypeIdentifiers
206         *            SemanticTypeIdentifiers for the FeatureTypeStyle
207         */
208        public void setSemanticTypeIdentifier( String[] semanticTypeIdentifiers ) {
209            semanticTypeIdentifier.clear();
210    
211            if ( semanticTypeIdentifiers != null ) {
212                for ( int i = 0; i < semanticTypeIdentifiers.length; i++ ) {
213                    semanticTypeIdentifier.add( semanticTypeIdentifiers[i] );
214                }
215            }
216        }
217    
218        /**
219         * adds the &lt;SemanticTypeIdentifier&gt;
220         *
221         * @param semanticTypeIdentifier
222         *            SemanticTypeIdentifier to add
223         */
224        public void addSemanticTypeIdentifier( String semanticTypeIdentifier ) {
225            this.semanticTypeIdentifier.add( semanticTypeIdentifier );
226        }
227    
228        /**
229         * Removes an &lt;SemanticTypeIdentifier&gt;.
230         *
231         * @param semanticTypeIdentifier
232         *            SemanticTypeIdentifier to remove
233         */
234        public void removeSemanticTypeIdentifier( String semanticTypeIdentifier ) {
235            this.semanticTypeIdentifier.remove( this.semanticTypeIdentifier.indexOf( semanticTypeIdentifier ) );
236        }
237    
238        /**
239         * Rules are used to group rendering instructions by feature-property conditions and map scales.
240         * Rule definitions are placed immediately inside of feature-style definitions.
241         *
242         * @return the rules of the FeatureTypeStyle as Array
243         *
244         */
245        public Rule[] getRules() {
246            return rules.toArray( new Rule[rules.size()] );
247        }
248    
249        /**
250         * sets the &lt;Rules&gt;
251         *
252         * @param rules
253         *            the rules of the FeatureTypeStyle as Array
254         */
255        public void setRules( Rule[] rules ) {
256            this.rules.clear();
257    
258            if ( rules != null ) {
259                for ( int i = 0; i < rules.length; i++ ) {
260                    this.rules.add( rules[i] );
261                }
262            }
263        }
264    
265        /**
266         * adds the &lt;Rules&gt;
267         *
268         * @param rule
269         *            a rule
270         */
271        public void addRule( Rule rule ) {
272            rules.add( rule );
273        }
274    
275        /**
276         * removes a rule
277         *
278         * @param rule
279         *            a rule
280         */
281        public void removeRule( Rule rule ) {
282            rules.remove( rules.indexOf( rule ) );
283        }
284    
285        /**
286         * exports the content of the FeatureTypeStyle as XML formated String
287         *
288         * @return xml representation of the FeatureTypeStyle
289         */
290        public String exportAsXML() {
291    
292            StringBuffer sb = new StringBuffer( 1000 );
293            sb.append( "<FeatureTypeStyle>" );
294            if ( name != null && !name.equals( "" ) ) {
295                sb.append( "<Name>" ).append( escape( name ) ).append( "</Name>" );
296            }
297            if ( title != null && !title.equals( "" ) ) {
298                sb.append( "<Title>" ).append( escape( title ) ).append( "</Title>" );
299            }
300            if ( abstract_ != null && !abstract_.equals( "" ) ) {
301                sb.append( "<Abstract>" ).append( escape( abstract_ ) ).append( "</Abstract>" );
302            }
303            if ( featureTypeName != null && !featureTypeName.equals( "" ) ) {
304                sb.append( "<FeatureTypeName>" ).append( escape( featureTypeName ) ).append( "</FeatureTypeName>" );
305            }
306            for ( int i = 0; i < semanticTypeIdentifier.size(); i++ ) {
307                sb.append( "<SemanticTypeIdentifier>" ).append( escape( semanticTypeIdentifier.get( i ) ) ).append(
308                                                                                                          "</SemanticTypeIdentifier>" );
309            }
310            for ( int i = 0; i < rules.size(); i++ ) {
311                sb.append( ( (Marshallable) rules.get( i ) ).exportAsXML() );
312            }
313            sb.append( "</FeatureTypeStyle>" );
314    
315            return sb.toString();
316        }
317    }