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