    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/graphics/sld/UserStyle.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     * A user-defined allows map styling to be defined externally from a system and to be passed around
    047     * in an interoperable format.
    048     * <p>
    049     * </p>
    050     * A UserStyle is at the same semantic level as a NamedStyle used in the context of a WMS. In a
    051     * sense, a named style can be thought of as a reference to a hidden UserStyle that is stored inside
    052     * of a map server.
    053     *
    054     *
    055     * @author <a href="mailto:k.lupp@web.de">Katharina Lupp</a>
    056     * @author last edited by: $Author: apoth $
    057     * @version $Revision: 21626 $ $Date: 2009-12-22 16:44:23 +0100 (Di, 22. Dez 2009) $
    058     */
    059    public class UserStyle extends AbstractStyle implements Marshallable {
    060        private List<FeatureTypeStyle> featureTypeStyles = null;
    061
    062        private String abstract_ = null;
    063
    064        private String title = null;
    065
    066        private boolean default_ = false;
    067
    068        /**
    069         * constructor initializing the class with the <UserStyle>
    070         * @param name
    071         * @param title
    072         * @param abstract_
    073         * @param default_
    074         * @param featureTypeStyles
    075         */
    076        UserStyle( String name, String title, String abstract_, boolean default_, FeatureTypeStyle[] featureTypeStyles ) {
    077            super( name );
    078
    079            this.featureTypeStyles = new ArrayList<FeatureTypeStyle>();
    080
    081            setTitle( title );
    082            setAbstract( abstract_ );
    083            setDefault( default_ );
    084            setFeatureTypeStyles( featureTypeStyles );
    085        }
    086
    087        /**
    088         * The Title is a human-readable short description for the style that might be displayed in a
    089         * GUI pick list.
    090         *
    091         * @return the title of the User-AbstractStyle
    092         *
    093         */
    094        public String getTitle() {
    095            return title;
    096        }
    097
    098        /**
    099         * sets the &lt;Title&gt;
    100         *
    101         * @param title
    102         *            the title of the User-AbstractStyle
    103         *
    104         */
    105        public void setTitle( String title ) {
    106            this.title = title;
    107        }
    108
    109        /**
    110         * the Abstract is a more exact description that may be a few paragraphs long.
    111         *
    112         * @return the abstract of the User-AbstractStyle
    113         */
    114        public String getAbstract() {
    115            return abstract_;
    116        }
    117
    118        /**
    119         * sets the &lt;Abstract&gt;
    120         *
    121         * @param abstract_
    122         *            the abstract of the User-AbstractStyle
    123         */
    124        public void setAbstract( String abstract_ ) {
    125            this.abstract_ = abstract_;
    126        }
    127
    128        /**
    129         * The IsDefault element identifies whether a style is the default style of a layer, for use in
    130         * SLD library mode when rendering or for storing inside of a map server. The default value is
    131         * <tt>false</tt>.
    132         *
    133         * @return true if the style ist the default style
    134         */
    135        public boolean isDefault() {
    136            return default_;
    137        }
    138
    139        /**
    140         * sets the &lt;Default&gt;
    141         *
    142         * @param default_
    143         */
    144        public void setDefault( boolean default_ ) {
    145            this.default_ = default_;
    146        }
    147
    148        /**
    149         * A UserStyle can contain one or more FeatureTypeStyles which allow the rendering of features
    150         * of specific types.
    151         * <p>
    152         * </p>
    153         * The FeatureTypeStyle defines the styling that is to be applied to a single feature type of a
    154         * layer.
    155         * <p>
    156         * </p>
    157         * The FeatureTypeStyle element identifies that explicit separation in SLD between the handling
    158         * of layers and the handling of features of specific feature types. The layer concept is unique
    159         * to WMS and SLD, but features are used more generally, such as in WFS and GML, so this
    160         * explicit separation is important.
    161         *
    162         * @return the FeatureTypeStyles of a User-AbstractStyle
    163         *
    164         */
    165        public FeatureTypeStyle[] getFeatureTypeStyles() {
    166
    167            return featureTypeStyles.toArray( new FeatureTypeStyle[featureTypeStyles.size()] );
    168        }
    169
    170        /**
    171         * sets the &lt;FeatureTypeStyle&gt;
    172         *
    173         * @param featureTypeStyles
    174         *            the FeatureTypeStyles of a User-AbstractStyle
    175         */
    176        public void setFeatureTypeStyles( FeatureTypeStyle[] featureTypeStyles ) {
    177            this.featureTypeStyles.clear();
    178
    179            if ( featureTypeStyles != null ) {
    180                for ( int i = 0; i < featureTypeStyles.length; i++ ) {
    181                    addFeatureTypeStyle( featureTypeStyles[i] );
    182                }
    183            }
    184        }
    185
    186        /**
    187         * Adds a &lt;FeatureTypeStyle&gt;
    188         *
    189         * @param featureTypeStyle
    190         *            a FeatureTypeStyle to add
    191         */
    192        public void addFeatureTypeStyle( FeatureTypeStyle featureTypeStyle ) {
    193            featureTypeStyles.add( featureTypeStyle );
    194        }
    195
    196        /**
    197         * Removes a &lt;FeatureTypeStyle&gt;
    198         *
    199         * @param featureTypeStyle
    200         */
    201        public void removeFeatureTypeStyle( FeatureTypeStyle featureTypeStyle ) {
    202            if ( featureTypeStyles.indexOf( featureTypeStyle ) != -1 ) {
    203                featureTypeStyles.remove( featureTypeStyles.indexOf( featureTypeStyle ) );
    204            }
    205        }
    206
    207        /**
    208         * exports the content of the UserStyle as XML formated String
    209         *
    210         * @return xml representation of the UserStyle
    211         */
    212        public String exportAsXML() {
    213
    214            StringBuffer sb = new StringBuffer( 100 );
    215            sb.append( "<UserStyle " );
    216            sb.append( "xmlns='http://www.opengis.net/sld' " );
    217            sb.append( "xmlns:gml='http://www.opengis.net/gml' " );
    218            sb.append( "xmlns:ogc='http://www.opengis.net/ogc' " );
    219            sb.append( "xmlns:xlink='http://www.w3.org/1999/xlink' >" );
    220            if ( name != null && !name.equals( "" ) ) {
    221                sb.append( "<Name>" ).append( escape( name ) ).append( "</Name>" );
    222            }
    223            if ( title != null && !title.equals( "" ) ) {
    224                sb.append( "<Title>" ).append( escape( title ) ).append( "</Title>" );
    225            }
    226            if ( abstract_ != null && !abstract_.equals( "" ) ) {
    227                sb.append( "<Abstract>" ).append( escape( abstract_ ) ).append( "</Abstract>" );
    228            }
    229            if ( default_ ) {
    230                sb.append( "<IsDefault>" ).append( 1 ).append( "</IsDefault>" );
    231            }
    232            for ( int i = 0; i < featureTypeStyles.size(); i++ ) {
    233                sb.append( ( (Marshallable) featureTypeStyles.get( i ) ).exportAsXML() );
    234            }
    235            sb.append( "</UserStyle>" );
    236
    237            return sb.toString();
    238        }
    239
    240    }